cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmen...@apache.org
Subject svn commit: r618081 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ framework/cayenne-jdk1.5-unpubl...
Date Sun, 03 Feb 2008 20:41:18 GMT
Author: kmenard
Date: Sun Feb  3 12:41:16 2008
New Revision: 618081

URL: http://svn.apache.org/viewvc?rev=618081&view=rev
Log:
Fixed CAY-574: DataObjectUtils 'objectForPK' should work on the client

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ClientObjEntity.java
Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataObjectUtils.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=618081&r1=618080&r2=618081&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Sun Feb  3 12:41:16 2008
@@ -17,9 +17,13 @@
 CAY-970 Allow application to add DbAdatperFactory to AutoAdapter
 CAY-980 Upgrade Derby to 10.3 to support alter table drop column
 
+Bug fixes since M3:
+
+CAY-574: DataObjectUtils 'objectForPK' should work on the client
+
 ----------------------------------
 Release: 3.0M3
-Date: 
+Date: 02/04/2008
 ----------------------------------
 
 Changes/New Features Since M2:
@@ -69,7 +73,7 @@
 
 ----------------------------------
 Release: 3.0M2
-Date: 
+Date: 11/11/2007
 ----------------------------------
 
 Changes/New Features Since M1:

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataObjectUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataObjectUtils.java?rev=618081&r1=618080&r2=618081&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataObjectUtils.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataObjectUtils.java
Sun Feb  3 12:41:16 2008
@@ -300,21 +300,15 @@
             throw new CayenneRuntimeException("Non-existent ObjEntity: " + objEntityName);
         }
 
-        DbEntity dbEntity = entity.getDbEntity();
-        if (dbEntity == null) {
-            throw new CayenneRuntimeException("No DbEntity for ObjEntity: "
-                    + entity.getName());
-        }
-
-        Collection<DbAttribute> pkAttributes = dbEntity.getPrimaryKeys();
+        Collection<String> pkAttributes = entity.getPrimaryKeyNames();
         if (pkAttributes.size() != 1) {
             throw new CayenneRuntimeException("PK contains "
                     + pkAttributes.size()
                     + " columns, expected 1.");
         }
 
-        DbAttribute attr = pkAttributes.iterator().next();
-        return new ObjectId(objEntityName, attr.getName(), pk);
+        String attr = pkAttributes.iterator().next();
+        return new ObjectId(objEntityName, attr, pk);
     }
 
     static ObjectId buildId(ObjectContext context, Class<?> dataObjectClass, Object
pk) {
@@ -332,21 +326,15 @@
                     + dataObjectClass.getName());
         }
 
-        DbEntity dbEntity = entity.getDbEntity();
-        if (dbEntity == null) {
-            throw new CayenneRuntimeException("No DbEntity for ObjEntity: "
-                    + entity.getName());
-        }
-
-        Collection<DbAttribute> pkAttributes = dbEntity.getPrimaryKeys();
+        Collection<String> pkAttributes = entity.getPrimaryKeyNames();
         if (pkAttributes.size() != 1) {
             throw new CayenneRuntimeException("PK contains "
                     + pkAttributes.size()
                     + " columns, expected 1.");
         }
 
