cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1083911 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ cayenne-lifecycle/ cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/ cayenne-lifecycle/src/test/ja...
Date Mon, 21 Mar 2011 19:19:57 GMT
Author: aadamchik
Date: Mon Mar 21 19:19:56 2011
New Revision: 1083911

URL: http://svn.apache.org/viewvc?rev=1083911&view=rev
Log:
CAY-1547 cayenne-lifecycle: support for setting UuidRelationships

    * adding ServerRuntime.getDataSource()
    * adding DB-aware unit tests to cayenne-lifecycle

Added:
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E1.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E2.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/LifecycleMap.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/UuidRoot1.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E1.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E2.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_LifecycleMap.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_UuidRoot1.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/cayenne-lifecycle.xml
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/lifecycle-map.map.xml
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java
    cayenne/main/trunk/framework/cayenne-lifecycle/.classpath
    cayenne/main/trunk/framework/cayenne-lifecycle/pom.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java?rev=1083911&r1=1083910&r2=1083911&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/server/ServerRuntime.java
Mon Mar 21 19:19:56 2011
@@ -20,7 +20,10 @@ package org.apache.cayenne.configuration
 
 import java.util.Collection;
 
+import javax.sql.DataSource;
+
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.configuration.CayenneRuntime;
 import org.apache.cayenne.configuration.rop.client.ClientRuntime;
 import org.apache.cayenne.di.Module;
@@ -70,4 +73,36 @@ public class ServerRuntime extends Cayen
         return injector.getInstance(DataDomain.class);
     }
 
