You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2013/08/04 20:04:15 UTC

svn commit: r1510286 [2/3] - in /cayenne/main/trunk: framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-core-unpublished/src/main/java/org/a...

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java Sun Aug  4 18:04:14 2013
@@ -25,7 +25,6 @@ import org.apache.cayenne.CayenneRuntime
 import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.TraversalHelper;
-import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EmbeddedAttribute;
@@ -33,7 +32,6 @@ import org.apache.cayenne.map.EntityInhe
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
-import org.apache.cayenne.map.Relationship;
 
 /**
  * A convenience superclass for {@link ClassDescriptorFactory} implementors.
@@ -72,39 +70,37 @@ public abstract class PersistentDescript
         descriptor.setPersistenceStateAccessor(new BeanAccessor(entityClass, "persistenceState", Integer.TYPE));
 
         // only include this entity attributes and skip superclasses...
-        for (Attribute attribute : descriptor.getEntity().getDeclaredAttributes()) {
+        for (ObjAttribute attribute : descriptor.getEntity().getDeclaredAttributes()) {
 
             if (attribute instanceof EmbeddedAttribute) {
                 EmbeddedAttribute embedded = (EmbeddedAttribute) attribute;
                 for (ObjAttribute objAttribute : embedded.getAttributes()) {
                     createEmbeddedAttributeProperty(descriptor, embedded, objAttribute);
                 }
-            } else if (attribute instanceof ObjAttribute) {
-                createAttributeProperty(descriptor, (ObjAttribute) attribute);
+            } else {
+                createAttributeProperty(descriptor, attribute);
             }
         }
 
         // only include this entity relationships and skip superclasses...
-        for (Relationship relationship : descriptor.getEntity().getDeclaredRelationships()) {
-
-            ObjRelationship objRelationship = (ObjRelationship) relationship;
+        for (ObjRelationship relationship : descriptor.getEntity().getDeclaredRelationships()) {
 
             if (relationship.isToMany()) {
 
-                String collectionType = objRelationship.getCollectionType();
+                String collectionType = relationship.getCollectionType();
                 if (collectionType == null || ObjRelationship.DEFAULT_COLLECTION_TYPE.equals(collectionType)) {
-                    createToManyListProperty(descriptor, objRelationship);
+                    createToManyListProperty(descriptor, relationship);
                 } else if (collectionType.equals("java.util.Map")) {
-                    createToManyMapProperty(descriptor, objRelationship);
+                    createToManyMapProperty(descriptor, relationship);
                 } else if (collectionType.equals("java.util.Set")) {
-                    createToManySetProperty(descriptor, objRelationship);
+                    createToManySetProperty(descriptor, relationship);
                 } else if (collectionType.equals("java.util.Collection")) {
-                    createToManyCollectionProperty(descriptor, objRelationship);
+                    createToManyCollectionProperty(descriptor, relationship);
                 } else {
                     throw new IllegalArgumentException("Unsupported to-many collection type: " + collectionType);
                 }
             } else {
-                createToOneProperty(descriptor, objRelationship);
+                createToOneProperty(descriptor, relationship);
             }
         }
 
@@ -255,7 +251,7 @@ public abstract class PersistentDescript
                         }
                     } else if (node.getType() == Expression.OBJ_PATH) {
                         String path = node.getOperand(0).toString();
-                        ObjAttribute attribute = (ObjAttribute) descriptor.getEntity().getAttribute(path);
+                        ObjAttribute attribute = descriptor.getEntity().getAttribute(path);
                         attributes.put(path, attribute);
                     }
                 }

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorResultMetadata.java Sun Aug  4 18:04:14 2013
@@ -55,7 +55,7 @@ class PersistentDescriptorResultMetadata
     void addObjectField(String attributeName, String column) {
         ObjEntity entity = classDescriptor.getEntity();
 
-        ObjAttribute attribute = (ObjAttribute) entity.getAttribute(attributeName);
+        ObjAttribute attribute = entity.getAttribute(attributeName);
         fields.put(attribute.getDbAttributePath(), column);
         reverseFields.put(column, attribute.getDbAttributePath());
     }
@@ -68,7 +68,7 @@ class PersistentDescriptorResultMetadata
         ObjEntity entity = classDescriptor.getEntity().getDataMap().getObjEntity(
                 entityName);
 
-        ObjAttribute attribute = (ObjAttribute) entity.getAttribute(attributeName);
+        ObjAttribute attribute = entity.getAttribute(attributeName);
         fields.put(attribute.getDbAttributePath(), column);
         reverseFields.put(column, attribute.getDbAttributePath());
     }

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/NamedObjectFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/NamedObjectFactory.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/NamedObjectFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/NamedObjectFactory.java Sun Aug  4 18:04:14 2013
@@ -109,8 +109,9 @@ public abstract class NamedObjectFactory
      * changed later.</i>
      * </p>
      */
-    public static Object createObject(Class objectClass, Object namingContext) {
-        return (factories.get(objectClass)).makeObject(namingContext);
+    @SuppressWarnings("unchecked")
+    public static <T> T createObject(Class<T> objectClass, Object namingContext) {
+        return (T) factories.get(objectClass).makeObject(namingContext);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/RelationshipFault.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/RelationshipFault.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/RelationshipFault.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/util/RelationshipFault.java Sun Aug  4 18:04:14 2013
@@ -74,12 +74,12 @@ public abstract class RelationshipFault 
         int state = relationshipOwner.getPersistenceState();
         return state == PersistenceState.MODIFIED || state == PersistenceState.DELETED;
     }
-    
+
     protected abstract void mergeLocalChanges(List resolved);
 
     /**
-     * Executes a query that returns related objects. Subclasses would invoke this method
-     * whenever they need to resolve a fault.
+     * Executes a query that returns related objects. Subclasses would invoke
+     * this method whenever they need to resolve a fault.
      */
     protected List resolveFromDB() {
         // non-persistent objects shouldn't trigger a fetch
@@ -97,7 +97,7 @@ public abstract class RelationshipFault 
         if (resolved instanceof RelationshipFault) {
             resolved = new ArrayList(resolved);
         }
-        
+
         // merge local before updating reverse to ensure we update reverse rels
         // of the right objects (see CAY-1757)
         mergeLocalChanges(resolved);
@@ -110,25 +110,21 @@ public abstract class RelationshipFault 
 
         return resolved;
     }
-    
-    // see if reverse relationship is to-one and we can connect source to results....
+
+    // see if reverse relationship is to-one and we can connect source to
+    // results....
     protected void updateReverse(List resolved) {
-        EntityResolver resolver = relationshipOwner
-                .getObjectContext()
-                .getEntityResolver();
-        ObjEntity sourceEntity = resolver.getObjEntity(relationshipOwner
-                .getObjectId()
-                .getEntityName());
+        EntityResolver resolver = relationshipOwner.getObjectContext().getEntityResolver();
+        ObjEntity sourceEntity = resolver.getObjEntity(relationshipOwner.getObjectId().getEntityName());
 
-        ObjRelationship relationship = (ObjRelationship) sourceEntity
-                .getRelationship(relationshipName);
+        ObjRelationship relationship = sourceEntity.getRelationship(relationshipName);
         ObjRelationship reverse = relationship.getReverseRelationship();
 
         if (reverse != null && !reverse.isToMany()) {
-            PropertyDescriptor property = resolver.getClassDescriptor(
-                    reverse.getSourceEntity().getName()).getProperty(reverse.getName());
+            PropertyDescriptor property = resolver.getClassDescriptor(reverse.getSourceEntity().getName()).getProperty(
+                    reverse.getName());
 
-            for(Object o : resolved) {
+            for (Object o : resolved) {
                 property.writePropertyDirectly(o, null, relationshipOwner);
             }
         }

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DataContextPrefetchTest.java Sun Aug  4 18:04:14 2013
@@ -368,7 +368,7 @@ public class DataContextPrefetchTest ext
         createTwoArtistsAndTwoPaintingsDataSet();
 
         ObjEntity paintingEntity = context.getEntityResolver().getObjEntity(Painting.class);
-        ObjRelationship relationship = (ObjRelationship) paintingEntity.getRelationship("toArtist");
+        ObjRelationship relationship = paintingEntity.getRelationship("toArtist");
         paintingEntity.removeRelationship("toArtist");
 
         try {
@@ -395,7 +395,7 @@ public class DataContextPrefetchTest ext
         createTwoArtistsAndTwoPaintingsDataSet();
 
         ObjEntity paintingEntity = context.getEntityResolver().getObjEntity(Painting.class);
-        ObjRelationship relationship = (ObjRelationship) paintingEntity.getRelationship("toArtist");
+        ObjRelationship relationship = paintingEntity.getRelationship("toArtist");
         paintingEntity.removeRelationship("toArtist");
 
         try {
@@ -731,7 +731,7 @@ public class DataContextPrefetchTest ext
             }
         });
     }
-    
+
     public void testPrefetchToOneWithBackRelationship_Joint() throws Exception {
         createArtistWithTwoPaintingsAndTwoInfosDataSet();
 

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java Sun Aug  4 18:04:14 2013
@@ -127,7 +127,7 @@ public class DbLoaderTest extends Server
         loader.loadObjEntities(map);
         ObjEntity artist = map.getObjEntity("Artist");
         assertNotNull(artist);
-        ObjAttribute id = (ObjAttribute) artist.getAttribute("artistId");
+        ObjAttribute id = artist.getAttribute("artistId");
         assertNotNull(id);
     }
 
@@ -293,13 +293,13 @@ public class DbLoaderTest extends Server
         ObjEntity blobEnt = map.getObjEntity("BlobTest");
         assertNotNull(blobEnt);
         // BLOBs should be mapped as byte[]
-        ObjAttribute blobAttr = (ObjAttribute) blobEnt.getAttribute("blobCol");
+        ObjAttribute blobAttr = blobEnt.getAttribute("blobCol");
         assertNotNull("BlobTest.blobCol failed to load", blobAttr);
         assertEquals("byte[]", blobAttr.getType());
         ObjEntity clobEnt = map.getObjEntity("ClobTest");
         assertNotNull(clobEnt);
         // CLOBs should be mapped as Strings by default
-        ObjAttribute clobAttr = (ObjAttribute) clobEnt.getAttribute("clobCol");
+        ObjAttribute clobAttr = clobEnt.getAttribute("clobCol");
         assertNotNull(clobAttr);
         assertEquals(String.class.getName(), clobAttr.getType());
     }

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteObjectTest.java Sun Aug  4 18:04:14 2013
@@ -158,8 +158,7 @@ public class DeleteObjectTest extends Se
         // as Painting -> Artist has Nullify rule, relationship list has to be
         // cleaned up,
         // and no exceptions thrown on concurrent modification...
