cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r572249 - in /cayenne/main/trunk/itests/jpa-chapter2/src: main/java/org/apache/cayenne/jpa/itest/ch2/entity/ main/resources/META-INF/ test/java/org/apache/cayenne/jpa/itest/ch2/ test/resources/
Date Mon, 03 Sep 2007 08:07:01 GMT
Author: aadamchik
Date: Mon Sep  3 01:06:57 2007
New Revision: 572249

URL: http://svn.apache.org/viewvc?rev=572249&view=rev
Log:
JPA itests: one-to-many defaults

Added:
    cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwned.java
    cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwner.java
    cayenne/main/trunk/itests/jpa-chapter2/src/test/java/org/apache/cayenne/jpa/itest/ch2/_2_1_8_2_BidiManyToOneRelationshipTest.java
Modified:
    cayenne/main/trunk/itests/jpa-chapter2/src/main/resources/META-INF/persistence.xml
    cayenne/main/trunk/itests/jpa-chapter2/src/test/resources/schema-hsqldb.sql

Added: cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwned.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwned.java?rev=572249&view=auto
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwned.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwned.java
Mon Sep  3 01:06:57 2007
@@ -0,0 +1,39 @@
+/*****************************************************************
+ *   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.jpa.itest.ch2.entity;
+
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class BidiOneToManyOwned {
+
+    @Id
+    protected int id;
+
+    @OneToMany(mappedBy = "owned")
+    protected Collection<BidiOneToManyOwner> owners;
+    
+    public Collection<BidiOneToManyOwner> getOwners() {
+        return owners;
+    }
+}

Added: cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwner.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwner.java?rev=572249&view=auto
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwner.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter2/src/main/java/org/apache/cayenne/jpa/itest/ch2/entity/BidiOneToManyOwner.java
Mon Sep  3 01:06:57 2007
@@ -0,0 +1,41 @@
+/*****************************************************************
+ *   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.jpa.itest.ch2.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+@Entity
+public class BidiOneToManyOwner {
+
+    @Id
+    protected int id;
+
+    @ManyToOne
+    protected BidiOneToManyOwned owned;
+
+    public BidiOneToManyOwned getOwned() {
+        return owned;
+    }
+
+    public void setOwned(BidiOneToManyOwned owned) {
+        this.owned = owned;
+    }
+}

Modified: cayenne/main/trunk/itests/jpa-chapter2/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter2/src/main/resources/META-INF/persistence.xml?rev=572249&r1=572248&r2=572249&view=diff
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter2/src/main/resources/META-INF/persistence.xml (original)
+++ cayenne/main/trunk/itests/jpa-chapter2/src/main/resources/META-INF/persistence.xml Mon
Sep  3 01:06:57 2007
@@ -42,5 +42,7 @@
 		<class>org.apache.cayenne.jpa.itest.ch2.entity.PropertyDefaultsInvalidEntity</class>
 		<class>org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToOneOwner</class>
 		<class>org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToOneOwned</class>
+		<class>org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToManyOwner</class>
+		<class>org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToManyOwned</class>
 	</persistence-unit>
 </persistence>

Added: cayenne/main/trunk/itests/jpa-chapter2/src/test/java/org/apache/cayenne/jpa/itest/ch2/_2_1_8_2_BidiManyToOneRelationshipTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter2/src/test/java/org/apache/cayenne/jpa/itest/ch2/_2_1_8_2_BidiManyToOneRelationshipTest.java?rev=572249&view=auto
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter2/src/test/java/org/apache/cayenne/jpa/itest/ch2/_2_1_8_2_BidiManyToOneRelationshipTest.java
(added)
+++ cayenne/main/trunk/itests/jpa-chapter2/src/test/java/org/apache/cayenne/jpa/itest/ch2/_2_1_8_2_BidiManyToOneRelationshipTest.java
Mon Sep  3 01:06:57 2007
@@ -0,0 +1,67 @@
+/*****************************************************************
+ *   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.jpa.itest.ch2;
+
+import org.apache.cayenne.itest.jpa.EntityManagerCase;
+import org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToManyOwned;
+import org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToManyOwner;
+
+public class _2_1_8_2_BidiManyToOneRelationshipTest extends EntityManagerCase {
+
+    public void testDefaultsSelect() throws Exception {
+        getDbHelper().deleteAll("BidiOneToManyOwner");
+        getDbHelper().deleteAll("BidiOneToManyOwned");
+
+        getDbHelper().insert("BidiOneToManyOwned", new String[] {
+            "id"
+        }, new Object[] {
+            5
+        });
+
+        getDbHelper().insert("BidiOneToManyOwner", new String[] {
+                "id", "owned_id"
+        }, new Object[] {
+                4, 5
+        });
+
+        getDbHelper().insert("BidiOneToManyOwned", new String[] {
+            "id"
+        }, new Object[] {
+            6
+        });
+
+        getDbHelper().insert("BidiOneToManyOwner", new String[] {
+                "id", "owned_id"
+        }, new Object[] {
+                5, 6
+        });
+
+        BidiOneToManyOwned owned = getEntityManager().find(BidiOneToManyOwned.class, 5);
+        assertNotNull(owned);
+        assertEquals(1, owned.getOwners().size());
+
+        BidiOneToManyOwner owner = getEntityManager().find(BidiOneToManyOwner.class, 4);
+        assertNotNull(owner);
+        assertTrue(owned.getOwners().contains(owner));
+        
+        BidiOneToManyOwner owner1 = getEntityManager().find(BidiOneToManyOwner.class, 5);
+        assertNotNull(owner1);
+        assertFalse(owned.getOwners().contains(owner1));
+    }
+}

Modified: cayenne/main/trunk/itests/jpa-chapter2/src/test/resources/schema-hsqldb.sql
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/jpa-chapter2/src/test/resources/schema-hsqldb.sql?rev=572249&r1=572248&r2=572249&view=diff
==============================================================================
--- cayenne/main/trunk/itests/jpa-chapter2/src/test/resources/schema-hsqldb.sql (original)
+++ cayenne/main/trunk/itests/jpa-chapter2/src/test/resources/schema-hsqldb.sql Mon Sep  3
01:06:57 2007
@@ -16,6 +16,8 @@
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('PropertyDefaultsOtherEntity',
1);
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('BidiOneToOneOwner', 1);
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('BidiOneToOneOwned', 1);
+insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('BidiOneToManyOwner', 1);
+insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('BidiOneToManyOwned', 1);
 
 create table FieldPersistenceEntity (id int not null, property1 VARCHAR(100), primary key(id));
 create table PropertyPersistenceEntity (id int not null, property1 VARCHAR(100), property2
BOOLEAN, primary key(id));
@@ -39,3 +41,6 @@
 create table BidiOneToOneOwner (id int not null, owned_id int not null, primary key(id));
 alter table BidiOneToOneOwner add constraint cfk_owned_id FOREIGN KEY (owned_id) references
BidiOneToOneOwned (id);
 alter table BidiOneToOneOwner add constraint cu_owned_id UNIQUE (owned_id);
+create table BidiOneToManyOwned (id int not null, primary key(id));
+create table BidiOneToManyOwner (id int not null, owned_id int not null, primary key(id));
+alter table BidiOneToManyOwner add constraint cfk_owned_id1 FOREIGN KEY (owned_id) references
BidiOneToManyOwned (id);



Mime
View raw message