Return-Path: Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: (qmail 26424 invoked from network); 3 Sep 2007 08:07:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Sep 2007 08:07:25 -0000 Received: (qmail 63124 invoked by uid 500); 3 Sep 2007 08:07:20 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 63102 invoked by uid 500); 3 Sep 2007 08:07:20 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 63093 invoked by uid 99); 3 Sep 2007 08:07:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 01:07:20 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Sep 2007 08:07:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4801C1A9832; Mon, 3 Sep 2007 01:07:03 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cayenne.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070903080703.4801C1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 owners; + + public Collection 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 @@ org.apache.cayenne.jpa.itest.ch2.entity.PropertyDefaultsInvalidEntity org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToOneOwner org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToOneOwned + org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToManyOwner + org.apache.cayenne.jpa.itest.ch2.entity.BidiOneToManyOwned 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);