cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r578794 - in /cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect: JpaClassDescriptorFactory.java JpaMapProperty.java
Date Mon, 24 Sep 2007 12:54:54 GMT
Author: aadamchik
Date: Mon Sep 24 05:54:53 2007
New Revision: 578794

URL: http://svn.apache.org/viewvc?rev=578794&view=rev
Log:
CAY-848 Support for mapping to-many as Maps and Sets and Collections
changed map key reading algorithm to support default objectid keys

Modified:
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaClassDescriptorFactory.java
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaMapProperty.java

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaClassDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaClassDescriptorFactory.java?rev=578794&r1=578793&r2=578794&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaClassDescriptorFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaClassDescriptorFactory.java
Mon Sep 24 05:54:53 2007
@@ -70,11 +70,13 @@
                 descriptor.getObjectClass(),
                 relationship.getName(),
                 Map.class);
+        Accessor mapKeyAccessor = createMapKeyAccessor(relationship, targetDescriptor);
         Property property = new JpaMapProperty(
                 descriptor,
                 targetDescriptor,
                 accessor,
-                reverseName);
+                reverseName,
+                mapKeyAccessor);
 
         descriptor.addDeclaredProperty(property);
     }

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaMapProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaMapProperty.java?rev=578794&r1=578793&r2=578794&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaMapProperty.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/reflect/JpaMapProperty.java
Mon Sep 24 05:54:53 2007
@@ -18,12 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.jpa.reflect;
 
-import java.util.Iterator;
-import java.util.Map;
-
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.ValueHolder;
-import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.reflect.Accessor;
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.PropertyException;
@@ -31,54 +27,21 @@
 import org.apache.cayenne.util.PersistentObjectMap;
 
 class JpaMapProperty extends JpaToManyProperty implements ToManyMapProperty {
-    
-    private Expression mapKey;
+
+    private Accessor mapKeyAccessor;
 
     JpaMapProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
-            Accessor accessor, String reverseName) {
+            Accessor accessor, String reverseName, Accessor mapKeyAccessor) {
         super(owner, targetDescriptor, accessor, reverseName);
-        this.mapKey = getRelationship().getMapKeyExpression();
+        this.mapKeyAccessor = mapKeyAccessor;
     }
 
     @Override
     protected ValueHolder createValueHolder(Persistent relationshipOwner) {
-        return new PersistentObjectMap(relationshipOwner, getName(), getRelationship()
-                .getMapKeyExpression());
+        return new PersistentObjectMap(relationshipOwner, getName(), mapKeyAccessor);
     }
 
-    public void remapTarget(Object source, Object target) throws PropertyException {
-        // TODO: andrus, 9/24/2007 - this is an clone of the remapTarget method in
-        // DataObjectToManyMapProperty that is a part of a different inheritance
-        // hierarchy... need to reconcile that somehow...
-
-        if (target == null) {
-            throw new NullPointerException("Null target");
-        }
-
-        Map map = (Map) readProperty(source);
-
-        Object newKey = mapKey.evaluate(target);
-        Object currentValue = map.get(newKey);
-
-        if (currentValue == target) {
-            // nothing to do
-            return;
-        }
-        // else - do not check for conflicts here (i.e. another object mapped for the same
-        // key), as we have no control of the order in which this method is called, so
-        // another object may be remapped later by the caller
-
-        // must do a slow map scan to ensure the object is not mapped under a different
-        // key...
-        Iterator it = map.entrySet().iterator();
-        while (it.hasNext()) {
-            Map.Entry e = (Map.Entry) it.next();
-            if (e.getValue() == target) {
-                it.remove();
-                break;
-            }
-        }
-
-        map.put(newKey, target);
+    public Object getMapKey(Object target) throws PropertyException {
+        return mapKeyAccessor.getValue(target);
     }
 }



Mime
View raw message