openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r472310 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/ openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/
Date Tue, 07 Nov 2006 22:38:38 GMT
Author: awhite
Date: Tue Nov  7 14:38:37 2006
New Revision: 472310

URL: http://svn.apache.org/viewvc?view=rev&rev=472310
Log:
Test for the OpenJPAQuery.setSubclasses method.


Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntitySub.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
    incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntity.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties?view=diff&rev=472310&r1=472309&r2=472310
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/meta/localizer.properties
Tue Nov  7 14:38:37 2006
@@ -290,7 +290,7 @@
 bad-bk-file: Could not create a backup file for "{0}".
 running-all-classes: No targets were given.  Running on all classes listed in \
 	your configuration, or all persistent classes in the classpath if no \
-	classes are configured.
+	classes are configured.  Use -help to display tool usage information.
 fatal-change: There has been a fatal change to the definition of "{0}" or its \
 	schema since it was last mapped, or the mapping you defined is invalid:\n\
 	{1}\nOpenJPA will attempt to create a new mapping.

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties?view=diff&rev=472310&r1=472309&r2=472310
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties
Tue Nov  7 14:38:37 2006
@@ -1,10 +1,11 @@
 needs-runtime-enhance: "{0}" requires runtime enhancement: {1}
 runtime-enhance-pcclasses: You have enabled runtime enhancement, but have not \
-	specified the set of persistent classes.  OpenJPA must look for metadata for \
-	every loaded class, which might increase class load times significantly.
+	specified the set of persistent classes.  OpenJPA must look for metadata \
+    for every loaded class, which might increase class load times significantly.
 running-all-classes: No targets were given.  Running on all classes in your \
     persistent classes list, or all metadata files in classpath directories if \
-	you have not listed your persistent classes.
+	you have not listed your persistent classes.  Use -help to display tool \
+    usage information.
 detach-custom-ser: Type "{0}" is set to detach on serialize, but implements \
 	a custom readObject and/or writeObject method.  You cannot use custom \
 	serialization with detachment. 

Modified: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntity.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntity.java?view=diff&rev=472310&r1=472309&r2=472310
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntity.java
(original)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntity.java
Tue Nov  7 14:38:37 2006
@@ -19,10 +19,13 @@
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
 import javax.persistence.ManyToOne;
 import javax.persistence.Version;
 
 @Entity
+@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
 public class ManyOneEntity {
 
     @Id

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntitySub.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntitySub.java?view=auto&rev=472310
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntitySub.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntitySub.java
Tue Nov  7 14:38:37 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.query;
+
+import javax.persistence.Entity;
+
+@Entity
+public class ManyOneEntitySub 
+    extends ManyOneEntity {
+
+    private int subInt;
+
+    public int getSubInt() { 
+        return subInt; 
+    }
+
+    public void setSubInt(int subInt) { 
+        this.subInt = subInt; 
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/ManyOneEntitySub.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java?view=auto&rev=472310
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
Tue Nov  7 14:38:37 2006
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.query;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+/**
+ * Test that we can exclude subclass instances from query results.
+ *
+ * @author Abe White
+ */
+public class TestQueryExcludingSubclasses
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        Map props = new HashMap();
+        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
+            + ManyOneEntity.class.getName() + ";"
+            + ManyOneEntitySub.class.getName() + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+
+        ManyOneEntity e1 = new ManyOneEntity();
+        e1.setName("e1"); 
+        ManyOneEntity e2 = new ManyOneEntity();
+        e2.setName("e2"); 
+        ManyOneEntity invalid = new ManyOneEntity();
+        invalid.setName("invalid"); 
+        ManyOneEntitySub esub1 = new ManyOneEntitySub();
+        esub1.setName("esub1"); 
+        ManyOneEntitySub esub2 = new ManyOneEntitySub();
+        esub2.setName("esub2"); 
+        ManyOneEntitySub invalidsub = new ManyOneEntitySub();
+        invalidsub.setName("invalidsub"); 
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(e1);
+        em.persist(e2);
+        em.persist(invalid);
+        em.persist(esub1);
+        em.persist(esub2);
+        em.persist(invalidsub);
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from ManyOneEntity").executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void testQuery() {
+        EntityManager em = emf.createEntityManager();
+        Query q = em.createQuery("select e from ManyOneEntity e "
+            + "where e.name like 'e%' order by e.name asc");
+        List<ManyOneEntity> res = (List<ManyOneEntity>) q.getResultList();
+        assertEquals(4, res.size());
+        for (int i = 0; i < 2; i++) {
+            assertEquals(ManyOneEntity.class, res.get(i).getClass());
+            assertEquals("e" + (i + 1), res.get(i).getName());
+        }
+        for (int i = 0; i < 2; i++) {
+            assertEquals(ManyOneEntitySub.class, res.get(i + 2).getClass());
+            assertEquals("esub" + (i + 1), res.get(i + 2).getName());
+        }
+        em.close();
+    }
+
+    public void testQueryExcludingSubclasses() {
+        EntityManager em = emf.createEntityManager();
+        Query q = em.createQuery("select e from ManyOneEntity e "
+            + "where e.name like 'e%' order by e.name asc");
+        ((OpenJPAQuery) q).setSubclasses(false);
+        List<ManyOneEntity> res = (List<ManyOneEntity>) q.getResultList();
+        assertEquals(2, res.size());
+        for (int i = 0; i < res.size(); i++) {
+            assertEquals(ManyOneEntity.class, res.get(i).getClass());
+            assertEquals("e" + (i + 1), res.get(i).getName());
+        }
+        em.close();
+    }
+
+
+    public static void main(String[] args) {
+        TestRunner.run(TestQueryExcludingSubclasses.class);
+    }
+}
+



Mime
View raw message