cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r399102 - in /incubator/cayenne/jpa/trunk/cayenne-jpa/src: main/java/org/apache/cayenne/jpa/bridge/ main/java/org/apache/cayenne/jpa/cspi/ main/java/org/apache/cayenne/jpa/enhancer/ main/java/org/apache/cayenne/jpa/map/ main/java/org/object...
Date Wed, 03 May 2006 00:44:55 GMT
Author: aadamchik
Date: Tue May  2 17:44:54 2006
New Revision: 399102

URL: http://svn.apache.org/viewcvs?rev=399102&view=rev
Log:
implementing enhanced DataObject delegate methods

Added:
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaClassDescriptorFactory.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionFieldAccessor.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionProperty.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaEntityDescriptor.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/objectstyle/
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/objectstyle/cayenne/
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/objectstyle/cayenne/map/
Modified:
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/enhancer/DataObjectDelegate.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToMany.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToOne.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToMany.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToOne.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaRelationship.java
    incubator/cayenne/jpa/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
Tue May  2 17:44:54 2006
@@ -365,6 +365,7 @@
             DbRelationship dbRelationship = new DbRelationship(cayenneRelationship
                     .getName());
             dbRelationship.setTargetEntity(cayenneTargetDbEntity);
+            dbRelationship.setToMany(relationship.isToMany());
             cayenneSrcDbEntity.addRelationship(dbRelationship);
             cayenneRelationship.addDbRelationship(dbRelationship);
 

Added: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaClassDescriptorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaClassDescriptorFactory.java?rev=399102&view=auto
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaClassDescriptorFactory.java
(added)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaClassDescriptorFactory.java
Tue May  2 17:44:54 2006
@@ -0,0 +1,46 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.cayenne.jpa.cspi;
+
+import org.objectstyle.cayenne.map.EntityDescriptor;
+import org.objectstyle.cayenne.map.EntityDescriptorFactory;
+import org.objectstyle.cayenne.map.EntityResolver;
+import org.objectstyle.cayenne.map.ObjEntity;
+import org.objectstyle.cayenne.property.ClassDescriptor;
+
+public class CjpaClassDescriptorFactory extends EntityDescriptorFactory {
+
+    public CjpaClassDescriptorFactory(EntityResolver resolver) {
+        super(resolver);
+    }
+
+    @Override
+    protected EntityDescriptor createDescriptor(String entityName) {
+        ObjEntity entity = resolver.getObjEntity(entityName);
+        if (entity == null) {
+            return null;
+        }
+
+        String superEntityName = entity.getSuperEntityName();
+
+        ClassDescriptor superDescriptor = (superEntityName != null) ? resolver
+                .getClassDescriptor(superEntityName) : null;
+
+        // return uncompiled
+        return new CjpaEntityDescriptor(entity, superDescriptor);
+    }
+
+}

Added: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionFieldAccessor.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionFieldAccessor.java?rev=399102&view=auto
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionFieldAccessor.java
(added)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionFieldAccessor.java
Tue May  2 17:44:54 2006
@@ -0,0 +1,48 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.cayenne.jpa.cspi;
+
+import org.objectstyle.cayenne.Fault;
+import org.objectstyle.cayenne.Persistent;
+import org.objectstyle.cayenne.property.FieldAccessor;
+import org.objectstyle.cayenne.property.PropertyAccessException;
+
+class CjpaCollectionFieldAccessor extends FieldAccessor {
+
+    public CjpaCollectionFieldAccessor(Class objectClass, String propertyName,
+            Class propertyType) {
+        super(objectClass, propertyName, propertyType);
+
+        if (!Persistent.class.isAssignableFrom(objectClass)) {
+            throw new IllegalArgumentException("Only supports persistent classes. Got: "
+                    + objectClass);
+        }
+    }
+
+    /**
+     * Resolves a fault before setting the field.
+     */
+    @Override
+    public void writePropertyDirectly(Object object, Object oldValue, Object newValue)
+            throws PropertyAccessException {
+
+        if (newValue instanceof Fault) {
+            newValue = ((Fault) newValue).resolveFault((Persistent) object, getName());
+        }
+
+        super.writePropertyDirectly(object, oldValue, newValue);
+    }
+}

