cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r398019 [2/2] - in /incubator/cayenne/trunk/cayenne-jpa/src: main/java/org/apache/cayenne/jpa/bridge/ main/java/org/apache/cayenne/jpa/conf/ main/java/org/apache/cayenne/jpa/map/ test/java/org/apache/cayenne/jpa/bridge/ test/java/org/apache...
Date Fri, 28 Apr 2006 21:27:36 GMT
Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAbstractEntity.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAbstractEntity.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAbstractEntity.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAbstractEntity.java
Fri Apr 28 14:27:32 2006
@@ -40,6 +40,23 @@
     protected Collection<JpaId> ids;
     protected Collection<JpaAttribute> attributes;
 
+    /**
+     * Returns a JpaAttribute for a given property name
+     */
+    public JpaAttribute attributeForName(String attributeName) {
+        if (attributeName == null) {
+            throw new IllegalArgumentException("Null attribute name");
+        }
+
+        for (JpaAttribute attribute : attributes) {
+            if (attributeName.equals(attribute.getName())) {
+                return attribute;
+            }
+        }
+
+        return null;
+    }
+    
     @TreeNodeChild
     public JpaEmbeddedId getEmbeddedId() {
         return embeddedId;

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaEntityMap.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaEntityMap.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaEntityMap.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaEntityMap.java
Fri Apr 28 14:27:32 2006
@@ -21,8 +21,8 @@
 import javax.persistence.CascadeType;
 import javax.persistence.FlushModeType;
 
+import org.apache.cayenne.jpa.conf.EntityMapLoaderContext;
 import org.apache.cayenne.util.TreeNodeChild;
-import org.objectstyle.cayenne.validation.ValidationResult;
 
 /**
  * An object that stores JPA mapping information. This is a root object in the hierarchy
@@ -50,10 +50,6 @@
     protected JpaEntityListeners defaultEntityListeners;
     protected Collection<CascadeType> cascades;
 
-    public JpaEntityMap() {
-        this.access = AccessType.FIELD;
-    }
-
     /**
      * Merges all entities from another map, overriding existing values.
      * 
@@ -71,7 +67,7 @@
      * @return An object containing unresolvable conflicts or null if no conflicts
      *         occured.
      */
-    public ValidationResult mergeNoOverride(JpaEntityMap map) {
+    public void mergeNoOverride(JpaEntityMap map, EntityMapLoaderContext context) {
         // TODO: implement
         throw new UnsupportedOperationException("TODO");
     }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaTable.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaTable.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaTable.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaTable.java
Fri Apr 28 14:27:32 2006
@@ -34,9 +34,17 @@
     }
 
     public JpaTable(Table annotation) {
-        name = annotation.name();
-        catalog = annotation.catalog();
-        schema = annotation.schema();
+        if (!"".equals(annotation.name())) {
+            name = annotation.name();
+        }
+
+        if (!"".equals(annotation.catalog())) {
+            catalog = annotation.catalog();
+        }
+
+        if (!"".equals(annotation.schema())) {
+            schema = annotation.schema();
+        }
 
         // resolve collection
         getUniqueConstraints();

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java
Fri Apr 28 14:27:32 2006
@@ -18,6 +18,8 @@
 import junit.framework.TestCase;
 
 import org.apache.cayenne.jpa.conf.EntityMapAnnotationLoader;
+import org.apache.cayenne.jpa.conf.EntityMapDefaultsLoader;
+import org.apache.cayenne.jpa.conf.EntityMapLoaderContext;
 import org.apache.cayenne.jpa.entity.cayenne.MockCayenneEntity1;
 import org.apache.cayenne.jpa.entity.cayenne.MockCayenneEntity2;
 import org.apache.cayenne.jpa.entity.cayenne.MockCayenneEntityMap1;
@@ -48,15 +50,20 @@
      */
     public void testLoadClassMapping() throws Exception {
         JpaEntityMap map = new JpaEntityMap();
-        ValidationResult conflicts = new ValidationResult();
-        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(conflicts);
+        EntityMapLoaderContext context = new EntityMapLoaderContext();
+        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
 
         loader.loadClassMapping(map, MockCayenneEntity1.class);
         loader.loadClassMapping(map, MockCayenneEntity2.class);
 
         loader.loadClassMapping(map, MockCayenneEntityMap1.class);
 
-        assertFalse("Found conflicts: " + conflicts, conflicts.hasFailures());
+        // apply defaults before conversion
+        new EntityMapDefaultsLoader(context).loadDefaults(map);
+
+        assertFalse("Found conflicts: " + context.getConflicts(), context
+                .getConflicts()
+                .hasFailures());
 
         ValidationResult dataMapConflicts = new ValidationResult();
         DataMap dataMap = new DataMapConverter(dataMapConflicts).toDataMap("n1", map);

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapMappingAssertion.java
Fri Apr 28 14:27:32 2006
@@ -23,6 +23,7 @@
 import org.apache.cayenne.jpa.entity.cayenne.MockCayenneEntity2;
 import org.objectstyle.cayenne.map.DataMap;
 import org.objectstyle.cayenne.map.DbEntity;
+import org.objectstyle.cayenne.map.ObjAttribute;
 import org.objectstyle.cayenne.map.ObjEntity;
 
 public class DataMapMappingAssertion extends Assert {
@@ -46,10 +47,10 @@
         assertEquals("MockCayenneEntity1", entity1.getName());
         assertEquals(MockCayenneEntity1.class.getName(), entity1.getClassName());
 
-        assertTable(entity1.getDbEntity());
-
-        assertEquals(3, entity1.getAttributeMap().size());
+        assertObjAttributes(entity1);
         assertEquals(4, entity1.getRelationshipMap().size());
+
+        assertDbEntity(entity1.getDbEntity());
     }
 
     protected void assertEntity2(ObjEntity entity2) {
@@ -59,10 +60,32 @@
         assertEquals(MockCayenneEntity2.class.getName(), entity2.getClassName());
     }
 
-    protected void assertTable(DbEntity table) {
+    protected void assertDbEntity(DbEntity table) {
         assertNotNull(table);
         assertEquals("mock_persistent_1", table.getName());
         assertEquals("catalog1", table.getCatalog());
         assertEquals("schema1", table.getSchema());
+    }
+
+    protected void assertObjAttributes(ObjEntity entity1) {
+        assertEquals(3, entity1.getAttributeMap().size());
+
+        ObjAttribute a1 = (ObjAttribute) entity1.getAttribute("attribute1");
+        assertNotNull(a1);
+        assertEquals("attribute1", a1.getName());
+        assertEquals("attribute1", a1.getDbAttributeName());
+        assertEquals(String.class.getName(), a1.getType());
+
+        ObjAttribute a2 = (ObjAttribute) entity1.getAttribute("attribute2");
+        assertNotNull(a2);
+        assertEquals("attribute2", a2.getName());
+        assertEquals("attribute2", a2.getDbAttributeName());
+        assertEquals(Integer.TYPE.getName(), a2.getType());
+
+        ObjAttribute a3 = (ObjAttribute) entity1.getAttribute("attribute9");
+        assertNotNull(a3);
+        assertEquals("attribute9", a3.getName());
+        assertEquals("column9", a3.getDbAttributeName());
+        assertEquals(Integer.TYPE.getName(), a3.getType());
     }
 }

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapAnnotationLoaderTest.java
Fri Apr 28 14:27:32 2006
@@ -16,10 +16,7 @@
 package org.apache.cayenne.jpa.conf;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
 import java.util.Arrays;
-import java.util.Collection;
-import java.util.regex.Matcher;
 
 import javax.persistence.Entity;
 import javax.persistence.IdClass;
@@ -43,54 +40,13 @@
 import org.apache.cayenne.jpa.map.JpaAttributeOverride;
 import org.apache.cayenne.jpa.map.JpaEntity;
 import org.apache.cayenne.jpa.map.JpaEntityMap;
-import org.objectstyle.cayenne.validation.ValidationResult;
 
 public class EntityMapAnnotationLoaderTest extends TestCase {
 
-    public void testGetterPattern() {
-        Matcher m1 = EntityMapAnnotationLoader.GETTER_PATTERN.matcher("xxx");
-        assertFalse(m1.matches());
-
-        Matcher m2 = EntityMapAnnotationLoader.GETTER_PATTERN.matcher("isA");
-        assertTrue(m2.matches());
-        assertEquals("A", m2.group(2));
-
-        Matcher m3 = EntityMapAnnotationLoader.GETTER_PATTERN.matcher("getThis");
-        assertTrue(m3.matches());
-        assertEquals("This", m3.group(2));
-    }
-
-    public void testSetterPattern() {
-        Matcher m1 = EntityMapAnnotationLoader.SETTER_PATTERN.matcher("xxx");
-        assertFalse(m1.matches());
-
-        Matcher m2 = EntityMapAnnotationLoader.SETTER_PATTERN.matcher("set");
-        assertFalse(m2.matches());
-
-        Matcher m3 = EntityMapAnnotationLoader.SETTER_PATTERN.matcher("setThis");
-        assertTrue(m3.matches());
-        assertEquals("This", m3.group(1));
-    }
-
-    public void testGetPropertyGetters() throws Exception {
-        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(
-                new ValidationResult());
-
-        Collection<Method> validGetters = loader
-                .getPropertyGetters(MockPropertyRegressionBean.class);
-        assertEquals(2, validGetters.size());
-
-        assertTrue(validGetters.contains(MockPropertyRegressionBean.class
-                .getDeclaredMethod("getP2", new Class[] {})));
-
-        assertTrue(validGetters.contains(MockPropertyRegressionBean.class
-                .getDeclaredMethod("getP3", new Class[] {})));
-    }
-
     public void testSortAnnotations() throws Exception {
 
         EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(
-                new ValidationResult());
+                new EntityMapLoaderContext());
 
         Annotation[] a1 = new Annotation[3];
         a1[0] = MockAnnotatedBean1.class.getAnnotation(NamedQuery.class);
@@ -110,8 +66,8 @@
      */
     public void testAttributeOverride() {
         JpaEntityMap map = new JpaEntityMap();
-        ValidationResult conflicts = new ValidationResult();
-        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(conflicts);
+        EntityMapLoaderContext context = new EntityMapLoaderContext();
+        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
         loader.loadClassMapping(map, MockAnnotatedBean2.class);
 
         assertEquals(1, map.getEntities().size());
@@ -140,8 +96,8 @@
      */
     public void testLoadClassMapping() throws Exception {
         JpaEntityMap map = new JpaEntityMap();
-        ValidationResult conflicts = new ValidationResult();
-        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(conflicts);
+        EntityMapLoaderContext context = new EntityMapLoaderContext();
+        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
 
         loader.loadClassMapping(map, MockEntity1.class);
         loader.loadClassMapping(map, MockEntity2.class);
@@ -151,15 +107,17 @@
 
         loader.loadClassMapping(map, MockEmbed1.class);
         loader.loadClassMapping(map, MockEmbed2.class);
-        
+
         loader.loadClassMapping(map, MockMappedSuperclass1.class);
         loader.loadClassMapping(map, MockMappedSuperclass2.class);
         loader.loadClassMapping(map, MockMappedSuperclass3.class);
-        
+
         loader.loadClassMapping(map, MockEntityMap1.class);
         loader.loadClassMapping(map, MockEntityMap2.class);
 
-        assertFalse("Found conflicts: " + conflicts, conflicts.hasFailures());
+        assertFalse("Found conflicts: " + context.getConflicts(), context
+                .getConflicts()
+                .hasFailures());
 
         new AnnotationMappingAssertion().testEntityMap(map);
     }

Added: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/JpaClassDescriptorTest.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/JpaClassDescriptorTest.java?rev=398019&view=auto
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/JpaClassDescriptorTest.java
(added)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/JpaClassDescriptorTest.java
Fri Apr 28 14:27:32 2006
@@ -0,0 +1,65 @@
+/*
+ *  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.conf;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.regex.Matcher;
+
+import junit.framework.TestCase;
+
+public class JpaClassDescriptorTest extends TestCase {
+
+    public void testGetterPattern() {
+        Matcher m1 = JpaClassDescriptor.GETTER_PATTERN.matcher("xxx");
+        assertFalse(m1.matches());
+
+        Matcher m2 = JpaClassDescriptor.GETTER_PATTERN.matcher("isA");
+        assertTrue(m2.matches());
+        assertEquals("A", m2.group(2));
+
+        Matcher m3 = JpaClassDescriptor.GETTER_PATTERN.matcher("getThis");
+        assertTrue(m3.matches());
+        assertEquals("This", m3.group(2));
+    }
+
+    public void testSetterPattern() {
+        Matcher m1 = JpaClassDescriptor.SETTER_PATTERN.matcher("xxx");
+        assertFalse(m1.matches());
+
+        Matcher m2 = JpaClassDescriptor.SETTER_PATTERN.matcher("set");
+        assertFalse(m2.matches());
+
+        Matcher m3 = JpaClassDescriptor.SETTER_PATTERN.matcher("setThis");
+        assertTrue(m3.matches());
+        assertEquals("This", m3.group(1));
+    }
+
+    public void testGetPropertyGetters() throws Exception {
+
+        JpaClassDescriptor descriptor = new JpaClassDescriptor(
+                MockPropertyRegressionBean.class);
+        Collection<Method> validGetters = descriptor.getPersistentPropertyCandidates();
+        assertEquals(2, validGetters.size());
+
+        assertTrue(validGetters.contains(MockPropertyRegressionBean.class
+                .getDeclaredMethod("getP2", new Class[] {})));
+
+        assertTrue(validGetters.contains(MockPropertyRegressionBean.class
+                .getDeclaredMethod("getP3", new Class[] {})));
+    }
+
+}

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity1.java
Fri Apr 28 14:27:32 2006
@@ -15,11 +15,11 @@
  */
 package org.apache.cayenne.jpa.entity.cayenne;
 
-import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
+import javax.persistence.IdClass;
 import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
@@ -34,6 +34,7 @@
 import org.apache.cayenne.jpa.entity.MockTargetEntity1;
 import org.apache.cayenne.jpa.entity.MockTargetEntity2;
 import org.objectstyle.cayenne.CayenneDataObject;
+import org.objectstyle.cayenne.ObjectId;
 
 @Entity
 @Table(name = "mock_persistent_1", catalog = "catalog1", schema = "schema1")
@@ -43,9 +44,9 @@
                 @QueryHint(name = "hint2", value = "value2")
         }), @NamedQuery(name = "query2", query = "select y")
 })
+@IdClass(ObjectId.class)
 public class MockCayenneEntity1 extends CayenneDataObject {
 
-    @Basic
     protected String attribute1;
 
     @Version

Modified: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity2.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity2.java?rev=398019&r1=398018&r2=398019&view=diff
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity2.java
(original)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/cayenne/MockCayenneEntity2.java
Fri Apr 28 14:27:32 2006
@@ -16,10 +16,13 @@
 package org.apache.cayenne.jpa.entity.cayenne;
 
 import javax.persistence.Entity;
+import javax.persistence.IdClass;
 
 import org.objectstyle.cayenne.CayenneDataObject;
+import org.objectstyle.cayenne.ObjectId;
 
 @Entity
+@IdClass(ObjectId.class)
 public class MockCayenneEntity2 extends CayenneDataObject {
 
-}
+}
\ No newline at end of file

Added: incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/JpaTableTest.java
URL: http://svn.apache.org/viewcvs/incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/JpaTableTest.java?rev=398019&view=auto
==============================================================================
--- incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/JpaTableTest.java
(added)
+++ incubator/cayenne/trunk/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/JpaTableTest.java
Fri Apr 28 14:27:32 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.map;
+
+import javax.persistence.Table;
+
+import junit.framework.TestCase;
+
+@Table
+public class JpaTableTest extends TestCase {
+
+    public void testEmptyAnnotationConstructor() throws Exception {
+        Table annotation = getClass().getAnnotation(Table.class);
+
+        JpaTable t = new JpaTable(annotation);
+        assertNull(t.getName());
+        assertNull(t.getCatalog());
+        assertNull(t.getSchema());
+    }
+}



Mime
View raw message