cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r739984 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/ java/org/apache/cayenne/testdo/mt/auto/ resources/
Date Mon, 02 Feb 2009 13:00:16 GMT
Author: aadamchik
Date: Mon Feb  2 13:00:15 2009
New Revision: 739984

URL: http://svn.apache.org/viewvc?rev=739984&view=rev
Log:
adding unit tests for rop single table inheritance

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtTable1Subclass.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtTable1Subclass.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MultiTier.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/testmap.map.xml

Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java?rev=739984&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/CayenneContextInheritanceTest.java
Mon Feb  2 13:00:15 2009
@@ -0,0 +1,138 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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;
+
+import java.util.List;
+
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.testdo.mt.ClientMtTable1;
+import org.apache.cayenne.testdo.mt.ClientMtTable1Subclass;
+import org.apache.cayenne.testdo.mt.MtTable1;
+import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
+
+public class CayenneContextInheritanceTest extends CayenneCase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        deleteTestData();
+    }
+
+    @Override
+    protected AccessStack buildAccessStack() {
+        return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+    }
+
+    private CayenneContext createClientContext() {
+        ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
+        LocalConnection connection = new LocalConnection(
+                serverChannel,
+                LocalConnection.HESSIAN_SERIALIZATION);
+        ClientChannel clientChannel = new ClientChannel(connection);
+        return new CayenneContext(clientChannel);
+    }
+
+    public void testPerformQueryInheritanceLeaf() {
+
+        ObjectContext setupContext = createDataContext();
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1)
VALUES (1, 'xxx', 'yyy')"));
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1,
SUBCLASS_ATTRIBUTE1) VALUES (2, 'sub1', 'zzz', 'sa1')"));
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1)
VALUES (3, '1111', 'aaa')"));
+
+        CayenneContext context = createClientContext();
+
+        SelectQuery query = new SelectQuery(ClientMtTable1Subclass.class);
+        List<ClientMtTable1Subclass> objects = context.performQuery(query);
+
+        assertEquals(1, objects.size());
+        assertEquals("sa1", objects.get(0).getSubclassAttribute1());
+    }
+
+    public void testPerformQueryInheritanceSuper() {
+
+        ObjectContext setupContext = createDataContext();
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1)
VALUES (1, 'a', 'yyy')"));
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1,
SUBCLASS_ATTRIBUTE1) VALUES (2, 'sub1', 'zzz', 'sa1')"));
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1)
VALUES (3, 'z', 'aaa')"));
+
+        CayenneContext context = createClientContext();
+
+        SelectQuery query = new SelectQuery(ClientMtTable1.class);
+        List<ClientMtTable1> objects = context.performQuery(query);
+
+        assertEquals(3, objects.size());
+        assertEquals("a", objects.get(0).getGlobalAttribute1());
+        assertEquals("sa1", ((ClientMtTable1Subclass) objects.get(1))
+                .getSubclassAttribute1());
+    }
+    
+    public void testPerformQueryWithQualifierInheritanceSuper() {
+
+        ObjectContext setupContext = createDataContext();
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1)
VALUES (1, 'a', 'XX')"));
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1,
SUBCLASS_ATTRIBUTE1) VALUES (2, 'sub1', 'XXA', 'sa1')"));
+        setupContext
+                .performQuery(new SQLTemplate(
+                        MtTable1.class,
+                        "INSERT INTO MT_TABLE1 (TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1)
VALUES (3, 'z', 'MM')"));
+
+        CayenneContext context = createClientContext();
+
+        SelectQuery query = new SelectQuery(ClientMtTable1.class);
+        query.andQualifier(ExpressionFactory.likeExp(ClientMtTable1.SERVER_ATTRIBUTE1_PROPERTY,
"X%"));
+        List<ClientMtTable1> objects = context.performQuery(query);
+
+        assertEquals(2, objects.size());
+        assertEquals("a", objects.get(0).getGlobalAttribute1());
+        assertEquals("sa1", ((ClientMtTable1Subclass) objects.get(1))
+                .getSubclassAttribute1());
+    }
+
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtTable1Subclass.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtTable1Subclass.java?rev=739984&r1=739983&r2=739984&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtTable1Subclass.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtTable1Subclass.java
Mon Feb  2 13:00:15 2009
@@ -9,6 +9,29 @@
  */
 public abstract class _ClientMtTable1Subclass extends ClientMtTable1 {
 
+    public static final String SUBCLASS_ATTRIBUTE1_PROPERTY = "subclassAttribute1";
 
+    protected String subclassAttribute1;
+
+    public String getSubclassAttribute1() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "subclassAttribute1", false);
+        }
+
+        return subclassAttribute1;
+    }
+    public void setSubclassAttribute1(String subclassAttribute1) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "subclassAttribute1", false);
+        }
+
+        Object oldValue = this.subclassAttribute1;
+        this.subclassAttribute1 = subclassAttribute1;
+
+        // notify objectContext about simple property change
+        if(objectContext != null) {
+            objectContext.propertyChanged(this, "subclassAttribute1", oldValue, subclassAttribute1);
+        }
+    }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtTable1Subclass.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtTable1Subclass.java?rev=739984&r1=739983&r2=739984&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtTable1Subclass.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtTable1Subclass.java
Mon Feb  2 13:00:15 2009
@@ -10,7 +10,15 @@
  */
 public abstract class _MtTable1Subclass extends MtTable1 {
 
+    public static final String SUBCLASS_ATTRIBUTE1_PROPERTY = "subclassAttribute1";
 
     public static final String TABLE1_ID_PK_COLUMN = "TABLE1_ID";
 
+    public void setSubclassAttribute1(String subclassAttribute1) {
+        writeProperty("subclassAttribute1", subclassAttribute1);
+    }
+    public String getSubclassAttribute1() {
+        return (String)readProperty("subclassAttribute1");
+    }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MultiTier.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MultiTier.java?rev=739984&r1=739983&r2=739984&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MultiTier.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MultiTier.java
Mon Feb  2 13:00:15 2009
@@ -33,4 +33,4 @@
 
         return context.performQuery(new NamedQuery("ParameterizedMtQueryWithLocalCache",
parameters, values));
     }