Added: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionProperty.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionProperty.java?rev=399102&view=auto
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionProperty.java
(added)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaCollectionProperty.java
Tue May  2 17:44:54 2006
@@ -0,0 +1,35 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.cayenne.jpa.cspi;
+
+import org.objectstyle.cayenne.property.ClassDescriptor;
+import org.objectstyle.cayenne.property.PropertyAccessException;
+import org.objectstyle.cayenne.property.PropertyAccessor;
+import org.objectstyle.cayenne.property.ToManyListProperty;
+
+class CjpaCollectionProperty extends ToManyListProperty {
+
+    public CjpaCollectionProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
+            PropertyAccessor accessor, String reverseName) {
+        super(owner, targetDescriptor, accessor, reverseName);
+    }
+
+    @Override
+    public void writePropertyDirectly(Object object, Object oldValue, Object newValue)
+            throws PropertyAccessException {
+        accessor.writePropertyDirectly(object, oldValue, newValue);
+    }
+}

Added: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaEntityDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaEntityDescriptor.java?rev=399102&view=auto
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaEntityDescriptor.java
(added)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaEntityDescriptor.java
Tue May  2 17:44:54 2006
@@ -0,0 +1,63 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.cayenne.jpa.cspi;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.objectstyle.cayenne.map.EntityDescriptor;
+import org.objectstyle.cayenne.map.EntityResolver;
+import org.objectstyle.cayenne.map.ObjEntity;
+import org.objectstyle.cayenne.map.ObjRelationship;
+import org.objectstyle.cayenne.property.ClassDescriptor;
+import org.objectstyle.cayenne.property.ListProperty;
+import org.objectstyle.cayenne.property.PropertyAccessor;
+
+class CjpaEntityDescriptor extends EntityDescriptor {
+
+    public CjpaEntityDescriptor(ObjEntity entity, ClassDescriptor superclassDescriptor) {
+        super(entity, superclassDescriptor);
+    }
+
+    @Override
+    protected void compileRelationships(EntityResolver resolver, Map allDescriptors) {
+        super.compileRelationships(resolver, allDescriptors);
+
+        // override all ListProperties with a customized version...
+
+        Iterator it = allDescriptors.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry entry = (Map.Entry) it.next();
+            if (entry.getValue() instanceof ListProperty) {
+
+                String name = entry.getKey().toString();
+                ListProperty overridenProperty = (ListProperty) entry.getValue();
+
+                PropertyAccessor accessor = new CjpaCollectionFieldAccessor(
+                        objectClass,
+                        name,
+                        null);
+
+                ObjRelationship relationship = (ObjRelationship) entity
+                        .getRelationship(name);
+
+                entry.setValue(new CjpaCollectionProperty(this, overridenProperty
+                        .getTargetDescriptor(), accessor, relationship
+                        .getReverseRelationshipName()));
+            }
+        }
+    }
+}

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaPersistenceProvider.java
Tue May  2 17:44:54 2006
@@ -97,7 +97,8 @@
      * {@link CjpaEntityManagerFactory} which is a DataDomain wrapper.
      */
     @Override