+    /**
+     * Provides access to the JDBC DataSource assigned to a given DataNode. A null
+     * argument will work if there's only one DataNode configured.
+     * <p>
+     * Normally Cayenne applications don't need to access DataSource or any other JDBC
+     * code directly, however in some unusual conditions it may be needed, and this method
+     * provides a shortcut to raw JDBC.
+     */
+    public DataSource getDataSource(String dataNodeName) {
+        DataDomain domain = getDataDomain();
+
+        if (dataNodeName != null) {
+            DataNode node = domain.getNode(dataNodeName);
+            if (node == null) {
+                throw new IllegalArgumentException("Unknown DataNode name: "
+                        + dataNodeName);
+            }
+
+            return node.getDataSource();
+        }
+
+        else {
+            Collection<DataNode> nodes = domain.getDataNodes();
+            if (nodes.size() != 1) {
+                throw new IllegalArgumentException(
+                        "If DataNode name is not specified, DataDomain must have exactly
1 DataNode. Actual node count: "
+                                + nodes.size());
+            }
+
+            return nodes.iterator().next().getDataSource();
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/.classpath
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/.classpath?rev=1083911&r1=1083910&r2=1083911&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/.classpath (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/.classpath Mon Mar 21 19:19:56 2011
@@ -2,6 +2,7 @@
 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
 	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry kind="src" path="src/test/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
 	<classpathentry kind="output" path="target/classes"/>

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/pom.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/pom.xml?rev=1083911&r1=1083910&r2=1083911&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/pom.xml (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/pom.xml Mon Mar 21 19:19:56 2011
@@ -20,6 +20,17 @@
 			<artifactId>mockito-all</artifactId>
 		</dependency>
 		<dependency>
+			<groupId>org.apache.cayenne.build-tools</groupId>
+			<artifactId>cayenne-test-utilities</artifactId>
+			<version>${project.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>hsqldb</groupId>
+			<artifactId>hsqldb</artifactId>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
 			<groupId>org.apache.cayenne.unpublished</groupId>
 			<artifactId>cayenne-legal-unpublished</artifactId>
 			<version>${version}</version>

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E1.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E1.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E1.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,7 @@
+package org.apache.cayenne.lifecycle.db;
+
+import org.apache.cayenne.lifecycle.db.auto._E1;
+
+public class E1 extends _E1 {
+
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E2.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E2.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/E2.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,7 @@
+package org.apache.cayenne.lifecycle.db;
+
+import org.apache.cayenne.lifecycle.db.auto._E2;
+
+public class E2 extends _E2 {
+
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/LifecycleMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/LifecycleMap.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/LifecycleMap.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/LifecycleMap.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,18 @@
+package org.apache.cayenne.lifecycle.db;
+
+import org.apache.cayenne.lifecycle.db.auto._LifecycleMap;
+
+public class LifecycleMap extends _LifecycleMap {
+
+    private static LifecycleMap instance;
+
+    private LifecycleMap() {}
+
+    public static LifecycleMap getInstance() {
+        if(instance == null) {
+            instance = new LifecycleMap();
+        }
+
+        return instance;
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/UuidRoot1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/UuidRoot1.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/UuidRoot1.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/UuidRoot1.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,9 @@
+package org.apache.cayenne.lifecycle.db;
+
+import org.apache.cayenne.lifecycle.db.auto._UuidRoot1;
+import org.apache.cayenne.lifecycle.relationship.UuidRelationship;
+
+@UuidRelationship(_UuidRoot1.UUID_PROPERTY)
+public class UuidRoot1 extends _UuidRoot1 {
+
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E1.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E1.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E1.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,16 @@
+package org.apache.cayenne.lifecycle.db.auto;
+
+import org.apache.cayenne.CayenneDataObject;
+
+/**
+ * Class _E1 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _E1 extends CayenneDataObject {
+
+
+    public static final String ID_PK_COLUMN = "ID";
+
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E2.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E2.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E2.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_E2.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,16 @@
+package org.apache.cayenne.lifecycle.db.auto;
+
+import org.apache.cayenne.CayenneDataObject;
+
+/**
+ * Class _E2 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _E2 extends CayenneDataObject {
+
+
+    public static final String ID_PK_COLUMN = "ID";
+
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_LifecycleMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_LifecycleMap.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_LifecycleMap.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_LifecycleMap.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,12 @@
+package org.apache.cayenne.lifecycle.db.auto;
+
+
+
+/**
+ * This class was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class _LifecycleMap {
+}
\ No newline at end of file

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_UuidRoot1.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_UuidRoot1.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_UuidRoot1.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/auto/_UuidRoot1.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,24 @@
+package org.apache.cayenne.lifecycle.db.auto;
+
+import org.apache.cayenne.CayenneDataObject;
+
+/**
+ * Class _UuidRoot1 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _UuidRoot1 extends CayenneDataObject {
+
+    public static final String UUID_PROPERTY = "uuid";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void setUuid(String uuid) {
+        writeProperty("uuid", uuid);
+    }
+    public String getUuid() {
+        return (String)readProperty("uuid");
+    }
+
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipHandlerTest.java
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,77 @@
+/*****************************************************************
+ *   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.lifecycle.relationship;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.lifecycle.db.E1;
+import org.apache.cayenne.lifecycle.db.UuidRoot1;
+import org.apache.cayenne.lifecycle.ref.ReferenceableHandler;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+
+public class UuidRelationshipHandlerTest extends TestCase {
+
+    private ServerRuntime runtime;
+
+    @Override
+    protected void setUp() throws Exception {
+        runtime = new ServerRuntime("cayenne-lifecycle.xml");
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        runtime.shutdown();
+    }
+
+    public void testRelate_Existing() throws Exception {
+
+        DBHelper dbHelper = new DBHelper(runtime.getDataSource(null));
+
+        TableHelper rootTable = new TableHelper(dbHelper, "UUID_ROOT1").setColumns(
+                "ID",
+                "UUID");
+        rootTable.deleteAll();
+        TableHelper e1Table = new TableHelper(dbHelper, "E1").setColumns("ID");
+        e1Table.deleteAll();
+        e1Table.insert(1);
+
+        ObjectContext context = runtime.getContext();
+        E1 e1 = (E1) Cayenne.objectForQuery(context, new SelectQuery(E1.class));
+
+        UuidRoot1 r1 = context.newObject(UuidRoot1.class);
+
+        ReferenceableHandler refHandler = new ReferenceableHandler(context
+                .getEntityResolver());
+        UuidRelationshipHandler handler = new UuidRelationshipHandler(refHandler);
+        handler.relate(r1, e1);
+
+        assertEquals("E1:1", r1.getUuid());
+        assertSame(e1, r1.readPropertyDirectly("cay:related:uuid"));
+        
+        context.commitChanges();
+        
+        Object[] r1x = rootTable.select();
+        assertEquals("E1:1", r1x[1]);
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/cayenne-lifecycle.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/cayenne-lifecycle.xml?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/cayenne-lifecycle.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/cayenne-lifecycle.xml
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="6">
+	<map name="lifecycle-map"/>
+
+	<node name="lifecycle-db"
+		 factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory"
+		 schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
+		>
+		<map-ref name="lifecycle-map"/>
+		<data-source>
+			<driver value="org.hsqldb.jdbcDriver"/>
+			<url value="jdbc:hsqldb:mem:lifecycle"/>
+			<connectionPool min="1" max="1"/>
+			<login userName="sa"/>
+		</data-source>
+	</node>
+</domain>

Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/lifecycle-map.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/lifecycle-map.map.xml?rev=1083911&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/lifecycle-map.map.xml
(added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/resources/lifecycle-map.map.xml
Mon Mar 21 19:19:56 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	 xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+	 project-version="6">
+	<property name="defaultPackage" value="org.apache.cayenne.lifecycle.db"/>
+	<db-entity name="E1">
+		<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
+	<db-entity name="E2">
+		<db-attribute name="ID" type="BIGINT" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
+	<db-entity name="UUID_ROOT1">
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="UUID" type="VARCHAR" length="200"/>
+	</db-entity>
+	<obj-entity name="E1" className="org.apache.cayenne.lifecycle.db.E1" dbEntityName="E1">
+	</obj-entity>
+	<obj-entity name="E2" className="org.apache.cayenne.lifecycle.db.E2" dbEntityName="E2">
+	</obj-entity>
+	<obj-entity name="UuidRoot1" className="org.apache.cayenne.lifecycle.db.UuidRoot1" dbEntityName="UUID_ROOT1">
+		<obj-attribute name="uuid" type="java.lang.String" db-attribute-path="UUID"/>
+	</obj-entity>
+</data-map>



Mime
View raw message