cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r718494 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java
Date Tue, 18 Nov 2008 06:31:55 GMT
Author: aadamchik
Date: Mon Nov 17 22:31:54 2008
New Revision: 718494

URL: http://svn.apache.org/viewvc?rev=718494&view=rev
Log:
CAY-795 Horizontal inheritance

select unit test that would require a UNION syntax... still failing

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java?rev=718494&r1=718493&r2=718494&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/HorizontalInheritanceTest.java
Mon Nov 17 22:31:54 2008
@@ -24,12 +24,13 @@
 import org.apache.cayenne.query.QueryChain;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.horizontalinherit.AbstractSuperEntity;
 import org.apache.cayenne.testdo.horizontalinherit.SubEntity1;
+import org.apache.cayenne.testdo.horizontalinherit.SubEntity2;
 import org.apache.cayenne.unit.InheritanceCase;
 
 /**
  * Tests for horizontal inheritance implementation.
- * 
  */
 public class HorizontalInheritanceTest extends InheritanceCase {
 
@@ -39,7 +40,7 @@
         deleteTestData();
     }
 
-    public void testSelectQueryOnConcreteLeafEntity() {
+    public void testDatabaseUnionCapabilities() {
 
         QueryChain inserts = new QueryChain();
         inserts
@@ -48,12 +49,43 @@
                         "INSERT INTO INHERITANCE_SUB_ENTITY1 "
                                 + "(ID, SUBENTITY_STRING_DB_ATTR, SUPER_INT_DB_ATTR, SUPER_STRING_DB_ATTR)
"
                                 + "VALUES (1, 'V11', 1, 'V21')"));
+
+        inserts
+                .addQuery(new SQLTemplate(
+                        SubEntity1.class,
+                        "INSERT INTO INHERITANCE_SUB_ENTITY2 "
+                                + "(ID, OVERRIDDEN_STRING_DB_ATTR, SUBENTITY_INT_DB_ATTR,
SUBENTITY_INT_DB_ATTR) "
+                                + "VALUES (1, 'VX11', 101, '201')"));
+
+        createDataContext().performGenericQuery(inserts);
+
+        SQLTemplate unionSql = new SQLTemplate(
+                SubEntity1.class,
+                "SELECT ID, SUBENTITY_STRING_DB_ATTR, SUPER_STRING_DB_ATTR, SUPER_INT_DB_ATTR,
NULL, 'INHERITANCE_SUB_ENTITY1'"
+                        + " FROM INHERITANCE_SUB_ENTITY1"
+                        + " UNION ALL"
+                        + " SELECT ID, OVERRIDDEN_STRING_DB_ATTR, NULL, SUBENTITY_INT_DB_ATTR,
SUBENTITY_INT_DB_ATTR, 'INHERITANCE_SUB_ENTITY2'"
+                        + " FROM INHERITANCE_SUB_ENTITY2");
+
+        unionSql.setFetchingDataRows(true);
+        assertEquals(2, createDataContext().performQuery(unionSql).size());
+    }
+
+    public void testSelectQueryOnConcreteLeafEntity() {
+
+        QueryChain inserts = new QueryChain();
         inserts
                 .addQuery(new SQLTemplate(
                         SubEntity1.class,
                         "INSERT INTO INHERITANCE_SUB_ENTITY1 "
                                 + "(ID, SUBENTITY_STRING_DB_ATTR, SUPER_INT_DB_ATTR, SUPER_STRING_DB_ATTR)
"
-                                + "VALUES (2, 'V12',2, 'V22')"));
+                                + "VALUES (1, 'V11', 1, 'V21')"));
+        inserts
+                .addQuery(new SQLTemplate(
+                        SubEntity1.class,
+                        "INSERT INTO INHERITANCE_SUB_ENTITY2 "
+                                + "(ID, OVERRIDDEN_STRING_DB_ATTR, SUBENTITY_INT_DB_ATTR,
SUPER_INT_DB_ATTR) "
+                                + "VALUES (2, 'V21', 3, 4)"));
         createDataContext().performGenericQuery(inserts);
 
         SelectQuery select = new SelectQuery(SubEntity1.class);
@@ -67,34 +99,32 @@
         assertEquals("V12", result.get(1).getSubEntityStringAttr());
     }
 
-    public void testDatabaseUnionCapabilities() {
-
+    public void testSelectQueryOnAbstractEntity() {
         QueryChain inserts = new QueryChain();
         inserts
                 .addQuery(new SQLTemplate(
                         SubEntity1.class,
                         "INSERT INTO INHERITANCE_SUB_ENTITY1 "
                                 + "(ID, SUBENTITY_STRING_DB_ATTR, SUPER_INT_DB_ATTR, SUPER_STRING_DB_ATTR)
"
-                                + "VALUES (1, 'V11', 1, 'V21')"));
-
+                                + "VALUES (1, 'V11', 1, 'V12')"));
         inserts
                 .addQuery(new SQLTemplate(
                         SubEntity1.class,
                         "INSERT INTO INHERITANCE_SUB_ENTITY2 "
-                                + "(ID, OVERRIDDEN_STRING_DB_ATTR, SUBENTITY_INT_DB_ATTR,
SUBENTITY_INT_DB_ATTR) "
-                                + "VALUES (1, 'VX11', 101, '201')"));
-
-        createDataContext().performGenericQuery(inserts);
-
-        SQLTemplate unionSql = new SQLTemplate(
-                SubEntity1.class,
-                "SELECT ID, SUBENTITY_STRING_DB_ATTR, SUPER_STRING_DB_ATTR, SUPER_INT_DB_ATTR,
NULL, 'INHERITANCE_SUB_ENTITY1'"
-                        + " FROM INHERITANCE_SUB_ENTITY1"
-                        + " UNION ALL"
-                        + " SELECT ID, OVERRIDDEN_STRING_DB_ATTR, NULL, SUBENTITY_INT_DB_ATTR,
SUBENTITY_INT_DB_ATTR, 'INHERITANCE_SUB_ENTITY2'"
-                        + " FROM INHERITANCE_SUB_ENTITY2");
+                                + "(ID, SUBENTITY_STRING_DB_ATTR, SUPER_INT_DB_ATTR, SUPER_STRING_DB_ATTR)
"
+                                + "VALUES (2, 'V21',2, 'V22')"));
+        
+        SelectQuery select = new SelectQuery(AbstractSuperEntity.class);
+        select.addOrdering(AbstractSuperEntity.SUPER_STRING_ATTR_PROPERTY, true);
 
-        unionSql.setFetchingDataRows(true);
-        assertEquals(2, createDataContext().performQuery(unionSql).size());
+        List<AbstractSuperEntity> result = createDataContext().performQuery(select);
+        assertEquals(2, result.size());
+        assertTrue(result.get(0) instanceof SubEntity1);
+        assertEquals(PersistenceState.COMMITTED, result.get(0).getPersistenceState());
+        assertEquals("V12", result.get(0).getSuperStringAttr());
+        
+        assertTrue(result.get(1) instanceof SubEntity2);
+        assertEquals(PersistenceState.COMMITTED, result.get(1).getPersistenceState());
+        assertEquals("V22", result.get(1).getSuperStringAttr());
     }
 }



Mime
View raw message