cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r606616 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/map/ test/java/org/apache/cayenne/access/
Date Sun, 23 Dec 2007 21:02:05 GMT
Author: aadamchik
Date: Sun Dec 23 13:02:04 2007
New Revision: 606616

URL: http://svn.apache.org/viewvc?rev=606616&view=rev
Log:
CAY-948 Implement flattened attributes in Cayenne
(refactoring to support secondary tables on commit)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbEntityClassDescriptor.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDeleteBucket.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainInsertBucket.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainSyncBucket.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainUpdateBucket.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNodeSyncQualifierDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDBDiffBuilder.java
Sun Dec 23 13:02:04 2007
@@ -54,9 +54,9 @@
     /**
      * Resets the builder to process a new combination of objEntity/dbEntity.
      */
-    void reset(ObjEntity objEntity, DbEntity dbEntity) {
-        this.objEntity = objEntity;
-        this.dbEntity = dbEntity;
+    void reset(DbEntityClassDescriptor descriptor) {
+        this.objEntity = descriptor.getEntity();
+        this.dbEntity = descriptor.getDbEntity();
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDeleteBucket.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDeleteBucket.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDeleteBucket.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainDeleteBucket.java
Sun Dec 23 13:02:04 2007
@@ -33,7 +33,6 @@
 import org.apache.cayenne.map.EntitySorter;
 import org.apache.cayenne.query.DeleteBatchQuery;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.reflect.ClassDescriptor;
 
 /**
  * @since 1.2
@@ -69,18 +68,19 @@
         sorter.sortDbEntities(dbEntities, true);
 
         for (DbEntity dbEntity : dbEntities) {
-            Collection<ClassDescriptor> descriptors = descriptorsByDbEntity.get(dbEntity);
+            Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
+                    .get(dbEntity);
             Map<Object, Query> batches = new LinkedHashMap<Object, Query>();
 
-            for (ClassDescriptor descriptor : descriptors) {
+            for (DbEntityClassDescriptor descriptor : descriptors) {
 
-                qualifierBuilder.reset(descriptor.getEntity(), dbEntity);
+                qualifierBuilder.reset(descriptor);
 
-                boolean isRootDbEntity = (descriptor.getEntity().getDbEntity() == dbEntity);
+                boolean isRootDbEntity = descriptor.isMaster();
 
                 // remove object set for dependent entity, so that it does not show up
                 // on post processing
-                List<Persistent> objects = objectsByDescriptor.get(descriptor);
+                List<Persistent> objects = objectsByDescriptor.get(descriptor.getClassDescriptor());
                 if (objects.isEmpty()) {
                     continue;
                 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainInsertBucket.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainInsertBucket.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainInsertBucket.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainInsertBucket.java
Sun Dec 23 13:02:04 2007
@@ -37,7 +37,6 @@
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.InsertBatchQuery;
 import org.apache.cayenne.query.Query;
-import org.apache.cayenne.reflect.ClassDescriptor;
 
 /**
  * @since 1.2
@@ -59,20 +58,22 @@
 
         for (DbEntity dbEntity : dbEntities) {
 
-            Collection<ClassDescriptor> descriptors = descriptorsByDbEntity.get(dbEntity);
+            Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
+                    .get(dbEntity);
 
             InsertBatchQuery batch = new InsertBatchQuery(dbEntity, 27);
-            for (ClassDescriptor descriptor : descriptors) {
+            for (DbEntityClassDescriptor descriptor : descriptors) {
 
-                diffBuilder.reset(descriptor.getEntity(), dbEntity);
+                diffBuilder.reset(descriptor);
 
-                List<Persistent> objects = objectsByDescriptor.get(descriptor);
+                List<Persistent> objects = objectsByDescriptor.get(descriptor
+                        .getClassDescriptor());
                 if (objects.isEmpty()) {
                     continue;
                 }
 
                 checkReadOnly(descriptor.getEntity());
-                createPermIds(descriptor, dbEntity, objects);
+                createPermIds(descriptor, objects);
                 sorter.sortObjectsForEntity(descriptor.getEntity(), objects, false);
 
                 for (Persistent o : objects) {
@@ -87,16 +88,15 @@
         }
     }
 
-    void createPermIds(
-            ClassDescriptor descriptor,
-            DbEntity entity,
-            Collection<Persistent> objects) {
+    void createPermIds(DbEntityClassDescriptor descriptor, Collection<Persistent> objects)
{
 
         if (objects.isEmpty()) {
             return;
         }
 
         ObjEntity objEntity = descriptor.getEntity();
+        DbEntity entity = descriptor.getDbEntity();
+
         DataNode node = parent.getDomain().lookupDataNode(entity.getDataMap());
         boolean supportsGeneratedKeys = node.getAdapter().supportsGeneratedKeys();
 
@@ -124,9 +124,8 @@
                 ObjAttribute objAttr = objEntity.getAttributeForDbAttribute(dbAttr);
                 if (objAttr != null) {
 
-                    Object value = descriptor
-                            .getProperty(objAttr.getName())
-                            .readPropertyDirectly(object);
+                    Object value = descriptor.getClassDescriptor().getProperty(
+                            objAttr.getName()).readPropertyDirectly(object);
 
                     if (value != null) {
                         Class<?> javaClass = objAttr.getJavaClass();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainSyncBucket.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainSyncBucket.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainSyncBucket.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainSyncBucket.java
Sun Dec 23 13:02:04 2007
@@ -34,7 +34,6 @@
 import org.apache.cayenne.graph.CompoundDiff;
 import org.apache.cayenne.graph.NodeIdChangeOperation;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.EmbeddedAttribute;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
@@ -58,7 +57,7 @@
     final DataDomainFlushAction parent;
 
     List<DbEntity> dbEntities;
-    Map<DbEntity, Collection<ClassDescriptor>> descriptorsByDbEntity;
+    Map<DbEntity, Collection<DbEntityClassDescriptor>> descriptorsByDbEntity;
 
     DataDomainSyncBucket(DataDomainFlushAction parent) {
         this.objectsByDescriptor = new HashMap<ClassDescriptor, List<Persistent>>();
@@ -105,49 +104,50 @@
     private void groupObjEntitiesBySpannedDbEntities() {
 
         dbEntities = new ArrayList<DbEntity>(objectsByDescriptor.size());
-        descriptorsByDbEntity = new HashMap<DbEntity, Collection<ClassDescriptor>>(
+        descriptorsByDbEntity = new HashMap<DbEntity, Collection<DbEntityClassDescriptor>>(
                 objectsByDescriptor.size() * 2);
 
         for (ClassDescriptor descriptor : objectsByDescriptor.keySet()) {
-            DbEntity dbEntity = descriptor.getEntity().getDbEntity();
 
-            Collection<ClassDescriptor> objEntitiesForDbEntity = descriptorsByDbEntity
-                    .get(dbEntity);
-            if (objEntitiesForDbEntity == null) {
-                objEntitiesForDbEntity = new ArrayList<ClassDescriptor>(1);
-                dbEntities.add(dbEntity);
-                descriptorsByDbEntity.put(dbEntity, objEntitiesForDbEntity);
-            }
+            // root DbEntity
+            {
+                DbEntityClassDescriptor dbEntityDescriptor = new DbEntityClassDescriptor(
+                        descriptor);
+                DbEntity dbEntity = dbEntityDescriptor.getDbEntity();
+
+                Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
+                        .get(dbEntity);
+                if (descriptors == null) {
+                    descriptors = new ArrayList<DbEntityClassDescriptor>(1);
+                    dbEntities.add(dbEntity);
+                    descriptorsByDbEntity.put(dbEntity, descriptors);
+                }
 
-            if (!objEntitiesForDbEntity.contains(descriptor)) {
-                objEntitiesForDbEntity.add(descriptor);
+                descriptors.add(dbEntityDescriptor);
             }
 
+            // secondary DbEntities...
+
             // Note that this logic won't allow flattened attributes to span multiple
             // databases...
-            for (ObjAttribute objAttribute : descriptor
-                    .getEntity()
-                    .getAttributeMap()
-                    .values()) {
-                // TODO: andrus, 2/10/2007 - handle embedded
-                if (objAttribute instanceof EmbeddedAttribute) {
-                    continue;
-                }
-                if (!objAttribute.isCompound()) {
-                    continue;
-                }
-
-                dbEntity = (DbEntity) objAttribute.getDbAttribute().getEntity();
-                objEntitiesForDbEntity = descriptorsByDbEntity.get(dbEntity);
+            for (ObjAttribute objAttribute : descriptor.getEntity().getAttributes()) {
 
-                if (objEntitiesForDbEntity == null) {
-                    objEntitiesForDbEntity = new ArrayList<ClassDescriptor>(1);
-                    dbEntities.add(dbEntity);
-                    descriptorsByDbEntity.put(dbEntity, objEntitiesForDbEntity);
-                }
+                if (objAttribute.isFlattened()) {
+                    DbEntityClassDescriptor dbEntityDescriptor = new DbEntityClassDescriptor(
+                            descriptor,
+                            objAttribute);
+
+                    DbEntity dbEntity = dbEntityDescriptor.getDbEntity();
+                    Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
+                            .get(dbEntity);
+
+                    if (descriptors == null) {
+                        descriptors = new ArrayList<DbEntityClassDescriptor>(1);
+                        dbEntities.add(dbEntity);
+                        descriptorsByDbEntity.put(dbEntity, descriptors);
+                    }
 
-                if (!objEntitiesForDbEntity.contains(descriptor)) {
-                    objEntitiesForDbEntity.add(descriptor);
+                    descriptors.add(dbEntityDescriptor);
                 }
             }
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainUpdateBucket.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainUpdateBucket.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainUpdateBucket.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainUpdateBucket.java
Sun Dec 23 13:02:04 2007
@@ -36,7 +36,6 @@
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.UpdateBatchQuery;
-import org.apache.cayenne.reflect.ClassDescriptor;
 
 /**
  * @since 1.2
@@ -56,18 +55,19 @@
 
         for (DbEntity dbEntity : dbEntities) {
 
-            Collection<ClassDescriptor> descriptors = descriptorsByDbEntity.get(dbEntity);
+            Collection<DbEntityClassDescriptor> descriptors = descriptorsByDbEntity
+                    .get(dbEntity);
             Map<Object, Query> batches = new LinkedHashMap<Object, Query>();
 
-            for (ClassDescriptor descriptor : descriptors) {
+            for (DbEntityClassDescriptor descriptor : descriptors) {
                 ObjEntity entity = descriptor.getEntity();
 
-                diffBuilder.reset(entity, dbEntity);
-                qualifierBuilder.reset(entity, dbEntity);
+                diffBuilder.reset(descriptor);
+                qualifierBuilder.reset(descriptor);
                 boolean isRootDbEntity = entity.getDbEntity() == dbEntity;
 
                 Iterator<Persistent> objects = objectsByDescriptor
-                        .get(descriptor)
+                        .get(descriptor.getClassDescriptor())
                         .iterator();
                 while (objects.hasNext()) {
                     Persistent o = objects.next();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNodeSyncQualifierDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNodeSyncQualifierDescriptor.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNodeSyncQualifierDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNodeSyncQualifierDescriptor.java
Sun Dec 23 13:02:04 2007
@@ -24,10 +24,8 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjAttribute;
@@ -71,14 +69,15 @@
         return map;
     }
 
-    void reset(ObjEntity entity, DbEntity dbEntity) {
+    void reset(DbEntityClassDescriptor descriptor) {
+
         attributes = new ArrayList<DbAttribute>(3);
         valueTransformers = new ArrayList<Transformer>(3);
-        usingOptimisticLocking = entity.getLockType() == ObjEntity.LOCK_TYPE_OPTIMISTIC;
+        usingOptimisticLocking = descriptor.getEntity().getLockType() == ObjEntity.LOCK_TYPE_OPTIMISTIC;
 
         // master PK columns
-        if (entity.getDbEntity() == dbEntity) {
-            for (final DbAttribute attribute : entity.getDbEntity().getPrimaryKeys()) {
+        if (descriptor.isMaster()) {
+            for (final DbAttribute attribute : descriptor.getDbEntity().getPrimaryKeys())
{
                 attributes.add(attribute);
                 valueTransformers.add(new Transformer() {
 
@@ -90,10 +89,9 @@
             }
         }
         else {
-            // detail table PK columns
-            DbRelationship masterDependentDbRel = findMasterToDependentDbRelationship(
-                    entity.getDbEntity(),
-                    dbEntity);
+
+            // TODO: andrus 12/23/2007 - only one step relationship is supported...
+            DbRelationship masterDependentDbRel = descriptor.getPathFromMaster().get(0);
 
             if (masterDependentDbRel != null) {
                 for (final DbJoin dbAttrPair : masterDependentDbRel.getJoins()) {
@@ -115,7 +113,7 @@
 
         if (usingOptimisticLocking) {
 
-            for (final ObjAttribute attribute : entity.getAttributes()) {
+            for (final ObjAttribute attribute : descriptor.getEntity().getAttributes()) {
 
                 if (attribute.isUsedForLocking()) {
                     // only care about first step in a flattened attribute
@@ -137,7 +135,9 @@
                 }
             }
 
-            for (final ObjRelationship relationship : entity.getRelationships()) {
+            for (final ObjRelationship relationship : descriptor
+                    .getEntity()
+                    .getRelationships()) {
 
                 if (relationship.isUsedForLocking()) {
                     // only care about the first DbRelationship
@@ -177,25 +177,5 @@
                 }
             }
         }
-    }
-
-    private DbRelationship findMasterToDependentDbRelationship(
-            DbEntity masterDbEntity,
-            DbEntity dependentDbEntity) {
-
-        for (DbRelationship relationship : masterDbEntity.getRelationships()) {
-            if (dependentDbEntity.equals(relationship.getTargetEntity())
-                    && relationship.isToDependentPK()) {
-
-                if (relationship.isToMany()) {
-                    throw new CayenneRuntimeException(
-                            "Only 'to one' master-detail relationships can be processed.");
-                }
-
-                return relationship;
-            }
-        }
-
-        return null;
     }
 }

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbEntityClassDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbEntityClassDescriptor.java?rev=606616&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbEntityClassDescriptor.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbEntityClassDescriptor.java
Sun Dec 23 13:02:04 2007
@@ -0,0 +1,97 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.reflect.ClassDescriptor;
+
+/**
+ * A descriptor of a primary or secondary DbEntity for a given persistent class during
+ * commit.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class DbEntityClassDescriptor {
+
+    private ClassDescriptor classDescriptor;
+    private List<DbRelationship> pathFromMaster;
+    private DbEntity dbEntity;
+
+    DbEntityClassDescriptor(ClassDescriptor classDescriptor) {
+        this.classDescriptor = classDescriptor;
+        this.dbEntity = classDescriptor.getEntity().getDbEntity();
+    }
+
+    DbEntityClassDescriptor(ClassDescriptor classDescriptor, ObjAttribute masterAttribute)
{
+        this.classDescriptor = classDescriptor;
+
+        Iterator<?> it = masterAttribute.getDbPathIterator();
+
+        if (masterAttribute.isFlattened()) {
+
+            while (it.hasNext()) {
+                Object object = it.next();
+                if (object instanceof DbRelationship) {
+
+                    if (pathFromMaster == null) {
+                        pathFromMaster = new ArrayList<DbRelationship>(2);
+                    }
+
+                    pathFromMaster.add((DbRelationship) object);
+                }
+                else if (object instanceof DbAttribute) {
+                    this.dbEntity = (DbEntity) ((DbAttribute) object).getEntity();
+                }
+            }
+        }
+
+        if (dbEntity == null) {
+            dbEntity = classDescriptor.getEntity().getDbEntity();
+        }
+    }
+
+    boolean isMaster() {
+        return pathFromMaster == null;
+    }
+
+    ClassDescriptor getClassDescriptor() {
+        return classDescriptor;
+    }
+
+    List<DbRelationship> getPathFromMaster() {
+        return pathFromMaster;
+    }
+
+    DbEntity getDbEntity() {
+        return dbEntity;
+    }
+
+    ObjEntity getEntity() {
+        return classDescriptor.getEntity();
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
Sun Dec 23 13:02:04 2007
@@ -236,7 +236,7 @@
     }
 
     /**
-     * Returns whether this DbAttribute is "flattened", meaning that it points to a column
+     * Returns whether this attribute is "flattened", meaning that it points to a column
      * from an entity other than the DbEntity mapped to the parent ObjEntity.
      * 
      * @since 3.0

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java?rev=606616&r1=606615&r2=606616&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesTest.java
Sun Dec 23 13:02:04 2007
@@ -27,7 +27,9 @@
 import java.util.List;
 
 import org.apache.art.CompoundPainting;
+import org.apache.cayenne.DataObjectUtils;
 import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.unit.CayenneCase;
 
@@ -176,7 +178,7 @@
                     painting.getGalleryName());
         }
     }
-    
+
     public void testInsert() {
         CompoundPainting o1 = context.newObject(CompoundPainting.class);
         o1.setArtistName("A1");
@@ -186,5 +188,47 @@
         o1.setTextReview("T1");
 
         context.commitChanges();
+
+        Number artistCount = (Number) DataObjectUtils.objectForQuery(
+                context,
+                new EJBQLQuery("select count(a) from Artist a"));
+        assertEquals(1, artistCount.intValue());
+        Number paintingCount = (Number) DataObjectUtils.objectForQuery(
+                context,
+                new EJBQLQuery("select count(a) from Painting a"));
+        assertEquals(1, paintingCount.intValue());
+
+        Number galleryCount = (Number) DataObjectUtils.objectForQuery(
+                context,
+                new EJBQLQuery("select count(a) from Gallery a"));
+        assertEquals(1, galleryCount.intValue());
+    }
+
+    public void testDelete() throws Exception {
+        CompoundPainting o1 = context.newObject(CompoundPainting.class);
+        o1.setArtistName("A1");
+        o1.setEstimatedPrice(new BigDecimal(1.0d));
+        o1.setGalleryName("G1");
+        o1.setPaintingTitle("P1");
+        o1.setTextReview("T1");
+
+        context.commitChanges();
+
+        context.deleteObject(o1);
+        context.commitChanges();
+
+        Number artistCount = (Number) DataObjectUtils.objectForQuery(
+                context,
+                new EJBQLQuery("select count(a) from Artist a"));
+        assertEquals(0, artistCount.intValue());
+        Number paintingCount = (Number) DataObjectUtils.objectForQuery(
+                context,
+                new EJBQLQuery("select count(a) from Painting a"));
+        assertEquals(0, paintingCount.intValue());
+
+        Number galleryCount = (Number) DataObjectUtils.objectForQuery(
+                context,
+                new EJBQLQuery("select count(a) from Gallery a"));
+        assertEquals(0, galleryCount.intValue());
     }
 }



Mime
View raw message