cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1308074 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/access/ java/org/apache/cayenne/testdo/testmap/auto/ resources/
Date Sun, 01 Apr 2012 11:07:05 GMT
Author: aadamchik
Date: Sun Apr  1 11:07:05 2012
New Revision: 1308074

URL: http://svn.apache.org/viewvc?rev=1308074&view=rev
Log:
CAY-1681 Third prefetch kind - DISJOINT_BY_ID

dding more regression to the unit tests

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Bag.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Box.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java?rev=1308074&r1=1308073&r2=1308074&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextDisjointByIdPrefetchTest.java
Sun Apr  1 11:07:05 2012
@@ -1,5 +1,6 @@
 package org.apache.cayenne.access;
 
+import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.ValueHolder;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.query.PrefetchTreeNode;
@@ -15,12 +16,14 @@ import org.apache.cayenne.unit.di.UnitTe
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import static org.apache.cayenne.exp.ExpressionFactory.matchExp;
 
 @UseServerRuntime(ServerCase.TESTMAP_PROJECT)
 public class DataContextDisjointByIdPrefetchTest extends ServerCase {
+
     @Inject
     protected DataContext context;
 
@@ -47,10 +50,10 @@ public class DataContextDisjointByIdPref
         dbHelper.deleteAll("BAG");
 
         tBag = new TableHelper(dbHelper, "BAG");
-        tBag.setColumns("ID");
+        tBag.setColumns("ID", "NAME");
 
         tBox = new TableHelper(dbHelper, "BOX");
-        tBox.setColumns("ID", "BAG_ID");
+        tBox.setColumns("ID", "BAG_ID", "NAME");
 
         tBoxInfo = new TableHelper(dbHelper, "BOX_INFO");
         tBoxInfo.setColumns("ID", "BOX_ID", "COLOR");
@@ -66,35 +69,35 @@ public class DataContextDisjointByIdPref
     }
 
     private void createBagWithTwoBoxesDataSet() throws Exception {
-        tBag.insert(1);
-        tBox.insert(1, 1);
-        tBox.insert(2, 1);
+        tBag.insert(1, "X");
+        tBox.insert(1, 1, "Y");
+        tBox.insert(2, 1, "Z");
     }
 
     private void createThreeBagsWithPlentyOfBoxesDataSet() throws Exception {
-        tBag.insert(1);
-        tBag.insert(2);
-        tBag.insert(3);
-
-        tBox.insert(1, 1);
-        tBox.insert(2, 1);
-        tBox.insert(3, 1);
-        tBox.insert(4, 1);
-        tBox.insert(5, 1);
-
-        tBox.insert(6, 2);
-        tBox.insert(7, 2);
-
-        tBox.insert(8, 3);
-        tBox.insert(9, 3);
-        tBox.insert(10, 3);
+        tBag.insert(1, null);
+        tBag.insert(2, null);
+        tBag.insert(3, null);
+
+        tBox.insert(1, 1, null);
+        tBox.insert(2, 1, null);
+        tBox.insert(3, 1, null);
+        tBox.insert(4, 1, null);
+        tBox.insert(5, 1, null);
+
+        tBox.insert(6, 2, null);
+        tBox.insert(7, 2, null);
+
+        tBox.insert(8, 3, null);
+        tBox.insert(9, 3, null);
+        tBox.insert(10, 3, null);
     }
 
     private void createBagWithTwoBoxesAndPlentyOfBallsDataSet() throws Exception {
-        tBag.insert(1);
-        tBox.insert(1, 1);
+        tBag.insert(1, null);
+        tBox.insert(1, 1, null);
         tBoxInfo.insert(1, 1, "red");
-        tBox.insert(2, 1);
+        tBox.insert(2, 1, null);
         tBoxInfo.insert(2, 2, "green");
 
         tThing.insert(1, 10, 10);
@@ -122,7 +125,7 @@ public class DataContextDisjointByIdPref
         tBall.insert(6, 2, 30, 40);
     }
 
-    public void testBasic() throws Exception {
+    public void testOneToMany() throws Exception {
         createBagWithTwoBoxesDataSet();
 
         SelectQuery query = new SelectQuery(Bag.class);
@@ -135,9 +138,42 @@ public class DataContextDisjointByIdPref
             public void execute() {
                 assertFalse(result.isEmpty());
                 Bag b1 = result.get(0);
-                List<?> toMany = (List<?>) b1.readPropertyDirectly(Bag.BOXES_PROPERTY);
+                List<Box> toMany = (List<Box>) b1
+                        .readPropertyDirectly(Bag.BOXES_PROPERTY);
                 assertNotNull(toMany);
                 assertFalse(((ValueHolder) toMany).isFault());
+                assertEquals(2, toMany.size());
+
+                List<String> names = new ArrayList<String>();
+                for (Box b : toMany) {
+                    assertEquals(PersistenceState.COMMITTED, b.getPersistenceState());
+                    names.add(b.getName());
+                }
+                
+                assertTrue(names.contains("Y"));
+                assertTrue(names.contains("Z"));
+            }
+        });
+    }
+
+    public void testManyToOne() throws Exception {
+        createBagWithTwoBoxesDataSet();
+
+        SelectQuery query = new SelectQuery(Box.class);
+        query.addPrefetch(Box.BAG_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+
+        final List<Box> result = context.performQuery(query);
+        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
+            public void execute() {
+                assertFalse(result.isEmpty());
+                Box b1 = result.get(0);
+                assertNotNull(b1.getBag());
+                assertEquals(PersistenceState.COMMITTED, b1
+                        .getBag()
+                        .getPersistenceState());
+                assertEquals("X", b1.getBag().getName());
             }
         });
     }
