openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r630340 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence: relations/TestLazyManyToOne.java relations/UnidirectionalManyToOne.java simple/Person.java
Date Fri, 22 Feb 2008 22:40:10 GMT
Author: pcl
Date: Fri Feb 22 14:40:08 2008
New Revision: 630340

URL: http://svn.apache.org/viewvc?rev=630340&view=rev
Log:
Lazy many-to-one tests.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLazyManyToOne.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/UnidirectionalManyToOne.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Person.java

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLazyManyToOne.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLazyManyToOne.java?rev=630340&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLazyManyToOne.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestLazyManyToOne.java
Fri Feb 22 14:40:08 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.openjpa.persistence.relations;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.enhance.DynamicPersistenceCapable;
+
+public class TestLazyManyToOne extends SQLListenerTestCase {
+
+    private int id;
+
+    public void setUp() {
+        setUp(BasicEntity.class, UnidirectionalManyToOne.class, CLEAR_TABLES);
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        UnidirectionalManyToOne pc = new UnidirectionalManyToOne();
+        pc.setRelated(new BasicEntity());
+        pc.getRelated().setName("foo");
+        em.persist(pc);
+        em.getTransaction().commit();
+        id = pc.getId();
+        em.close();
+
+        sql.clear();
+    }
+
+    public void testLazyManyToOne() {
+        EntityManager em = emf.createEntityManager();
+        UnidirectionalManyToOne pc = em.find(UnidirectionalManyToOne.class, id);
+        if (pc instanceof PersistenceCapable // unenhanced has inefficiencies
+            && !(pc instanceof DynamicPersistenceCapable))
+            assertEquals(1, sql.size());
+        assertNotNull(pc.getRelated());
+        if (pc instanceof PersistenceCapable // unenhanced has inefficiencies
+            && !(pc instanceof DynamicPersistenceCapable))
+            assertEquals(2, sql.size());
+        em.close();
+    }
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/UnidirectionalManyToOne.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/UnidirectionalManyToOne.java?rev=630340&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/UnidirectionalManyToOne.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/UnidirectionalManyToOne.java
Fri Feb 22 14:40:08 2008
@@ -0,0 +1,53 @@
+/*
+ * 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.openjpa.persistence.relations;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.FetchType;
+import javax.persistence.Entity;
+import javax.persistence.CascadeType;
+
+@Entity
+public class UnidirectionalManyToOne {
+
+    @Id
+    @GeneratedValue
+    private int id;
+
+    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
+    private BasicEntity related;
+
+    public void setRelated(BasicEntity related) {
+        this.related = related;
+    }
+
+    public BasicEntity getRelated() {
+        return related;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+}

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Person.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Person.java?rev=630340&r1=630339&r2=630340&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Person.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Person.java
Fri Feb 22 14:40:08 2008
@@ -20,8 +20,6 @@
 
 import javax.persistence.Entity;
 import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.Version;
 
 @Entity
 public class Person {



Mime
View raw message