cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1042377 - in /cayenne/sandbox/cayenne-mixin/trunk: pom.xml src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java
Date Sun, 05 Dec 2010 15:58:44 GMT
Author: aadamchik
Date: Sun Dec  5 15:58:43 2010
New Revision: 1042377

URL: http://svn.apache.org/viewvc?rev=1042377&view=rev
Log:
fixing referenceable lazy init bug

Modified:
    cayenne/sandbox/cayenne-mixin/trunk/pom.xml
    cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java

Modified: cayenne/sandbox/cayenne-mixin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/pom.xml?rev=1042377&r1=1042376&r2=1042377&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/pom.xml (original)
+++ cayenne/sandbox/cayenne-mixin/trunk/pom.xml Sun Dec  5 15:58:43 2010
@@ -8,7 +8,7 @@
 		<version>3.1M1</version>
 	</parent>
 	<artifactId>cayenne-mixin</artifactId>
-	<version>3.1.0.5</version>
+	<version>3.1.0.6</version>
 	<name>Library: cayenne-mixin</name>
 	<packaging>jar</packaging>
 	<properties>

Modified: cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java?rev=1042377&r1=1042376&r2=1042377&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java
(original)
+++ cayenne/sandbox/cayenne-mixin/trunk/src/main/java/org/apache/cayenne/mixin/ref/ReferenceableHandler.java
Sun Dec  5 15:58:43 2010
@@ -53,13 +53,7 @@ public class ReferenceableHandler {
     public Object getReferenceable(ObjectContext context, String uuid) {
 
         String entityName = UuidCoder.getEntityName(uuid);
-        UuidCoder coder = coders.get(entityName);
-        if (coder == null) {
-            throw new IllegalArgumentException("Entity "
-                    + entityName
-                    + " is not a known referenceable");
-        }
-
+        UuidCoder coder = getCoder(entityName);
         ObjectId oid = coder.toObjectId(uuid);
         return Cayenne.objectForPK(context, oid);
     }
@@ -99,21 +93,28 @@ public class ReferenceableHandler {
     @PostPersist(entityAnnotations = Referenceable.class)
     protected void initProperties(DataObject object) {
 
-        UuidCoder coder = coders.get(object.getObjectId().getEntityName());
+        UuidCoder coder = getCoder(object.getObjectId().getEntityName());
+        String uuid = coder.toUuid(object.getObjectId());
+        object.writePropertyDirectly(Referenceable.UUID_PROPERTY, uuid);
+    }
+
+    protected UuidCoder getCoder(String entityName) {
+        UuidCoder coder = coders.get(entityName);
         if (coder == null) {
 
-            ObjEntity entity = entityResolver.lookupObjEntity(object.getClass());
+            // TODO: check @Referenceable annotation?
+            ObjEntity entity = entityResolver.getObjEntity(entityName);
             if (entity == null) {
-                throw new IllegalArgumentException("Entity "
-                        + object.getObjectId().getEntityName()
-                        + " is not a known referenceable");
+                throw new IllegalArgumentException("Entity '"
+                        + entityName
+                        + "' is not a known referenceable");
             }
 
             coder = new UuidCoder(entity);
             coders.put(entity.getName(), coder);
         }
 
-        String uuid = coder.toUuid(object.getObjectId());
-        object.writePropertyDirectly(Referenceable.UUID_PROPERTY, uuid);
+        return coder;
+
     }
 }



Mime
View raw message