@@ -158,14 +194,15 @@ public class DataContextDisjointByIdPref
         assertEquals(9, context.getObjectStore().getDataRowCache().size());
     }
 
-    public void testToOneRelationship() throws Exception {
+    public void testOneToOneRelationship() throws Exception {
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Box.class);
-        query.addPrefetch(Box.BOX_INFO_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addPrefetch(Box.BOX_INFO_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
         final List<Box> result = context.performQuery(query);
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
             public void execute() {
                 assertFalse(result.isEmpty());
                 Box b1 = result.get(0);
@@ -180,11 +217,12 @@ public class DataContextDisjointByIdPref
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Bag.class);
-        query.addPrefetch(Bag.BALLS_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addPrefetch(Bag.BALLS_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
         final List<Bag> result = context.performQuery(query);
 
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
             public void execute() {
                 assertFalse(result.isEmpty());
                 Bag b1 = result.get(0);
@@ -200,12 +238,12 @@ public class DataContextDisjointByIdPref
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Ball.class);
-        query.orQualifier(
-                matchExp(Ball.THING_VOLUME_PROPERTY, 40).andExp(matchExp(Ball.THING_WEIGHT_PROPERTY,
30)));
-        query.orQualifier(
-                matchExp(Ball.THING_VOLUME_PROPERTY, 20).andExp(matchExp(Ball.THING_WEIGHT_PROPERTY,
10)));
-        query.addPrefetch(Ball.THING_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.orQualifier(matchExp(Ball.THING_VOLUME_PROPERTY, 40).andExp(
+                matchExp(Ball.THING_WEIGHT_PROPERTY, 30)));
+        query.orQualifier(matchExp(Ball.THING_VOLUME_PROPERTY, 20).andExp(
+                matchExp(Ball.THING_WEIGHT_PROPERTY, 10)));
+        query.addPrefetch(Ball.THING_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
         context.performQuery(query);
 
         assertEquals(4, context.getObjectStore().getDataRowCache().size());
@@ -215,11 +253,12 @@ public class DataContextDisjointByIdPref
         createBagWithTwoBoxesAndPlentyOfBallsDataSet();
 
         SelectQuery query = new SelectQuery(Box.class);
-        query.addPrefetch(Box.THINGS_PROPERTY)
-                .setSemantics(PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
+        query.addPrefetch(Box.THINGS_PROPERTY).setSemantics(
+                PrefetchTreeNode.DISJOINT_BY_ID_PREFETCH_SEMANTICS);
         final List<Box> result = context.performQuery(query);
 
         queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
+
             public void execute() {
                 assertFalse(result.isEmpty());
                 Box b1 = result.get(0);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Bag.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Bag.java?rev=1308074&r1=1308073&r2=1308074&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Bag.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Bag.java
Sun Apr  1 11:07:05 2012
@@ -14,26 +14,34 @@ import org.apache.cayenne.testdo.testmap
  */
 public abstract class _Bag extends CayenneDataObject {
 
+    public static final String NAME_PROPERTY = "name";
     public static final String BALLS_PROPERTY = "balls";
     public static final String BOXES_PROPERTY = "boxes";
 
     public static final String ID_PK_COLUMN = "ID";
 
+    public void setName(String name) {
+        writeProperty(NAME_PROPERTY, name);
+    }
+    public String getName() {
+        return (String)readProperty(NAME_PROPERTY);
+    }
+
     @SuppressWarnings("unchecked")
     public List<Ball> getBalls() {
-        return (List<Ball>)readProperty("balls");
+        return (List<Ball>)readProperty(BALLS_PROPERTY);
     }
 
 
     public void addToBoxes(Box obj) {
-        addToManyTarget("boxes", obj, true);
+        addToManyTarget(BOXES_PROPERTY, obj, true);
     }
     public void removeFromBoxes(Box obj) {
-        removeToManyTarget("boxes", obj, true);
+        removeToManyTarget(BOXES_PROPERTY, obj, true);
     }
     @SuppressWarnings("unchecked")
     public List<Box> getBoxes() {
-        return (List<Box>)readProperty("boxes");
+        return (List<Box>)readProperty(BOXES_PROPERTY);
     }
 
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Box.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Box.java?rev=1308074&r1=1308073&r2=1308074&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Box.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/testmap/auto/_Box.java
Sun Apr  1 11:07:05 2012
@@ -16,6 +16,7 @@ import org.apache.cayenne.testdo.testmap
  */
 public abstract class _Box extends CayenneDataObject {
 
+    public static final String NAME_PROPERTY = "name";
     public static final String BAG_PROPERTY = "bag";
     public static final String BALLS_PROPERTY = "balls";
     public static final String BOX_INFO_PROPERTY = "boxInfo";
@@ -23,39 +24,46 @@ public abstract class _Box extends Cayen
 
     public static final String ID_PK_COLUMN = "ID";
 
+    public void setName(String name) {
+        writeProperty(NAME_PROPERTY, name);
+    }
+    public String getName() {
+        return (String)readProperty(NAME_PROPERTY);
+    }
+
     public void setBag(Bag bag) {
-        setToOneTarget("bag", bag, true);
+        setToOneTarget(BAG_PROPERTY, bag, true);
     }
 
     public Bag getBag() {
-        return (Bag)readProperty("bag");
+        return (Bag)readProperty(BAG_PROPERTY);
     }
 
 
     public void addToBalls(Ball obj) {
-        addToManyTarget("balls", obj, true);
+        addToManyTarget(BALLS_PROPERTY, obj, true);
     }
     public void removeFromBalls(Ball obj) {
-        removeToManyTarget("balls", obj, true);
+        removeToManyTarget(BALLS_PROPERTY, obj, true);
     }
     @SuppressWarnings("unchecked")
     public List<Ball> getBalls() {
-        return (List<Ball>)readProperty("balls");
+        return (List<Ball>)readProperty(BALLS_PROPERTY);
     }
 
 
     public void setBoxInfo(BoxInfo boxInfo) {
-        setToOneTarget("boxInfo", boxInfo, true);
+        setToOneTarget(BOX_INFO_PROPERTY, boxInfo, true);
     }
 
     public BoxInfo getBoxInfo() {
-        return (BoxInfo)readProperty("boxInfo");
+        return (BoxInfo)readProperty(BOX_INFO_PROPERTY);
     }
 
 
     @SuppressWarnings("unchecked")
     public List<Thing> getThings() {
-        return (List<Thing>)readProperty("things");
+        return (List<Thing>)readProperty(THINGS_PROPERTY);
     }
 
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml?rev=1308074&r1=1308073&r2=1308074&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml
Sun Apr  1 11:07:05 2012
@@ -53,6 +53,7 @@
 	</db-entity>
 	<db-entity name="BAG">
 		<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isGenerated="true" isMandatory="true"/>
+		<db-attribute name="NAME" type="VARCHAR" length="200"/>
 	</db-entity>
 	<db-entity name="BALL">
 		<db-attribute name="BOX_ID" type="BIGINT" isMandatory="true"/>
@@ -92,6 +93,7 @@
 	<db-entity name="BOX">
 		<db-attribute name="BAG_ID" type="BIGINT" isMandatory="true"/>
 		<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="NAME" type="VARCHAR"/>
 	</db-entity>
 	<db-entity name="BOX_INFO">
 		<db-attribute name="BOX_ID" type="BIGINT" isMandatory="true"/>
@@ -348,6 +350,7 @@
 	<obj-entity name="ArtistExhibit" className="org.apache.cayenne.testdo.testmap.ArtistExhibit"
dbEntityName="ARTIST_EXHIBIT">
 	</obj-entity>
 	<obj-entity name="Bag" className="org.apache.cayenne.testdo.testmap.Bag" clientClassName="test.client.Bag"
dbEntityName="BAG" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 	</obj-entity>
 	<obj-entity name="Ball" className="org.apache.cayenne.testdo.testmap.Ball" clientClassName="test.client.Ball"
dbEntityName="BALL" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject">
 		<obj-attribute name="thingVolume" type="java.lang.Integer" db-attribute-path="THING_VOLUME"/>
@@ -378,6 +381,7 @@
 		<obj-attribute name="booleanColumn" type="java.lang.Boolean" db-attribute-path="BOOLEAN_COLUMN"/>
 	</obj-entity>
 	<obj-entity name="Box" className="org.apache.cayenne.testdo.testmap.Box" clientClassName="test.client.Box"
dbEntityName="BOX" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject">
+		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 	</obj-entity>
 	<obj-entity name="BoxInfo" className="org.apache.cayenne.testdo.testmap.BoxInfo" clientClassName="test.client.BoxInfo"
dbEntityName="BOX_INFO" superClassName="org.apache.cayenne.CayenneDataObject" clientSuperClassName="org.apache.cayenne.PersistentObject">
 		<obj-attribute name="color" type="java.lang.String" db-attribute-path="COLOR"/>



Mime
View raw message