-    public EntityManagerFactory createContainerManagerFactory(PersistenceUnitInfo info) {
+    public synchronized EntityManagerFactory createContainerManagerFactory(
+            PersistenceUnitInfo info) {
         String name = info.getPersistenceUnitName();
         DataDomain domain = configuration.getDomain(name);
 
@@ -107,6 +108,8 @@
 
             // configure Cayenne domain
             domain = new DataDomain(name);
+            domain.getEntityResolver().setClassDescriptorFactory(
+                    new CjpaClassDescriptorFactory(domain.getEntityResolver()));
             configuration.addDomain(domain);
 
             EntityMapLoader loader = new EntityMapLoader(info);

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/enhancer/DataObjectDelegate.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/enhancer/DataObjectDelegate.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/enhancer/DataObjectDelegate.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/enhancer/DataObjectDelegate.java
Tue May  2 17:44:54 2006
@@ -23,6 +23,7 @@
 import org.objectstyle.cayenne.CayenneRuntimeException;
 import org.objectstyle.cayenne.DataObject;
 import org.objectstyle.cayenne.ObjectContext;
+import org.objectstyle.cayenne.ObjectId;
 import org.objectstyle.cayenne.access.DataContext;
 import org.objectstyle.cayenne.access.DataNode;
 import org.objectstyle.cayenne.access.types.ExtendedTypeMap;
@@ -34,17 +35,22 @@
 import org.objectstyle.cayenne.map.ObjEntity;
 import org.objectstyle.cayenne.map.ObjRelationship;
 import org.objectstyle.cayenne.property.ClassDescriptor;
+import org.objectstyle.cayenne.property.Property;
+import org.objectstyle.cayenne.property.PropertyUtils;
 import org.objectstyle.cayenne.validation.BeanValidationFailure;
 import org.objectstyle.cayenne.validation.ValidationFailure;
 import org.objectstyle.cayenne.validation.ValidationResult;
 
 /**
- * A static delegate for DataObject callbacks. It only implements DataContext retrieval
- * and validation methods. Remaining methods should not be called by Cayenne runtime
- * anymore.
+ * A static delegate for DataObject callbacks. To obtain class descriptors,
+ * DataObjectDelegate will use a DataObject context first, and then fall back to the
+ * DataContext bound to the current thread. If none of these methods work, and exception
+ * is thrown.
  * 
  * @author Andrus Adamchik
  */
+// TODO: andrus, 5/2/2006 - going ahead, the delegate should only impement the validation
+// methods, as property access by the framework should be done via ClassDescriptor.
 public final class DataObjectDelegate {
 
     public static DataContext getDataContext(DataObject object) {
@@ -62,7 +68,7 @@
     }
 
     public static Object readNestedProperty(DataObject object, String path) {
-        throw new UnsupportedOperationException("Not supported");
+        return PropertyUtils.getProperty(object, path);
     }
 
     /**
@@ -73,23 +79,26 @@
         throw new UnsupportedOperationException("Not supported");
     }
 
-    public static Object readProperty(DataObject object, String propertyName) {
-        throw new UnsupportedOperationException("Not supported");
+    public static Object readProperty(DataObject object, String property) {
+        return getPropertyDescriptor(object, property).readProperty(object);
     }
 
-    public static Object readPropertyDirectly(DataObject object, String propName) {
-        throw new UnsupportedOperationException("Not supported");
+    public static Object readPropertyDirectly(DataObject object, String property) {
+        return getPropertyDescriptor(object, property).readPropertyDirectly(object);
     }
 
-    public static void writeProperty(DataObject object, String propName, Object val) {
-        throw new UnsupportedOperationException("Not supported");
+    public static void writeProperty(DataObject object, String property, Object newValue)
{
+        Property p = getPropertyDescriptor(object, property);
+        p.writeProperty(object, p.readPropertyDirectly(object), newValue);
     }
 
     public static void writePropertyDirectly(
             DataObject object,
-            String propName,
-            Object val) {
-        throw new UnsupportedOperationException("Not supported");
+            String property,
+            Object newValue) {
+
+        Property p = getPropertyDescriptor(object, property);
+        p.writePropertyDirectly(object, p.readPropertyDirectly(object), newValue);
     }
 
     public static void removeToManyTarget(
@@ -130,6 +139,87 @@
         throw new UnsupportedOperationException("Not supported");
     }
 
+    public static void validateForInsert(
+            DataObject object,
+            ValidationResult validationResult) {
+        validateForSave(object, validationResult);
+    }
+
+    /**
+     * Returns a Cayenne ClassDescriptor for the enhanced DataObject class. To obtain
+     * class descriptors, uses a DataObject context first, and then falls back to the
+     * DataContext bound to the current thread. If none of these methods work, and
+     * exception is thrown.
+     */
+    protected static ClassDescriptor getDescriptor(DataObject enhancedObject)
+            throws IllegalStateException, IllegalArgumentException {
+        ObjectContext context = enhancedObject.getObjectContext();
+
+        if (context == null) {
+
+            try {
+                context = DataContext.getThreadDataContext();
+            }
+            catch (IllegalStateException e) {
+                // catch a generic exception trown by DataContext and rethrow a more
+                // informative one
+                throw new IllegalStateException("Object is not registered, and no "
+                        + "DataContext is bound to the current thread. Object: "
+                        + enhancedObject);
+            }
+        }
+
+        String entityName;
+
+        ObjectId oid = enhancedObject.getObjectId();
+        if (oid != null) {
+            entityName = oid.getEntityName();
+        }
+        else {
+            ObjEntity entity = context.getEntityResolver().lookupObjEntity(
+                    enhancedObject.getClass());
+            entityName = entity.getName();
+        }
+
+        ClassDescriptor descriptor = context.getEntityResolver().getClassDescriptor(
+                entityName);
+
+        if (descriptor == null) {
+            throw new IllegalArgumentException("No descriptor found for object "
+                    + enhancedObject);
+        }
+
+        return descriptor;
+    }
+
+    protected static Property getPropertyDescriptor(
+            DataObject enhancedObject,
+            String property) {
+
+        Property p = getDescriptor(enhancedObject).getProperty(property);
+
+        if (p == null) {
+            throw new IllegalArgumentException("No property descriptor '"
+                    + property
+                    + "' for object "
+                    + enhancedObject);
+        }
+
+        return p;
+    }
+
+    public static void validateForUpdate(
+            DataObject object,
+            ValidationResult validationResult) {
+        validateForSave(object, validationResult);
+    }
+
+    public static void validateForDelete(
+            DataObject object,
+            ValidationResult validationResult) {
+        // does nothing
+    }
+
     protected static void validateForSave(
             DataObject object,
             ValidationResult validationResult) {
@@ -270,21 +360,4 @@
         }
     }
 
-    public static void validateForInsert(
-            DataObject object,
-            ValidationResult validationResult) {
-        validateForSave(object, validationResult);
-    }
-
-    public static void validateForUpdate(
-            DataObject object,
-            ValidationResult validationResult) {
-        validateForSave(object, validationResult);
-    }
-
-    public static void validateForDelete(
-            DataObject object,
-            ValidationResult validationResult) {
-        // does nothing
-    }
 }

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToMany.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToMany.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToMany.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToMany.java
Tue May  2 17:44:54 2006
@@ -40,6 +40,11 @@
         mappedBy = annotation.mappedBy();
     }
 