-}
+}
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml?rev=739984&r1=739983&r2=739984&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/multi-tier.map.xml
Mon Feb  2 13:00:15 2009
@@ -44,6 +44,7 @@
 	<db-entity name="MT_TABLE1">
 		<db-attribute name="GLOBAL_ATTRIBUTE1" type="VARCHAR" length="100"/>
 		<db-attribute name="SERVER_ATTRIBUTE1" type="VARCHAR" length="100"/>
+		<db-attribute name="SUBCLASS_ATTRIBUTE1" type="VARCHAR" length="100"/>
 		<db-attribute name="TABLE1_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 	</db-entity>
 	<db-entity name="MT_TABLE2">
@@ -96,6 +97,7 @@
 	</obj-entity>
 	<obj-entity name="MtTable1Subclass" superEntityName="MtTable1" className="org.apache.cayenne.testdo.mt.MtTable1Subclass"
clientClassName="org.apache.cayenne.testdo.mt.ClientMtTable1Subclass">
 		<qualifier><![CDATA[globalAttribute1 = "sub1"]]></qualifier>
+		<obj-attribute name="subclassAttribute1" type="java.lang.String" db-attribute-path="SUBCLASS_ATTRIBUTE1"/>
 	</obj-entity>
 	<obj-entity name="MtTable2" className="org.apache.cayenne.testdo.mt.MtTable2" clientClassName="org.apache.cayenne.testdo.mt.ClientMtTable2"