-        DbAttribute attr = pkAttributes.iterator().next();
-        return new ObjectId(entity.getName(), attr.getName(), pk);
+        String attr = pkAttributes.iterator().next();
+        return new ObjectId(entity.getName(), attr, pk);
     }
 
     // not intended for instantiation

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ClientObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ClientObjEntity.java?rev=618081&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ClientObjEntity.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ClientObjEntity.java
Sun Feb  3 12:41:16 2008
@@ -0,0 +1,33 @@
+package org.apache.cayenne.map;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A client version of ObjEntity that delegates some of its method calls to
+ * its corresponding server entity.
+ *
+ * @since 3.0
+ * @author Kevin Menard
+ */
+public class ClientObjEntity extends ObjEntity {
+
+    private Collection<String> primaryKeyNames;
+
+    public ClientObjEntity() {
+        super();
+    }
+
+    public ClientObjEntity(final String name) {
+        super(name);
+    }
+
+    @Override
+    public Collection<String> getPrimaryKeyNames() {
+        return Collections.unmodifiableCollection(primaryKeyNames);
+    }
+
+    public void setPrimaryKeyNames(final Collection<String> primaryKeyNames) {
+        this.primaryKeyNames = primaryKeyNames;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=618081&r1=618080&r2=618081&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Sun Feb  3 12:41:16 2008
@@ -188,10 +188,11 @@
      */
     public ObjEntity getClientEntity() {
 
-        ObjEntity entity = new ObjEntity(getName());
+        ClientObjEntity entity = new ClientObjEntity(getName());
         entity.setClassName(getClientClassName());
         entity.setSuperClassName(getClientSuperClassName());
         entity.setSuperEntityName(getSuperEntityName());
+        entity.setPrimaryKeyNames(getPrimaryKeyNames());
 
         // TODO: should we also copy lock type?
 
@@ -736,6 +737,22 @@
 
         return null;
     }
+
+    public Collection<String> getPrimaryKeyNames() {
+        if (getDbEntity() == null) {
+            throw new CayenneRuntimeException("No DbEntity for ObjEntity: " + getName());
+        }
+
+        Collection<DbAttribute> pkAttributes = getDbEntity().getPrimaryKeys();
+        Collection<String> ret = new ArrayList<String>(pkAttributes.size());
+        
+        for (DbAttribute pk : pkAttributes) {
+            ret.add(pk.getName());
+        }
+
+        return Collections.unmodifiableCollection(ret);
+    }
+
 
     /**
      * Returns ObjRelationship of this entity that maps to <code>dbRelationship</code>

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java?rev=618081&r1=618080&r2=618081&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/ObjEntityTest.java
Sun Feb  3 12:41:16 2008
@@ -74,6 +74,43 @@
         assertFalse(e1.isClientAllowed());
     }
 
+    public void testGetPrimaryKeyNames() {
+        ObjEntity entity = new ObjEntity("entity");
+        DbEntity dbentity = new DbEntity("dbe");
+
+        // need a container
+        DataMap dataMap = new DataMap();
+        dataMap.addObjEntity(entity);
+        dataMap.addDbEntity(dbentity);
+        entity.setDbEntity(dbentity);
+
+        // Test correctness with no mapped PK.
+        assertEquals(0, entity.getPrimaryKeyNames().size());
+
+
+        // Add a single column PK to the DB entity.
+        DbAttribute pk = new DbAttribute();
+        pk.setName("id");
+        pk.setPrimaryKey(true);
+        dbentity.addAttribute(pk);
+
+        // Test correctness with a single column PK.
+        assertEquals(1, entity.getPrimaryKeyNames().size());
+        assertTrue(entity.getPrimaryKeyNames().contains(pk.getName()));
+
+
+        // Add a multi-column PK to the DB entity.
+        DbAttribute pk2 = new DbAttribute();
+        pk2.setName("id2");
+        pk2.setPrimaryKey(true);
+        dbentity.addAttribute(pk2);
+
+        // Test correctness with a multi-column PK.
+        assertEquals(2, entity.getPrimaryKeyNames().size());
+        assertTrue(entity.getPrimaryKeyNames().contains(pk.getName()));
+        assertTrue(entity.getPrimaryKeyNames().contains(pk2.getName()));
+    }
+
     public void testGetClientEntity() {
         
         DataMap map = new DataMap();
@@ -88,6 +125,10 @@
         e1.addAttribute(new ObjAttribute("A1"));
         e1.addAttribute(new ObjAttribute("A2"));
         map.addObjEntity(e1);
+
+        DbEntity dbentity = new DbEntity("dbe");
+        map.addDbEntity(dbentity);
+        e1.setDbEntity(dbentity);
 
         ObjRelationship r1 = new ObjRelationship("r1") {
 



Mime
View raw message