You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2009/10/15 21:28:24 UTC

svn commit: r825623 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/ openjpa-persistence-jdbc/src/test/resources/META-INF/ openjpa-persistence/src/mai...

Author: curtisr7
Date: Thu Oct 15 19:28:23 2009
New Revision: 825623

URL: http://svn.apache.org/viewvc?rev=825623&view=rev
Log:
OPENJPA-250: Have preload process registered classes. Added simple preload testcase. Fixed problem where preloading wasn't being enabled due to a change in 821925.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/MdrTestEntity.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java   (with props)
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=825623&r1=825622&r2=825623&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java Thu Oct 15 19:28:23 2009
@@ -362,6 +362,11 @@
                 throw new MetaDataException(_loc.get("repos-preload-error"), pae);
             }
         }
+        
+        // Hook this class in early so we can process registered classes and add them 
+        // to _aliases list.
+        PCRegistry.addRegisterClassListener(this);
+        processRegisteredClasses(multi);
     }
 
     protected void lock() {
@@ -369,13 +374,13 @@
             _lock.lock();
         }
     }
-
+    
     protected void unlock() {
         if (_lock != null) {
             _lock.unlock();
         }
     }
-
+    
     /**
      * Return the metadata for the given class.
      * 
@@ -1530,6 +1535,7 @@
         } finally {
             unlock();
         }
+        
 
         Collection<String> pcNames = getPersistentTypeNames(false, envLoader);
         Collection<Class<?>> failed = null;

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/MdrTestEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/MdrTestEntity.java?rev=825623&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/MdrTestEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/MdrTestEntity.java Thu Oct 15 19:28:23 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.meta;
+
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+
+@Entity
+@NamedQueries( { @NamedQuery(name = "query", query = "SELECT p FROM MdrTestEntity p") })
+public class MdrTestEntity {
+    @Id
+    int id;
+
+    @ManyToOne(cascade = CascadeType.MERGE)
+    MdrTestEntity manyToOne;
+
+    @OneToMany
+    List<MdrTestEntity> oneToMany;
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/MdrTestEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java?rev=825623&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java Thu Oct 15 19:28:23 2009
@@ -0,0 +1,69 @@
+/*
+ * 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.meta;
+
+import java.security.AccessController;
+import java.util.Collection;
+
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.meta.MetaDataRepository;
+import org.apache.openjpa.meta.QueryMetaData;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+
+public class TestMetaDataRepository extends AbstractPersistenceTestCase {
+    private final String PU_NAME = "mdr-pu";
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+
+    }
+
+    /**
+     * This method ensures that some of the basic MetaData is properly registered after creating an
+     * EMF.
+     */
+    public void testPreloadBasic() {
+        OpenJPAEntityManagerFactorySPI emf = null;
+        try {
+            emf = createNamedEMF(PU_NAME, "openjpa.MetaDataRepository", "Preload=true,NoLock=true");
+            MetaDataRepository mdr = emf.getConfiguration().getMetaDataRepositoryInstance();
+
+            // Check that there is cached metadata in the repo
+            ClassMetaData metadata = mdr.getCachedMetaData(MdrTestEntity.class);
+            assertNotNull(metadata);
+
+            // Make sure that there is an alias registered
+            int numEntities =
+                mdr.getPersistentTypeNames(false,
+                    AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction())).size();
+            Collection<String> aliases = mdr.getAliasNames();
+            assertTrue(aliases.size() == numEntities);
+
+            QueryMetaData query = mdr.getCachedQueryMetaData(MdrTestEntity.class, "query");
+            assertNotNull(query);
+        } finally {
+            if (emf != null) {
+                emf.close();
+            }
+        }
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=825623&r1=825622&r2=825623&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 Thu Oct 15 19:28:23 2009
@@ -250,6 +250,10 @@
             <property name="openjpa.ManagedRuntime" value="org.apache.openjpa.jta.JTAManagedRuntime"/>
         </properties>
     </persistence-unit>
+    
+    <persistence-unit name="mdr-pu">
+        <class>org.apache.openjpa.persistence.meta.MdrTestEntity</class>
+    </persistence-unit>      
 
 </persistence>
 

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java?rev=825623&r1=825622&r2=825623&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java (original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java Thu Oct 15 19:28:23 2009
@@ -101,7 +101,7 @@
             // functions and they need to be allowed time to configure themselves before we go off and
             // start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
             // any exceptions here because we want to fail-fast.
-            Options o = Configurations.parseProperties(Configurations.getProperties("openjpa.MetaDataRepository"));
+            Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
             if(o.getBooleanProperty("Preload")){
                 conf.getMetaDataRepositoryInstance().preload();
             }
@@ -196,7 +196,7 @@
             // functions and they need to be allowed time to configure themselves before we go off and
             // start instanting configurable objects (ie:openjpa.MetaDataRepository). Don't catch
             // any exceptions here because we want to fail-fast.
-            Options o = Configurations.parseProperties(Configurations.getProperties("openjpa.MetaDataRepository"));
+            Options o = Configurations.parseProperties(Configurations.getProperties(conf.getMetaDataRepository()));
             if(o.getBooleanProperty("Preload")){
                 conf.getMetaDataRepositoryInstance().preload();
             }