dbEntityName="MT_TABLE2">
 		<obj-attribute name="globalAttribute" type="java.lang.String" db-attribute-path="GLOBAL_ATTRIBUTE"/>

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=739984&r1=739983&r2=739984&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
Mon Feb  2 13:00:15 2009
@@ -5,7 +5,6 @@
 	<property name="clientSupported" value="true"/>
 	<property name="defaultClientPackage" value="test.client"/>
 	<property name="defaultClientSuperclass" value="org.apache.cayenne.PersistentObject"/>
-	
 	<procedure name="cayenne_tst_out_proc">
 		<procedure-parameter name="in_param" type="INTEGER" direction="in"/>
 		<procedure-parameter name="out_param" type="INTEGER" direction="out"/>
@@ -585,14 +584,18 @@
 	<obj-relationship name="painting" source="PaintingInfo" target="Painting" deleteRule="Nullify"
db-relationship-path="painting"/>
 	<obj-relationship name="paintingArray" source="ROArtist" target="Painting" deleteRule="Deny"
db-relationship-path="paintingArray"/>
 	<obj-relationship name="toArtist" source="ROPainting" target="Artist" deleteRule="Nullify"
db-relationship-path="toArtist"/>
+	<query name="EjbqlQueryTest" factory="org.apache.cayenne.map.EjbqlBuilder">
+		<property name="cayenne.GenericSelectQuery.fetchingDataRows" value="true"/>
+		<property name="cayenne.GenericSelectQuery.cacheStrategy" value="SHARED_CACHE"/>
+		<ejbql><![CDATA[select * from ejbql]]></ejbql>
+	</query>
 	<query name="NonSelectingQuery" factory="org.apache.cayenne.map.SQLTemplateBuilder" root="data-map"
root-name="testmap">
-		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="upper"/>
+		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="UPPER"/>
 		<sql><![CDATA[INSERT INTO PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE)
 VALUES (512, 'No Painting Like This', 12.5)]]></sql>
 		<sql adapter-class="org.apache.cayenne.dba.db2.DB2Adapter"><![CDATA[INSERT INTO
PAINTING (PAINTING_ID, PAINTING_TITLE, ESTIMATED_PRICE) VALUES (512, 'No Painting Like This',
12.5)]]></sql>
 	</query>
 	<query name="ObjectQuery" factory="org.apache.cayenne.map.SelectQueryBuilder" root="obj-entity"
root-name="Painting">
-		<property name="cayenne.GenericSelectQuery.refreshingObjects" value="false"/>
 		<qualifier><![CDATA[toArtist = $artist]]></qualifier>
 		<ordering><![CDATA[paintingTitle]]></ordering>
 	</query>
@@ -629,19 +632,14 @@
 	</query>
 	<query name="SelectTestLower" factory="org.apache.cayenne.map.SQLTemplateBuilder" root="data-map"
root-name="testmap">
 		<property name="cayenne.GenericSelectQuery.fetchingDataRows" value="true"/>
-		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="lower"/>
+		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="LOWER"/>
 		<sql><![CDATA[select * from ARTIST]]></sql>
 	</query>
 	<query name="SelectTestUpper" factory="org.apache.cayenne.map.SQLTemplateBuilder" root="data-map"
root-name="testmap">
 		<property name="cayenne.GenericSelectQuery.fetchingDataRows" value="true"/>
-		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="upper"/>
+		<property name="cayenne.SQLTemplate.columnNameCapitalization" value="UPPER"/>
 		<sql><![CDATA[select * from ARTIST]]></sql>
 	</query>
-	<query name="EjbqlQueryTest" factory="org.apache.cayenne.map.EjbqlBuilder">	
-		<property name="cayenne.GenericSelectQuery.cacheStrategy" value="SHARED_CACHE"/>
	
-		<property name="cayenne.GenericSelectQuery.fetchingDataRows" value="true"/>
-		<ejbql><![CDATA[select * from ejbql]]></ejbql>
-	</query>
 	<entity-listener class="org.apache.art.EntityListenerDataMap">
 		<pre-persist method-name="prePersistDataMap1"/>
 		<pre-persist method-name="prePersistDataMap2"/>



Mime
View raw message