-        ObjRelationship r = (ObjRelationship) context.getEntityResolver().getObjEntity(Painting.class)
-                .getRelationship("toArtist");
+        ObjRelationship r = context.getEntityResolver().getObjEntity(Painting.class).getRelationship("toArtist");
         assertEquals(DeleteRule.NULLIFY, r.getDeleteRule());
         assertEquals(0, paintings.size());
 

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteRulesTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteRulesTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteRulesTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/DeleteRulesTest.java Sun Aug  4 18:04:14 2013
@@ -298,7 +298,7 @@ public class DeleteRulesTest extends Ser
     private int changeDeleteRule(int deleteRule) {
         ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
 
-        ObjRelationship relationship = (ObjRelationship) entity.getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
+        ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
         int oldRule = relationship.getDeleteRule();
         relationship.setDeleteRule(deleteRule);
         return oldRule;
@@ -307,7 +307,7 @@ public class DeleteRulesTest extends Ser
     private ObjRelationship unsetReverse() {
         ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
 
-        ObjRelationship relationship = (ObjRelationship) entity.getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
+        ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
         ObjRelationship reverse = relationship.getReverseRelationship();
 
         if (reverse != null) {
@@ -322,7 +322,7 @@ public class DeleteRulesTest extends Ser
     private void restoreReverse(ObjRelationship reverse) {
         ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
 
-        ObjRelationship relationship = (ObjRelationship) entity.getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
+        ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B_PROPERTY);
         relationship.getTargetEntity().addRelationship(reverse);
         context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatA");
         context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatB");

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/FlattenedArcKeyTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/FlattenedArcKeyTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/FlattenedArcKeyTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/FlattenedArcKeyTest.java Sun Aug  4 18:04:14 2013
@@ -37,7 +37,7 @@ public class FlattenedArcKeyTest extends
     public void testAttributes() {
         ObjectId src = new ObjectId("X");
         ObjectId target = new ObjectId("Y");
-        ObjRelationship r1 = (ObjRelationship) entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(
+        ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(
                 FlattenedTest3.TO_FT1_PROPERTY);
 
         FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
@@ -50,13 +50,13 @@ public class FlattenedArcKeyTest extends
     public void testHashCode() {
         ObjectId src = new ObjectId("X");
         ObjectId target = new ObjectId("Y");
-        ObjRelationship r1 = (ObjRelationship) entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(
+        ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(
                 FlattenedTest3.TO_FT1_PROPERTY);
 
         FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
         FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
 
-        ObjRelationship r3 = (ObjRelationship) entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(
+        ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(
                 FlattenedTest1.FT3OVER_COMPLEX_PROPERTY);
 
         FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);
@@ -72,13 +72,13 @@ public class FlattenedArcKeyTest extends
     public void testEquals() {
         ObjectId src = new ObjectId("X");
         ObjectId target = new ObjectId("Y");
-        ObjRelationship r1 = (ObjRelationship) entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(
+        ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(
                 FlattenedTest3.TO_FT1_PROPERTY);
 
         FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
         FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
 
-        ObjRelationship r3 = (ObjRelationship) entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(
+        ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(
                 FlattenedTest1.FT3OVER_COMPLEX_PROPERTY);
 
         FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/JointPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/JointPrefetchTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/JointPrefetchTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/access/JointPrefetchTest.java Sun Aug  4 18:04:14 2013
@@ -20,7 +20,6 @@
 package org.apache.cayenne.access;
 
 import java.sql.Date;
-import java.sql.Types;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -337,7 +336,7 @@ public class JointPrefetchTest extends S
                 PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS);
 
         ObjEntity artistE = context.getEntityResolver().getObjEntity("Artist");
-        ObjAttribute dateOfBirth = (ObjAttribute) artistE.getAttribute("dateOfBirth");
+        ObjAttribute dateOfBirth = artistE.getAttribute("dateOfBirth");
         assertEquals("java.util.Date", dateOfBirth.getType());
         dateOfBirth.setType("java.sql.Date");
         try {

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjAttributeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjAttributeTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjAttributeTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjAttributeTest.java Sun Aug  4 18:04:14 2013
@@ -57,7 +57,7 @@ public class ObjAttributeTest extends Te
     public void testSerializability() throws Exception {
         ObjAttribute a1 = new ObjAttribute("a1");
 
-        ObjAttribute a2 = (ObjAttribute) Util.cloneViaSerialization(a1);
+        ObjAttribute a2 = Util.cloneViaSerialization(a1);
         assertEquals(a1.getName(), a2.getName());
     }
 

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java Sun Aug  4 18:04:14 2013
@@ -75,18 +75,18 @@ public class ObjEntityTest extends Serve
 
         map.addObjEntity(subEntity);
 
-        ObjAttribute a1 = (ObjAttribute) subEntity.getAttribute("a1");
+        ObjAttribute a1 = subEntity.getAttribute("a1");
         assertNotNull(a1);
         assertSame(subEntity, a1.getEntity());
         assertEquals("overridden.path", a1.getDbAttributePath());
         assertEquals("int", a1.getType());
 
-        ObjAttribute a2 = (ObjAttribute) subEntity.getAttribute("a2");
+        ObjAttribute a2 = subEntity.getAttribute("a2");
         assertNotNull(a2);
         assertSame(subEntity, a2.getEntity());
         assertNull(a2.getDbAttributePath());
 
-        ObjAttribute a3 = (ObjAttribute) subEntity.getAttribute("a3");
+        ObjAttribute a3 = subEntity.getAttribute("a3");
         assertNotNull(a3);
         assertSame(subEntity, a3.getEntity());
     }
@@ -130,9 +130,8 @@ public class ObjEntityTest extends Serve
     }
 
     public void testAttributes() {
-        // ObjEntity artistE = getObjEntity("Artist");
         ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
-        ObjAttribute attr = (ObjAttribute) artistE.getAttribute("artistName");
+        ObjAttribute attr = artistE.getAttribute("artistName");
 
         assertEquals(attr.getMaxLength(), attr.getDbAttribute().getMaxLength());
         assertEquals(attr.isMandatory(), attr.getDbAttribute().isMandatory());
@@ -267,7 +266,7 @@ public class ObjEntityTest extends Serve
         ObjRelationship r1 = new ObjRelationship("r1") {
 
             @Override
-            public Entity getTargetEntity() {
+            public ObjEntity getTargetEntity() {
                 return target;
             }
         };

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/map/ObjRelationshipTest.java Sun Aug  4 18:04:14 2013
@@ -40,476 +40,456 @@ import org.apache.cayenne.util.XMLEncode
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class ObjRelationshipTest extends ServerCase {
 
-	@Inject
-	private ServerRuntime runtime;
+    @Inject
+    private ServerRuntime runtime;
 
-	private DbEntity artistDBEntity;
-	private DbEntity artistExhibitDBEntity;
-	private DbEntity exhibitDBEntity;
-	private DbEntity paintingDbEntity;
-	private DbEntity galleryDBEntity;
-
-	@Override
-	protected void setUpAfterInjection() throws Exception {
-		EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-
-		artistDBEntity = resolver.getDbEntity("ARTIST");
-		artistExhibitDBEntity = resolver.getDbEntity("ARTIST_EXHIBIT");
-		exhibitDBEntity = resolver.getDbEntity("EXHIBIT");
-		paintingDbEntity = resolver.getDbEntity("PAINTING");
-		galleryDBEntity = resolver.getDbEntity("GALLERY");
-	}
-
-	public void testEncodeAsXML() {
-		StringWriter buffer = new StringWriter();
-		PrintWriter out = new PrintWriter(buffer);
-		XMLEncoder encoder = new XMLEncoder(out);
-
-		DataMap map = new DataMap("M");
-		ObjEntity source = new ObjEntity("S");
-		ObjEntity target = new ObjEntity("T");
-		map.addObjEntity(source);
-		map.addObjEntity(target);
-
-		ObjRelationship r = new ObjRelationship("X");
-		r.setSourceEntity(source);
-		r.setTargetEntityName("T");
-		r.setCollectionType("java.util.Map");
-		r.setMapKey("bla");
-
-		r.encodeAsXML(encoder);
-		out.close();
-
-		String lineBreak = System.getProperty("line.separator");
-
-		assertEquals("<obj-relationship name=\"X\" source=\"S\" target=\"T\" "
-				+ "collection-type=\"java.util.Map\" map-key=\"bla\"/>"
-				+ lineBreak, buffer.getBuffer().toString());
-	}
-
-	public void testCollectionType() {
-		ObjRelationship r = new ObjRelationship("X");
-		assertNull(r.getCollectionType());
-		r.setCollectionType("java.util.Map");
-		assertEquals("java.util.Map", r.getCollectionType());
-	}
-
-	public void testSerializability() throws Exception {
-		ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Artist");
-
-		// start with "to many"
-		ObjRelationship r1 = (ObjRelationship) artistObjEnt
-				.getRelationship("paintingArray");
-
-		ObjRelationship r2 = Util.cloneViaSerialization(r1);
-		assertEquals(r1.getName(), r2.getName());
-		assertEquals(r1.getDbRelationshipPath(), r2.getDbRelationshipPath());
-	}
-
-	public void testGetClientRelationship() {
-		final ObjEntity target = new ObjEntity("te1");
-		ObjRelationship r1 = new ObjRelationship("r1") {
-
-			@Override
-			public Entity getTargetEntity() {
-				return target;
-			}
-		};
-
-		r1.setDeleteRule(DeleteRule.DENY);
-		r1.setTargetEntityName("te1");
-
-		ObjRelationship r2 = r1.getClientRelationship();
-		assertNotNull(r2);
-		assertEquals(r1.getName(), r2.getName());
-		assertEquals(r1.getTargetEntityName(), r2.getTargetEntityName());
-		assertEquals(r1.getDeleteRule(), r2.getDeleteRule());
-	}
-
-	public void testGetReverseDbRelationshipPath() {
-		ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Artist");
-		ObjEntity paintingObjEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Painting");
-
-		// start with "to many"
-		ObjRelationship r1 = (ObjRelationship) artistObjEnt
-				.getRelationship("paintingArray");
-
-		assertEquals("toArtist", r1.getReverseDbRelationshipPath());
-
-		ObjRelationship r2 = (ObjRelationship) paintingObjEnt
-				.getRelationship("toArtist");
-
-		assertEquals("paintingArray", r2.getReverseDbRelationshipPath());
-	}
-
-	public void testSetDbRelationshipPath() {
-		ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Artist");
-
-		ObjRelationship r = new ObjRelationship("r");
-		r.setSourceEntity(artistObjEnt);
-		r.setDbRelationshipPath("paintingArray");
-		assertEquals(r.getDbRelationshipPath(), "paintingArray");
-	}
-
-	public void testRefreshFromPath() {
-		ObjRelationship relationship = new ObjRelationship();
-
-		// attempt to resolve must fail - relationship is outside of context,
-		// plus the path is random
-		try {
-			relationship.setDbRelationshipPath("dummy.path");
-			fail("set random path should have failed.");
-		} catch (CayenneRuntimeException ex) {
-			// expected
-		}
-
-		DataMap map = new DataMap();
-		ObjEntity entity = new ObjEntity("Test");
-		map.addObjEntity(entity);
-
-		relationship.setSourceEntity(entity);
-		// attempt to resolve must fail - relationship is outside of context,
-		// plus the path is random
-		try {
-			relationship.refreshFromPath("dummy.path", false);
-			fail("refresh over a dummy path should have failed.");
-		} catch (ExpressionException ex) {
-			// expected
-		}
-
-		// finally assemble ObjEntity to make the path valid
-		DbEntity dbEntity1 = new DbEntity("TEST1");
-		DbEntity dbEntity2 = new DbEntity("TEST2");
-		DbEntity dbEntity3 = new DbEntity("TEST3");
-		map.addDbEntity(dbEntity1);
-		map.addDbEntity(dbEntity2);
-		map.addDbEntity(dbEntity3);
-		entity.setDbEntityName("TEST1");
-		DbRelationship dummyR = new DbRelationship("dummy");
-		dummyR.setTargetEntityName("TEST2");
-		dummyR.setSourceEntity(dbEntity1);
-		DbRelationship pathR = new DbRelationship("path");
-		pathR.setTargetEntityName("TEST3");
-		pathR.setSourceEntity(dbEntity2);
-		dbEntity1.addRelationship(dummyR);
-		dbEntity2.addRelationship(pathR);
-
-		relationship.refreshFromPath("dummy.path", false);
-
-		List<DbRelationship> resolvedPath = relationship.getDbRelationships();
-		assertEquals(2, resolvedPath.size());
-		assertSame(dummyR, resolvedPath.get(0));
-		assertSame(pathR, resolvedPath.get(1));
-	}
-
-	public void testCalculateToMany() {
-		// assemble fixture....
-		DataMap map = new DataMap();
-		ObjEntity entity = new ObjEntity("Test");
-		map.addObjEntity(entity);
-
-		DbEntity dbEntity1 = new DbEntity("TEST1");
-		DbEntity dbEntity2 = new DbEntity("TEST2");
-		DbEntity dbEntity3 = new DbEntity("TEST3");
-		map.addDbEntity(dbEntity1);
-		map.addDbEntity(dbEntity2);
-		map.addDbEntity(dbEntity3);
-		entity.setDbEntityName("TEST1");
-		DbRelationship dummyR = new DbRelationship("dummy");
-		dummyR.setTargetEntityName("TEST2");
-		dummyR.setSourceEntity(dbEntity1);
-		DbRelationship pathR = new DbRelationship("path");
-		pathR.setTargetEntityName("TEST3");
-		pathR.setSourceEntity(dbEntity2);
-		dbEntity1.addRelationship(dummyR);
-		dbEntity2.addRelationship(pathR);
-
-		ObjRelationship relationship = new ObjRelationship();
-		relationship.setSourceEntity(entity);
-
-		// test how toMany changes dependending on the underlying
-		// DbRelationships
-		// add DbRelationships directly to avoid events to test
-		// "calculateToMany"
-		relationship.dbRelationships.add(dummyR);
-		assertFalse(relationship.isToMany());
-
-		dummyR.setToMany(true);
-		relationship.recalculateToManyValue();
-		assertTrue(relationship.isToMany());
-
-		dummyR.setToMany(false);
-		relationship.recalculateToManyValue();
-		assertFalse(relationship.isToMany());
-
-		// test chain
-		relationship.dbRelationships.add(pathR);
-		assertFalse(relationship.isToMany());
-
-		pathR.setToMany(true);
-		relationship.recalculateToManyValue();
-		assertTrue(relationship.isToMany());
-	}
-
-	public void testCalculateToManyFromPath() {
-		// assemble fixture....
-		DataMap map = new DataMap();
-		ObjEntity entity = new ObjEntity("Test");
-		map.addObjEntity(entity);
-
-		DbEntity dbEntity1 = new DbEntity("TEST1");
-		DbEntity dbEntity2 = new DbEntity("TEST2");
-		DbEntity dbEntity3 = new DbEntity("TEST3");
-		map.addDbEntity(dbEntity1);
-		map.addDbEntity(dbEntity2);
-		map.addDbEntity(dbEntity3);
-		entity.setDbEntityName("TEST1");
-		DbRelationship dummyR = new DbRelationship("dummy");
-		dummyR.setTargetEntityName("TEST2");
-		dummyR.setSourceEntity(dbEntity1);
-		DbRelationship pathR = new DbRelationship("path");
-		pathR.setTargetEntityName("TEST3");
-		pathR.setSourceEntity(dbEntity2);
-		dbEntity1.addRelationship(dummyR);
-		dbEntity2.addRelationship(pathR);
-
-		ObjRelationship relationship = new ObjRelationship();
-		relationship.setSourceEntity(entity);
-
-		// test how toMany changes when the path is set as a string
-
-		relationship.setDbRelationshipPath("dummy");
-		assertFalse(relationship.isToMany());
-
-		dummyR.setToMany(true);
-		relationship.setDbRelationshipPath(null);
-		relationship.setDbRelationshipPath("dummy");
-		assertTrue(relationship.isToMany());
-
-		dummyR.setToMany(false);
-		relationship.setDbRelationshipPath(null);
-		relationship.setDbRelationshipPath("dummy");
-		assertFalse(relationship.isToMany());
-
-		// test chain
-		relationship.setDbRelationshipPath(null);
-		relationship.setDbRelationshipPath("dummy.path");
-		assertFalse(relationship.isToMany());
-
-		pathR.setToMany(true);
-		relationship.setDbRelationshipPath(null);
-		relationship.setDbRelationshipPath("dummy.path");
-		assertTrue(relationship.isToMany());
-	}
-
-	public void testTargetEntity() throws Exception {
-		ObjRelationship relationship = new ObjRelationship("some_rel");
-		relationship.setTargetEntityName("targ");
-
-		try {
-			relationship.getTargetEntity();
-			fail("Without a container, getTargetEntity() must fail.");
-		} catch (CayenneRuntimeException ex) {
-			// expected
-		}
-
-		// assemble container
-		DataMap map = new DataMap();
-		ObjEntity src = new ObjEntity("src");
-		map.addObjEntity(src);
-
-		src.addRelationship(relationship);
-		assertNull(relationship.getTargetEntity());
-
-		ObjEntity target = new ObjEntity("targ");
-		map.addObjEntity(target);
-
-		assertSame(target, relationship.getTargetEntity());
-	}
-
-	public void testGetReverseRel1() {
-
-		ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Artist");
-		ObjEntity paintingObjEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Painting");
-
-		// start with "to many"
-		ObjRelationship r1 = (ObjRelationship) artistObjEnt
-				.getRelationship("paintingArray");
-		ObjRelationship r2 = r1.getReverseRelationship();
-
-		assertNotNull(r2);
-		assertSame(paintingObjEnt.getRelationship("toArtist"), r2);
-	}
-
-	public void testGetReverseRel2() {
-		ObjEntity artistEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Artist");
-		ObjEntity paintingEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Painting");
-
-		// start with "to one"
-		ObjRelationship r1 = (ObjRelationship) paintingEnt
-				.getRelationship("toArtist");
-		ObjRelationship r2 = r1.getReverseRelationship();
-
-		assertNotNull(r2);
-		assertSame(artistEnt.getRelationship("paintingArray"), r2);
-	}
-
-	public void testSingleDbRelationship() {
-		ObjRelationship relationship = new ObjRelationship();
-		DbRelationship r1 = new DbRelationship("X");
-		relationship.addDbRelationship(r1);
-		assertEquals(1, relationship.getDbRelationships().size());
-		assertEquals(r1, relationship.getDbRelationships().get(0));
-		assertFalse(relationship.isFlattened());
-		assertFalse(relationship.isReadOnly());
-		assertEquals(r1.isToMany(), relationship.isToMany());
-		relationship.removeDbRelationship(r1);
-		assertEquals(0, relationship.getDbRelationships().size());
-	}
-
-	public void testFlattenedRelationship() {
-		DbRelationship r1 = new DbRelationship("X");
-		DbRelationship r2 = new DbRelationship("Y");
-
-		r1.setSourceEntity(artistDBEntity);
-		r1.setTargetEntity(artistExhibitDBEntity);
-		r1.setToMany(true);
-
-		r2.setSourceEntity(artistExhibitDBEntity);
-		r2.setTargetEntity(exhibitDBEntity);
-		r2.setToMany(false);
-
-		ObjRelationship relationship = new ObjRelationship();
-		relationship.addDbRelationship(r1);
-		relationship.addDbRelationship(r2);
-		assertTrue(relationship.isToMany());
-		assertEquals(2, relationship.getDbRelationships().size());
-		assertEquals(r1, relationship.getDbRelationships().get(0));
-		assertEquals(r2, relationship.getDbRelationships().get(1));
-
-		assertTrue(relationship.isFlattened());
-
-		relationship.removeDbRelationship(r1);
-		assertFalse(relationship.isToMany()); // only remaining rel is r2... a
-												// toOne
-		assertEquals(1, relationship.getDbRelationships().size());
-		assertEquals(r2, relationship.getDbRelationships().get(0));
-		assertFalse(relationship.isFlattened());
-		assertFalse(relationship.isReadOnly());
-
-	}
-
-	public void testReadOnly_Flattened1_1__N_1() {
-
-		// check common vertical inheritance relationships
-
-		DataMapLoader loader = runtime.getInjector().getInstance(
-				DataMapLoader.class);
-		URL url = getClass().getClassLoader().getResource(
-				"inheritance-vertical.map.xml");
-		DataMap dataMap = loader.load(new URLResource(url));
-		EntityResolver resolver = new EntityResolver(
-				Collections.singleton(dataMap));
-
-		ObjEntity iv2Sub1 = resolver.getObjEntity(Iv2Sub1.class);
-		ObjRelationship x = (ObjRelationship) iv2Sub1
-				.getRelationship(Iv2Sub1.X_PROPERTY);
-		assertTrue(x.isFlattened());
-		assertFalse(x.isReadOnly());
-	}
-
-	public void testReadOnlyMoreThan3DbRelsRelationship() {
-		// Readonly is a flattened relationship that isn't over a single
-		// many->many link
-		// table
-		DbRelationship r1 = new DbRelationship("X");
-		DbRelationship r2 = new DbRelationship("Y");
-		DbRelationship r3 = new DbRelationship("Z");
-
-		r1.setSourceEntity(artistDBEntity);
-		r1.setTargetEntity(artistExhibitDBEntity);
-		r1.setToMany(true);
-		r2.setSourceEntity(artistExhibitDBEntity);
-		r2.setTargetEntity(exhibitDBEntity);
-		r2.setToMany(false);
-		r3.setSourceEntity(exhibitDBEntity);
-		r3.setTargetEntity(galleryDBEntity);
-		r3.setToMany(false);
-
-		ObjRelationship relationship = new ObjRelationship();
-		relationship.addDbRelationship(r1);
-		relationship.addDbRelationship(r2);
-		relationship.addDbRelationship(r3);
-
-		assertTrue(relationship.isFlattened());
-		assertTrue(relationship.isReadOnly());
-		assertTrue(relationship.isToMany());
-
-	}
-
-	// Test for a read-only flattened relationship that is readonly because it's
-	// dbrel
-	// sequence is "incorrect" (or rather, unsupported)
-	public void testIncorrectSequenceReadOnlyRelationship() {
-		DbRelationship r1 = new DbRelationship("X");
-		DbRelationship r2 = new DbRelationship("Y");
-
-		r1.setSourceEntity(artistDBEntity);
-		r1.setTargetEntity(paintingDbEntity);
-		r1.setToMany(true);
-		r2.setSourceEntity(paintingDbEntity);
-		r2.setTargetEntity(galleryDBEntity);
-		r2.setToMany(false);
-
-		ObjRelationship relationship = new ObjRelationship();
-		relationship.addDbRelationship(r1);
-		relationship.addDbRelationship(r2);
-
-		assertTrue(relationship.isFlattened());
-		assertTrue(relationship.isReadOnly());
-		assertTrue(relationship.isToMany());
-	}
-
-	// Test a relationship loaded from the test datamap that we know should be
-	// flattened
-	public void testKnownFlattenedRelationship() {
-		ObjEntity artistEnt = runtime.getDataDomain().getEntityResolver()
-				.getObjEntity("Artist");
-		ObjRelationship theRel = (ObjRelationship) artistEnt
-				.getRelationship("groupArray");
-		assertNotNull(theRel);
-		assertTrue(theRel.isFlattened());
-		assertFalse(theRel.isReadOnly());
-	}
-
-	public void testBadDeleteRuleValue() {
-		ObjRelationship relationship = new ObjRelationship();
-
-		try {
-			relationship.setDeleteRule(999);
-			fail("Should have failed with IllegalArgumentException");
-		} catch (IllegalArgumentException e) {
-			// Good... it should throw an exception
-		}
-	}
-
-	public void testOkDeleteRuleValue() {
-		ObjRelationship relationship = new ObjRelationship();
-		try {
-			relationship.setDeleteRule(DeleteRule.CASCADE);
-			relationship.setDeleteRule(DeleteRule.DENY);
-			relationship.setDeleteRule(DeleteRule.NULLIFY);
-		} catch (IllegalArgumentException e) {
-			e.printStackTrace();
-			fail("Should not have thrown an exception :" + e.getMessage());
-		}
-	}
+    private DbEntity artistDBEntity;
+    private DbEntity artistExhibitDBEntity;
+    private DbEntity exhibitDBEntity;
+    private DbEntity paintingDbEntity;
+    private DbEntity galleryDBEntity;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+
+        artistDBEntity = resolver.getDbEntity("ARTIST");
+        artistExhibitDBEntity = resolver.getDbEntity("ARTIST_EXHIBIT");
+        exhibitDBEntity = resolver.getDbEntity("EXHIBIT");
+        paintingDbEntity = resolver.getDbEntity("PAINTING");
+        galleryDBEntity = resolver.getDbEntity("GALLERY");
+    }
+
+    public void testEncodeAsXML() {
+        StringWriter buffer = new StringWriter();
+        PrintWriter out = new PrintWriter(buffer);
+        XMLEncoder encoder = new XMLEncoder(out);
+
+        DataMap map = new DataMap("M");
+        ObjEntity source = new ObjEntity("S");
+        ObjEntity target = new ObjEntity("T");
+        map.addObjEntity(source);
+        map.addObjEntity(target);
+
+        ObjRelationship r = new ObjRelationship("X");
+        r.setSourceEntity(source);
+        r.setTargetEntityName("T");
+        r.setCollectionType("java.util.Map");
+        r.setMapKey("bla");
+
+        r.encodeAsXML(encoder);
+        out.close();
+
+        String lineBreak = System.getProperty("line.separator");
+
+        assertEquals("<obj-relationship name=\"X\" source=\"S\" target=\"T\" "
+                + "collection-type=\"java.util.Map\" map-key=\"bla\"/>" + lineBreak, buffer.getBuffer().toString());
+    }
+
+    public void testCollectionType() {
+        ObjRelationship r = new ObjRelationship("X");
+        assertNull(r.getCollectionType());
+        r.setCollectionType("java.util.Map");
+        assertEquals("java.util.Map", r.getCollectionType());
+    }
+
+    public void testSerializability() throws Exception {
+        ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+
+        // start with "to many"
+        ObjRelationship r1 = artistObjEnt.getRelationship("paintingArray");
+
+        ObjRelationship r2 = Util.cloneViaSerialization(r1);
+        assertEquals(r1.getName(), r2.getName());
+        assertEquals(r1.getDbRelationshipPath(), r2.getDbRelationshipPath());
+    }
+
+    public void testGetClientRelationship() {
+        final ObjEntity target = new ObjEntity("te1");
+        ObjRelationship r1 = new ObjRelationship("r1") {
+
+            @Override
+            public ObjEntity getTargetEntity() {
+                return target;
+            }
+        };
+
+        r1.setDeleteRule(DeleteRule.DENY);
+        r1.setTargetEntityName("te1");
+
+        ObjRelationship r2 = r1.getClientRelationship();
+        assertNotNull(r2);
+        assertEquals(r1.getName(), r2.getName());
+        assertEquals(r1.getTargetEntityName(), r2.getTargetEntityName());
+        assertEquals(r1.getDeleteRule(), r2.getDeleteRule());
+    }
+
+    public void testGetReverseDbRelationshipPath() {
+        ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        ObjEntity paintingObjEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Painting");
+
+        // start with "to many"
+        ObjRelationship r1 = artistObjEnt.getRelationship("paintingArray");
+
+        assertEquals("toArtist", r1.getReverseDbRelationshipPath());
+
+        ObjRelationship r2 = paintingObjEnt.getRelationship("toArtist");
+
+        assertEquals("paintingArray", r2.getReverseDbRelationshipPath());
+    }
+
+    public void testSetDbRelationshipPath() {
+        ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+
+        ObjRelationship r = new ObjRelationship("r");
+        r.setSourceEntity(artistObjEnt);
+        r.setDbRelationshipPath("paintingArray");
+        assertEquals(r.getDbRelationshipPath(), "paintingArray");
+    }
+
+    public void testRefreshFromPath() {
+        ObjRelationship relationship = new ObjRelationship();
+
+        // attempt to resolve must fail - relationship is outside of context,
+        // plus the path is random
+        try {
+            relationship.setDbRelationshipPath("dummy.path");
+            fail("set random path should have failed.");
+        } catch (CayenneRuntimeException ex) {
+            // expected
+        }
+
+        DataMap map = new DataMap();
+        ObjEntity entity = new ObjEntity("Test");
+        map.addObjEntity(entity);
+
+        relationship.setSourceEntity(entity);
+        // attempt to resolve must fail - relationship is outside of context,
+        // plus the path is random
+        try {
+            relationship.refreshFromPath("dummy.path", false);
+            fail("refresh over a dummy path should have failed.");
+        } catch (ExpressionException ex) {
+            // expected
+        }
+
+        // finally assemble ObjEntity to make the path valid
+        DbEntity dbEntity1 = new DbEntity("TEST1");
+        DbEntity dbEntity2 = new DbEntity("TEST2");
+        DbEntity dbEntity3 = new DbEntity("TEST3");
+        map.addDbEntity(dbEntity1);
+        map.addDbEntity(dbEntity2);
+        map.addDbEntity(dbEntity3);
+        entity.setDbEntityName("TEST1");
+        DbRelationship dummyR = new DbRelationship("dummy");
+        dummyR.setTargetEntityName("TEST2");
+        dummyR.setSourceEntity(dbEntity1);
+        DbRelationship pathR = new DbRelationship("path");
+        pathR.setTargetEntityName("TEST3");
+        pathR.setSourceEntity(dbEntity2);
+        dbEntity1.addRelationship(dummyR);
+        dbEntity2.addRelationship(pathR);
+
+        relationship.refreshFromPath("dummy.path", false);
+
+        List<DbRelationship> resolvedPath = relationship.getDbRelationships();
+        assertEquals(2, resolvedPath.size());
+        assertSame(dummyR, resolvedPath.get(0));
+        assertSame(pathR, resolvedPath.get(1));
+    }
+
+    public void testCalculateToMany() {
+        // assemble fixture....
+        DataMap map = new DataMap();
+        ObjEntity entity = new ObjEntity("Test");
+        map.addObjEntity(entity);
+
+        DbEntity dbEntity1 = new DbEntity("TEST1");
+        DbEntity dbEntity2 = new DbEntity("TEST2");
+        DbEntity dbEntity3 = new DbEntity("TEST3");
+        map.addDbEntity(dbEntity1);
+        map.addDbEntity(dbEntity2);
+        map.addDbEntity(dbEntity3);
+        entity.setDbEntityName("TEST1");
+        DbRelationship dummyR = new DbRelationship("dummy");
+        dummyR.setTargetEntityName("TEST2");
+        dummyR.setSourceEntity(dbEntity1);
+        DbRelationship pathR = new DbRelationship("path");
+        pathR.setTargetEntityName("TEST3");
+        pathR.setSourceEntity(dbEntity2);
+        dbEntity1.addRelationship(dummyR);
+        dbEntity2.addRelationship(pathR);
+
+        ObjRelationship relationship = new ObjRelationship();
+        relationship.setSourceEntity(entity);
+
+        // test how toMany changes dependending on the underlying
+        // DbRelationships
+        // add DbRelationships directly to avoid events to test
+        // "calculateToMany"
+        relationship.dbRelationships.add(dummyR);
+        assertFalse(relationship.isToMany());
+
+        dummyR.setToMany(true);
+        relationship.recalculateToManyValue();
+        assertTrue(relationship.isToMany());
+
+        dummyR.setToMany(false);
+        relationship.recalculateToManyValue();
+        assertFalse(relationship.isToMany());
+
+        // test chain
+        relationship.dbRelationships.add(pathR);
+        assertFalse(relationship.isToMany());
+
+        pathR.setToMany(true);
+        relationship.recalculateToManyValue();
+        assertTrue(relationship.isToMany());
+    }
+
+    public void testCalculateToManyFromPath() {
+        // assemble fixture....
+        DataMap map = new DataMap();
+        ObjEntity entity = new ObjEntity("Test");
+        map.addObjEntity(entity);
+
+        DbEntity dbEntity1 = new DbEntity("TEST1");
+        DbEntity dbEntity2 = new DbEntity("TEST2");
+        DbEntity dbEntity3 = new DbEntity("TEST3");
+        map.addDbEntity(dbEntity1);
+        map.addDbEntity(dbEntity2);
+        map.addDbEntity(dbEntity3);
+        entity.setDbEntityName("TEST1");
+        DbRelationship dummyR = new DbRelationship("dummy");
+        dummyR.setTargetEntityName("TEST2");
+        dummyR.setSourceEntity(dbEntity1);
+        DbRelationship pathR = new DbRelationship("path");
+        pathR.setTargetEntityName("TEST3");
+        pathR.setSourceEntity(dbEntity2);
+        dbEntity1.addRelationship(dummyR);
+        dbEntity2.addRelationship(pathR);
+
+        ObjRelationship relationship = new ObjRelationship();
+        relationship.setSourceEntity(entity);
+
+        // test how toMany changes when the path is set as a string
+
+        relationship.setDbRelationshipPath("dummy");
+        assertFalse(relationship.isToMany());
+
+        dummyR.setToMany(true);
+        relationship.setDbRelationshipPath(null);
+        relationship.setDbRelationshipPath("dummy");
+        assertTrue(relationship.isToMany());
+
+        dummyR.setToMany(false);
+        relationship.setDbRelationshipPath(null);
+        relationship.setDbRelationshipPath("dummy");
+        assertFalse(relationship.isToMany());
+
+        // test chain
+        relationship.setDbRelationshipPath(null);
+        relationship.setDbRelationshipPath("dummy.path");
+        assertFalse(relationship.isToMany());
+
+        pathR.setToMany(true);
+        relationship.setDbRelationshipPath(null);
+        relationship.setDbRelationshipPath("dummy.path");
+        assertTrue(relationship.isToMany());
+    }
+
+    public void testTargetEntity() throws Exception {
+        ObjRelationship relationship = new ObjRelationship("some_rel");
+        relationship.setTargetEntityName("targ");
+
+        try {
+            relationship.getTargetEntity();
+            fail("Without a container, getTargetEntity() must fail.");
+        } catch (CayenneRuntimeException ex) {
+            // expected
+        }
+
+        // assemble container
+        DataMap map = new DataMap();
+        ObjEntity src = new ObjEntity("src");
+        map.addObjEntity(src);
+
+        src.addRelationship(relationship);
+        assertNull(relationship.getTargetEntity());
+
+        ObjEntity target = new ObjEntity("targ");
+        map.addObjEntity(target);
+
+        assertSame(target, relationship.getTargetEntity());
+    }
+
+    public void testGetReverseRel1() {
+
+        ObjEntity artistObjEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        ObjEntity paintingObjEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Painting");
+
+        // start with "to many"
+        ObjRelationship r1 = artistObjEnt.getRelationship("paintingArray");
+        ObjRelationship r2 = r1.getReverseRelationship();
+
+        assertNotNull(r2);
+        assertSame(paintingObjEnt.getRelationship("toArtist"), r2);
+    }
+
+    public void testGetReverseRel2() {
+        ObjEntity artistEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        ObjEntity paintingEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Painting");
+
+        // start with "to one"
+        ObjRelationship r1 = paintingEnt.getRelationship("toArtist");
+        ObjRelationship r2 = r1.getReverseRelationship();
+
+        assertNotNull(r2);
+        assertSame(artistEnt.getRelationship("paintingArray"), r2);
+    }
+
+    public void testSingleDbRelationship() {
+        ObjRelationship relationship = new ObjRelationship();
+        DbRelationship r1 = new DbRelationship("X");
+        relationship.addDbRelationship(r1);
+        assertEquals(1, relationship.getDbRelationships().size());
+        assertEquals(r1, relationship.getDbRelationships().get(0));
+        assertFalse(relationship.isFlattened());
+        assertFalse(relationship.isReadOnly());
+        assertEquals(r1.isToMany(), relationship.isToMany());
+        relationship.removeDbRelationship(r1);
+        assertEquals(0, relationship.getDbRelationships().size());
+    }
+
+    public void testFlattenedRelationship() {
+        DbRelationship r1 = new DbRelationship("X");
+        DbRelationship r2 = new DbRelationship("Y");
+
+        r1.setSourceEntity(artistDBEntity);
+        r1.setTargetEntity(artistExhibitDBEntity);
+        r1.setToMany(true);
+
+        r2.setSourceEntity(artistExhibitDBEntity);
+        r2.setTargetEntity(exhibitDBEntity);
+        r2.setToMany(false);
+
+        ObjRelationship relationship = new ObjRelationship();
+        relationship.addDbRelationship(r1);
+        relationship.addDbRelationship(r2);
+        assertTrue(relationship.isToMany());
+        assertEquals(2, relationship.getDbRelationships().size());
+        assertEquals(r1, relationship.getDbRelationships().get(0));
+        assertEquals(r2, relationship.getDbRelationships().get(1));
+
+        assertTrue(relationship.isFlattened());
+
+        relationship.removeDbRelationship(r1);
+        assertFalse(relationship.isToMany()); // only remaining rel is r2... a
+                                              // toOne
+        assertEquals(1, relationship.getDbRelationships().size());
+        assertEquals(r2, relationship.getDbRelationships().get(0));
+        assertFalse(relationship.isFlattened());
+        assertFalse(relationship.isReadOnly());
+
+    }
+
+    public void testReadOnly_Flattened1_1__N_1() {
+
+        // check common vertical inheritance relationships
+
+        DataMapLoader loader = runtime.getInjector().getInstance(DataMapLoader.class);
+        URL url = getClass().getClassLoader().getResource("inheritance-vertical.map.xml");
+        DataMap dataMap = loader.load(new URLResource(url));
+        EntityResolver resolver = new EntityResolver(Collections.singleton(dataMap));
+
+        ObjEntity iv2Sub1 = resolver.getObjEntity(Iv2Sub1.class);
+        ObjRelationship x = iv2Sub1.getRelationship(Iv2Sub1.X_PROPERTY);
+        assertTrue(x.isFlattened());
+        assertFalse(x.isReadOnly());
+    }
+
+    public void testReadOnlyMoreThan3DbRelsRelationship() {
+        // Readonly is a flattened relationship that isn't over a single
+        // many->many link
+        // table
+        DbRelationship r1 = new DbRelationship("X");
+        DbRelationship r2 = new DbRelationship("Y");
+        DbRelationship r3 = new DbRelationship("Z");
+
+        r1.setSourceEntity(artistDBEntity);
+        r1.setTargetEntity(artistExhibitDBEntity);
+        r1.setToMany(true);
+        r2.setSourceEntity(artistExhibitDBEntity);
+        r2.setTargetEntity(exhibitDBEntity);
+        r2.setToMany(false);
+        r3.setSourceEntity(exhibitDBEntity);
+        r3.setTargetEntity(galleryDBEntity);
+        r3.setToMany(false);
+
+        ObjRelationship relationship = new ObjRelationship();
+        relationship.addDbRelationship(r1);
+        relationship.addDbRelationship(r2);
+        relationship.addDbRelationship(r3);
+
+        assertTrue(relationship.isFlattened());
+        assertTrue(relationship.isReadOnly());
+        assertTrue(relationship.isToMany());
+
+    }
+
+    // Test for a read-only flattened relationship that is readonly because it's
+    // dbrel
+    // sequence is "incorrect" (or rather, unsupported)
+    public void testIncorrectSequenceReadOnlyRelationship() {
+        DbRelationship r1 = new DbRelationship("X");
+        DbRelationship r2 = new DbRelationship("Y");
+
+        r1.setSourceEntity(artistDBEntity);
+        r1.setTargetEntity(paintingDbEntity);
+        r1.setToMany(true);
+        r2.setSourceEntity(paintingDbEntity);
+        r2.setTargetEntity(galleryDBEntity);
+        r2.setToMany(false);
+
+        ObjRelationship relationship = new ObjRelationship();
+        relationship.addDbRelationship(r1);
+        relationship.addDbRelationship(r2);
+
+        assertTrue(relationship.isFlattened());
+        assertTrue(relationship.isReadOnly());
+        assertTrue(relationship.isToMany());
+    }
+
+    // Test a relationship loaded from the test datamap that we know should be
+    // flattened
+    public void testKnownFlattenedRelationship() {
+        ObjEntity artistEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        ObjRelationship theRel = artistEnt.getRelationship("groupArray");
+        assertNotNull(theRel);
+        assertTrue(theRel.isFlattened());
+        assertFalse(theRel.isReadOnly());
+    }
+
+    public void testBadDeleteRuleValue() {
+        ObjRelationship relationship = new ObjRelationship();
+
+        try {
+            relationship.setDeleteRule(999);
+            fail("Should have failed with IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // Good... it should throw an exception
+        }
+    }
+
+    public void testOkDeleteRuleValue() {
+        ObjRelationship relationship = new ObjRelationship();
+        try {
+            relationship.setDeleteRule(DeleteRule.CASCADE);
+            relationship.setDeleteRule(DeleteRule.DENY);
+            relationship.setDeleteRule(DeleteRule.NULLIFY);
+        } catch (IllegalArgumentException e) {
+            e.printStackTrace();
+            fail("Should not have thrown an exception :" + e.getMessage());
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java Sun Aug  4 18:04:14 2013
@@ -597,17 +597,16 @@ public class SelectQueryTest extends Ser
         ObjEntity galleryEntity = resolver.getObjEntity(Gallery.class);
         ObjEntity artistExhibitEntity = resolver.getObjEntity(ArtistExhibit.class);
         ObjEntity exhibitEntity = resolver.getObjEntity(Exhibit.class);
-        ObjRelationship paintingToArtistRel = (ObjRelationship) paintingEntity.getRelationship("toArtist");
+        ObjRelationship paintingToArtistRel = paintingEntity.getRelationship("toArtist");
         paintingEntity.removeRelationship("toArtist");
 
-        ObjRelationship galleryToPaintingRel = (ObjRelationship) galleryEntity.getRelationship("paintingArray");
+        ObjRelationship galleryToPaintingRel = galleryEntity.getRelationship("paintingArray");
         galleryEntity.removeRelationship("paintingArray");
 
-        ObjRelationship artistExhibitToArtistRel = (ObjRelationship) artistExhibitEntity.getRelationship("toArtist");
+        ObjRelationship artistExhibitToArtistRel = artistExhibitEntity.getRelationship("toArtist");
         artistExhibitEntity.removeRelationship("toArtist");
 
-        ObjRelationship exhibitToArtistExhibitRel = (ObjRelationship) exhibitEntity
-                .getRelationship("artistExhibitArray");
+        ObjRelationship exhibitToArtistExhibitRel = exhibitEntity.getRelationship("artistExhibitArray");
         exhibitEntity.removeRelationship("artistExhibitArray");
 
         Expression e = ExpressionFactory.matchExp("artistName", "artist1");

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/util/EntityMergeSupportTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/util/EntityMergeSupportTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/util/EntityMergeSupportTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/util/EntityMergeSupportTest.java Sun Aug  4 18:04:14 2013
@@ -27,7 +27,6 @@ import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.DeleteRule;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.merge.MergeCase;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
@@ -84,17 +83,13 @@ public class EntityMergeSupportTest exte
         objEntity2.setDbEntity(dbEntity2);
         map.addObjEntity(objEntity2);
 
-        assertTrue(new EntityMergeSupport(map).synchronizeWithDbEntities(Arrays.asList(
-                objEntity1,
-                objEntity2)));
+        assertTrue(new EntityMergeSupport(map).synchronizeWithDbEntities(Arrays.asList(objEntity1, objEntity2)));
         assertNotNull(objEntity1.getAttribute("name"));
         assertNotNull(objEntity1.getRelationship("rel1To2"));
         assertNotNull(objEntity2.getRelationship("rel2To1"));
 
-        assertEquals(((ObjRelationship) objEntity1.getRelationship("rel1To2"))
-                .getDeleteRule(), DeleteRule.DEFAULT_DELETE_RULE_TO_MANY);
-        assertEquals(((ObjRelationship) objEntity2.getRelationship("rel2To1"))
-                .getDeleteRule(), DeleteRule.DEFAULT_DELETE_RULE_TO_ONE);
+        assertEquals(objEntity1.getRelationship("rel1To2").getDeleteRule(), DeleteRule.DEFAULT_DELETE_RULE_TO_MANY);
+        assertEquals(objEntity2.getRelationship("rel2To1").getDeleteRule(), DeleteRule.DEFAULT_DELETE_RULE_TO_ONE);
 
         map.removeObjEntity(objEntity2.getName());
         map.removeObjEntity(objEntity1.getName());

Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/EntityUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/EntityUtils.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/EntityUtils.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/java/org/apache/cayenne/gen/EntityUtils.java Sun Aug  4 18:04:14 2013
@@ -19,13 +19,20 @@
 
 package org.apache.cayenne.gen;
 
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.map.*;
-
 import java.util.Collection;
 import java.util.LinkedHashSet;
 
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.map.CallbackDescriptor;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.MappingNamespace;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.map.Relationship;
+
 /**
  * Attributes and Methods for working with ObjEntities.
  * 
@@ -46,8 +53,8 @@ public class EntityUtils {
 
     protected Collection<String> callbackNames;
 
-    public EntityUtils(DataMap dataMap, ObjEntity objEntity, String fqnBaseClass,
-            String fqnSuperClass, String fqnSubClass) {
+    public EntityUtils(DataMap dataMap, ObjEntity objEntity, String fqnBaseClass, String fqnSuperClass,
+            String fqnSubClass) {
 
         StringUtils stringUtils = StringUtils.getInstance();
 
@@ -66,12 +73,11 @@ public class EntityUtils {
         for (CallbackDescriptor cb : objEntity.getCallbackMap().getCallbacks()) {
             callbackNames.addAll(cb.getCallbackMethods());
         }
-        
+
     }
 
-    EntityUtils(DataMap dataMap, ObjEntity objEntity, String baseClassName,
-            String basePackageName, String superClassName, String superPackageName,
-            String subClassName, String subPackageName) {
+    EntityUtils(DataMap dataMap, ObjEntity objEntity, String baseClassName, String basePackageName,
+            String superClassName, String superPackageName, String subClassName, String subPackageName) {
 
         this.baseClassName = baseClassName;
         this.basePackageName = basePackageName;
@@ -125,7 +131,8 @@ public class EntityUtils {
     }
 
     /**
-     * Returns true if current ObjEntity contains at least one toMany relationship.
+     * Returns true if current ObjEntity contains at least one toMany
+     * relationship.
      */
     public boolean hasToManyRelationships() {
         return hasToManyRelationships(objEntity);
@@ -149,8 +156,8 @@ public class EntityUtils {
     }
 
     /**
-     * Returns true if current ObjEntity contains at least one toMany relationship,
-     * ignoring those declared in superentities.
+     * Returns true if current ObjEntity contains at least one toMany
+     * relationship, ignoring those declared in superentities.
      * 
      * @since 1.2
      */
@@ -159,8 +166,8 @@ public class EntityUtils {
     }
 
     /**
-     * Returns true if an ObjEntity contains at least one toMany relationship, ignoring
-     * those declared in superentities.
+     * Returns true if an ObjEntity contains at least one toMany relationship,
+     * ignoring those declared in superentities.
      * 
      * @since 1.2
      */
@@ -179,7 +186,8 @@ public class EntityUtils {
     }
 
     /**
-     * Returns true if current ObjEntity contains at least one toOne relationship.
+     * Returns true if current ObjEntity contains at least one toOne
+     * relationship.
      */
     public boolean hasToOneRelationships() {
         return hasToOneRelationships(objEntity);
@@ -203,16 +211,16 @@ public class EntityUtils {
     }
 
     /**
-     * Returns true if current ObjEntity contains at least one toOne relationship,
-     * ignoring those declared in superentities.
+     * Returns true if current ObjEntity contains at least one toOne
+     * relationship, ignoring those declared in superentities.
      */
     public boolean hasToOneDeclaredRelationships() {
         return hasToOneDeclaredRelationships(objEntity);
     }
 
     /**
-     * Returns true if an ObjEntity contains at least one toOne relationship, ignoring
-     * those declared in superentities.
+     * Returns true if an ObjEntity contains at least one toOne relationship,
+     * ignoring those declared in superentities.
      */
     public boolean hasToOneDeclaredRelationships(ObjEntity anObjEntity) {
         if (anObjEntity == null) {
@@ -229,37 +237,41 @@ public class EntityUtils {
     }
 
     /**
-     * Returns the map key type for a collection relationship of type java.util.Map.
+     * Returns the map key type for a collection relationship of type
+     * java.util.Map.
      * 
-     * @param relationship The relationship to look up type information for.
+     * @param relationship
+     *            The relationship to look up type information for.
      * @return The type of the attribute keyed on.
      */
     public String getMapKeyType(final ObjRelationship relationship) {
 
         ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
 
-        // If the map key is null, then we're doing look-ups by actual object key.
+        // If the map key is null, then we're doing look-ups by actual object
+        // key.
         if (relationship.getMapKey() == null) {
 
-            // If it's a multi-column key, then the return type is always ObjectId.
+            // If it's a multi-column key, then the return type is always
+            // ObjectId.
             DbEntity dbEntity = targetEntity.getDbEntity();
             if ((dbEntity != null) && (dbEntity.getPrimaryKeys().size() > 1)) {
                 return ObjectId.class.getName();
             }
 
-            // If it's a single column key or no key exists at all, then we really don't
+            // If it's a single column key or no key exists at all, then we
+            // really don't
             // know what the key type is,
             // so default to Object.
             return Object.class.getName();
         }
 
-        // If the map key is a non-default attribute, then fetch the attribute and return
+        // If the map key is a non-default attribute, then fetch the attribute
+        // and return
         // its type.
-        ObjAttribute attribute = (ObjAttribute) targetEntity.getAttribute(relationship
-                .getMapKey());
+        ObjAttribute attribute = targetEntity.getAttribute(relationship.getMapKey());
         if (attribute == null) {
-            throw new CayenneRuntimeException("Invalid map key '"
-                    + relationship.getMapKey()
+            throw new CayenneRuntimeException("Invalid map key '" + relationship.getMapKey()
                     + "', no matching attribute found");
         }
 

Modified: cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java Sun Aug  4 18:04:14 2013
@@ -28,7 +28,6 @@ import junit.framework.TestCase;
 
 import org.apache.cayenne.map.CallbackDescriptor;
 import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
@@ -101,7 +100,7 @@ public class ClassGenerationActionTest e
             }
             
             @Override
-            public Entity getTargetEntity() {
+            public ObjEntity getTargetEntity() {
                 return testEntity2;
             }
         };

Modified: cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-tools/src/test/java/org/apache/cayenne/tools/dbimport/DbImportActionTest.java Sun Aug  4 18:04:14 2013
@@ -214,7 +214,7 @@ public class DbImportActionTest extends 
 
         ObjEntity oe1 = map.getObjEntity("E1");
 
-        ObjAttribute oa1 = (ObjAttribute) oe1.getAttribute("nonPk");
+        ObjAttribute oa1 = oe1.getAttribute("nonPk");
         assertEquals("java.lang.Integer", oa1.getType());
     }
 
@@ -248,7 +248,7 @@ public class DbImportActionTest extends 
 
         ObjEntity oe1 = map.getObjEntity("E1");
 
-        ObjAttribute oa1 = (ObjAttribute) oe1.getAttribute("nonPk");
+        ObjAttribute oa1 = oe1.getAttribute("nonPk");
         assertEquals("int", oa1.getType());
     }