openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r596954 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test: java/org/apache/openjpa/kernel/TestDynamicClassRegistration.java resources/META-INF/persistence.xml
Date Wed, 21 Nov 2007 06:25:30 GMT
Author: pcl
Date: Tue Nov 20 22:25:29 2007
New Revision: 596954

URL: http://svn.apache.org/viewvc?rev=596954&view=rev
Log:
Example of how to do dynamic class registration in OpenJPA.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestDynamicClassRegistration.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestDynamicClassRegistration.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestDynamicClassRegistration.java?rev=596954&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestDynamicClassRegistration.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/kernel/TestDynamicClassRegistration.java
Tue Nov 20 22:25:29 2007
@@ -0,0 +1,78 @@
+/*
+ * 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.kernel;
+
+import java.util.List;
+import java.util.Collections;
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.enhance.UnenhancedFieldAccess;
+import org.apache.openjpa.enhance.ManagedClassSubclasser;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.JPAFacadeHelper;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.query.SimpleEntity;
+import org.apache.openjpa.persistence.test.PersistenceTestCase;
+
+public class TestDynamicClassRegistration
+    extends PersistenceTestCase {
+
+    private OpenJPAEntityManagerFactorySPI emf;
+
+    public void setUp() throws Exception {
+        super.setUp();
+
+        emf = createNamedEMF("empty-pu");
+    }
+
+    public void testEnhancedDynamicClassRegistration() {
+        assertTrue(
+            PersistenceCapable.class.isAssignableFrom(SimpleEntity.class));
+
+        // trigger class initialization
+        new SimpleEntity();
+
+        ClassMetaData meta =
+            JPAFacadeHelper.getMetaData(emf, SimpleEntity.class);
+        assertNotNull(meta);
+        EntityManager em = emf.createEntityManager();
+        javax.persistence.Query q = em.createQuery("select o from simple o");
+        em.close();
+    }
+
+    public void testUnenhancedDynamicClassRegistration() {
+        assertFalse(PersistenceCapable.class.isAssignableFrom(
+            UnenhancedFieldAccess.class));
+
+        // trigger class initialization
+        ManagedClassSubclasser.prepareUnenhancedClasses(
+            emf.getConfiguration(),
+            Collections.singleton(UnenhancedFieldAccess.class),
+            null);
+
+        ClassMetaData meta =
+            JPAFacadeHelper.getMetaData(emf, UnenhancedFieldAccess.class);
+        assertNotNull(meta);
+        EntityManager em = emf.createEntityManager();
+        javax.persistence.Query q = em.createQuery(
+            "select o from UnenhancedFieldAccess o");
+        em.close();
+    }
+}
\ No newline at end of file

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=596954&r1=596953&r2=596954&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Tue
Nov 20 22:25:29 2007
@@ -71,4 +71,7 @@
                 value="DriverClassName=not.a.real.Driver,Url=jdbc:notreal://"/>
         </properties>
     </persistence-unit>
+
+    <persistence-unit name="empty-pu">
+    </persistence-unit>
 </persistence>



Mime
View raw message