+    @Override
+    public boolean isToMany() {
+        return true;
+    }
+
     @TreeNodeChild
     public JpaJoinTable getJoinTable() {
         return parent != null ? parent.getJoinTable() : null;

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToOne.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToOne.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToOne.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManyToOne.java
Tue May  2 17:44:54 2006
@@ -43,6 +43,11 @@
         fetch = annotation.fetch();
         optional = annotation.optional();
     }
+    
+    @Override
+    public boolean isToMany() {
+        return false;
+    }
 
     /**
      * Always returns null as Many-To-One is always a relationship owner.

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToMany.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToMany.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToMany.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToMany.java
Tue May  2 17:44:54 2006
@@ -41,6 +41,11 @@
         fetch = annotation.fetch();
         mappedBy = annotation.mappedBy();
     }
+    
+    @Override
+    public boolean isToMany() {
+        return true;
+    }
 
     @TreeNodeChild(type = JpaJoinColumn.class)
     public Collection<JpaJoinColumn> getJoinColumns() {

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToOne.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToOne.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToOne.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaOneToOne.java
Tue May  2 17:44:54 2006
@@ -44,6 +44,11 @@
         optional = annotation.optional();
         mappedBy = annotation.mappedBy();
     }
+    
+    @Override
+    public boolean isToMany() {
+        return false;
+    }
 
     public boolean isOptional() {
         return optional;

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaRelationship.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaRelationship.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaRelationship.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaRelationship.java
Tue May  2 17:44:54 2006
@@ -27,6 +27,8 @@
     protected String mappedBy;
     protected Collection<CascadeType> cascades;
 
+    public abstract boolean isToMany();
+
     public boolean isOwner() {
         return getMappedBy() == null;
     }

Modified: incubator/cayenne/jpa/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/jpa/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java?rev=399102&r1=399101&r2=399102&view=diff
==============================================================================
--- incubator/cayenne/jpa/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
(original)
+++ incubator/cayenne/jpa/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
Tue May  2 17:44:54 2006
@@ -113,6 +113,13 @@
     protected void assertObjRelationships(ObjEntity entity1) {
         assertEquals(4, entity1.getRelationshipMap().size());
 
+        ObjRelationship attribute4 = (ObjRelationship) entity1
+                .getRelationship("attribute4");
+        assertNotNull(attribute4);
+        assertTrue(attribute4.isToMany());
+        assertEquals("attribute4", attribute4.getDbRelationshipPath());
+        assertEquals("MockCayenneTargetEntity2", attribute4.getTargetEntityName());
+
         ObjRelationship attribute5 = (ObjRelationship) entity1
                 .getRelationship("attribute5");
         assertNotNull(attribute5);



Mime
View raw message