openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r940093 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/ openjpa-persistence/...
Date Sat, 01 May 2010 19:00:23 GMT
Author: curtisr7
Date: Sat May  1 19:00:23 2010
New Revision: 940093

URL: http://svn.apache.org/viewvc?rev=940093&view=rev
Log:
OPENJPA-1634: Process JAXB metadata when preloading the MetaDataRepository.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/DelegatingMetaDataFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java?rev=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/AbstractExpressionBuilder.java
Sat May  1 19:00:23 2010
@@ -312,7 +312,7 @@ public abstract class AbstractExpression
         }
         else {
             // xmlsupport xpath
-            XMLMetaData xmlmeta = fmd.getRepository().getXMLMetaData(fmd);
+            XMLMetaData xmlmeta = fmd.getRepository().getXMLMetaData(fmd.getDeclaredType());
             if (xmlmeta != null) {
                 path.get(fmd, xmlmeta);
                 return path;

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/DelegatingMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/DelegatingMetaDataFactory.java?rev=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/DelegatingMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/DelegatingMetaDataFactory.java
Sat May  1 19:00:23 2010
@@ -123,8 +123,8 @@ public class DelegatingMetaDataFactory
         _delegate.addFieldExtensionKeys(exts);
     }
 
-    public void loadXMLMetaData(FieldMetaData fmd) {
-        _delegate.loadXMLMetaData(fmd);
+    public void loadXMLMetaData(Class<?> cls) {
+        _delegate.loadXMLMetaData(cls);
     }
     
     public String getMetaModelClassName(String managedClassName) {

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataFactory.java?rev=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataFactory.java
Sat May  1 19:00:23 2010
@@ -151,7 +151,7 @@ public interface MetaDataFactory
      * Load XMLClassMetadata for the given class. Loaded
      * metadata should be added directly to the repository.
      */
-    public void loadXMLMetaData(FieldMetaData fmd);
+    public void loadXMLMetaData(Class<?> cls);
     
     /**
      * Gets the name of the meta-model class for the given fully-qualified

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=940093&r1=940092&r2=940093&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
Sat May  1 19:00:23 2010
@@ -332,7 +332,18 @@ public class MetaDataRepository implemen
             }
         }
         resolveAll(multi);
-
+        
+        // Preload XML MetaData
+        for (Class<?> cls : loaded) {
+            ClassMetaData cmd = getCachedMetaData(cls);
+            if (cmd != null) {
+                getXMLMetaData(cls);
+                for (FieldMetaData fmd : cmd.getFields()) {
+                    getXMLMetaData(fmd.getDeclaredType());
+                }
+            }
+        }
+        
         // Hook in this class as a listener and process registered classes list to populate
_aliases
         // list.
         PCRegistry.addRegisterClassListener(this);
@@ -2344,25 +2355,27 @@ public class MetaDataRepository implemen
      * @param fmd
      * @return XML metadata
      */
-    public XMLMetaData getXMLMetaData(FieldMetaData fmd) {
+    public XMLMetaData getXMLMetaData(Class<?> cls) {
         if (_locking) {
             synchronized (this) {
-                return getXMLMetaDataInternal(fmd);
+                return getXMLMetaDataInternal(cls);
             }
         } else {
-            return getXMLMetaDataInternal(fmd);
+            return getXMLMetaDataInternal(cls);
         }
     }
     
-    private XMLMetaData getXMLMetaDataInternal(FieldMetaData fmd) {
-        Class<?> cls = fmd.getDeclaredType();
+    private XMLMetaData getXMLMetaDataInternal(Class<?> cls) {
+        if (cls == null) {
+            return null;
+        }
         // check if cached before
         XMLMetaData xmlmeta = _xmlmetas.get(cls);
         if (xmlmeta != null)
             return xmlmeta;
 
         // load JAXB XML metadata
-        _factory.loadXMLMetaData(fmd);
+        _factory.loadXMLMetaData(cls);
 
         xmlmeta = (XMLClassMetaData) _xmlmetas.get(cls);
 
@@ -2376,8 +2389,8 @@ public class MetaDataRepository implemen
      * @param access
      *            the access type to use in populating metadata
      */
-    public XMLClassMetaData addXMLMetaData(Class<?> type, String name) {
-        XMLClassMetaData meta = newXMLClassMetaData(type, name);
+    public XMLClassMetaData addXMLClassMetaData(Class<?> type) {
+        XMLClassMetaData meta = newXMLClassMetaData(type);
         if(_locking){
             synchronized(this){
                 _xmlmetas.put(type, meta);                
@@ -2402,8 +2415,8 @@ public class MetaDataRepository implemen
      * @param name
      * @return a XMLClassMetaData
      */
-    protected XMLClassMetaData newXMLClassMetaData(Class<?> type, String name) {
-        return new XMLClassMetaData(type, name);
+    protected XMLClassMetaData newXMLClassMetaData(Class<?> type) {
+        return new XMLClassMetaData(type);
     }
 
     /**

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java?rev=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/NoneMetaDataFactory.java
Sat May  1 19:00:23 2010
@@ -144,7 +144,7 @@ public class NoneMetaDataFactory
         return null;
     }
     
-    public void loadXMLMetaData(FieldMetaData fmd) {
+    public void loadXMLMetaData(Class<?> cls) {
     }
 
     public String getMetaModelClassName(String managedClassName) {

Modified: 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=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/meta/TestMetaDataRepository.java
Sat May  1 19:00:23 2010
@@ -18,50 +18,75 @@
  */
 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.FieldMetaData;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.meta.QueryMetaData;
+import org.apache.openjpa.meta.XMLMetaData;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
+import org.apache.openjpa.persistence.xmlmapping.entities.Customer;
+import org.apache.openjpa.persistence.xmlmapping.entities.EAddress;
+import org.apache.openjpa.persistence.xmlmapping.entities.Order;
+import org.apache.openjpa.persistence.xmlmapping.xmlbindings.myaddress.Address;
 
 public class TestMetaDataRepository extends AbstractPersistenceTestCase {
-    private final String PU_NAME = "mdr-pu";
+	private final String PU_NAME = "mdr-pu";
 
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
+	@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");
+			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.contains("MdrTestEntity"));
+
+			// assertTrue(aliases.size() == numEntities);
+
+			QueryMetaData query = mdr.getCachedQueryMetaData(
+					MdrTestEntity.class, "query");
+			assertNotNull(query);
+		} finally {
+			if (emf != null) {
+				emf.close();
+			}
+		}
+	}
 
-    }
-
-    /**
-     * This method ensures that some of the basic MetaData is properly registered after creating
an
-     * EMF.
-     */
-    public void testPreloadBasic() {
+	public void testXmlMappingPreload() {
         OpenJPAEntityManagerFactorySPI emf = null;
         try {
-            emf = createNamedEMF(PU_NAME, "openjpa.MetaDataRepository", "Preload=true");
+            emf =
+                createNamedEMF("test", "openjpa.MetaDataRepository", "Preload=true", Customer.class,
+                    Customer.CustomerKey.class, Order.class, EAddress.class);
             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.contains("MdrTestEntity"));
-
-//            assertTrue(aliases.size() == numEntities);
+            assertNotNull(mdr.getCachedXMLMetaData(Address.class));
+            assertNull(mdr.getCachedXMLMetaData(Order.class));
+            
 
-            QueryMetaData query = mdr.getCachedQueryMetaData(MdrTestEntity.class, "query");
-            assertNotNull(query);
         } finally {
             if (emf != null) {
                 emf.close();

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java?rev=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
Sat May  1 19:00:23 2010
@@ -145,20 +145,19 @@ public class AnnotationPersistenceXMLMet
     }
 
     /**
-     * Parse persistence metadata for the given field metadata. If the MetaData(/Mapping)Repository
-     * is using locking, that lock MUST be held prior to calling this method.
+     * Parse persistence metadata for the given field metadata. This parser/class is NOT
threadsafe! The caller of 
+     * this method needs to insure that the MetaData(/Mapping)Repository is locked prior
to calling this method.
      */
-    public synchronized void parse(FieldMetaData fmd) {
-        Class<?> cls = fmd.getDeclaredType();
+    public synchronized void parse(Class<?> cls) {
         if (_log.isTraceEnabled())
             _log.trace(_loc.get("parse-class", cls.getName()));
-        parseXMLClassAnnotations(cls, fmd);
+        parseXMLClassAnnotations(cls);
     }
 
     /**
      * Read annotations for the current type.
      */
-    private XMLMetaData parseXMLClassAnnotations(Class<?> cls, FieldMetaData fmd) {
+    private XMLMetaData parseXMLClassAnnotations(Class<?> cls) {
         // check immediately whether the class has JAXB XML annotations
         if (cls == null || xmlTypeClass == null
             || !((AccessController.doPrivileged(J2DoPrivHelper
@@ -169,7 +168,7 @@ public class AnnotationPersistenceXMLMet
             return null;
 
         // find / create metadata
-        XMLMetaData meta = getXMLMetaData(cls, fmd);
+        XMLMetaData meta = getXMLMetaData(cls);
         
         return meta;
     }
@@ -177,11 +176,11 @@ public class AnnotationPersistenceXMLMet
     /**
      * Find or create xml metadata for the current type. 
      */
-    private XMLMetaData getXMLMetaData(Class<?> cls, FieldMetaData fmd) {
+    private XMLMetaData getXMLMetaData(Class<?> cls) {
         XMLMetaData meta = getRepository().getCachedXMLMetaData(cls);
         if (meta == null) {
             // if not in cache, create metadata
-            meta = getRepository().addXMLMetaData(cls, fmd.getName());
+            meta = getRepository().addXMLClassMetaData(cls);
             parseXmlRootElement(cls, meta);
             populateFromReflection(cls, meta);
         }
@@ -238,8 +237,7 @@ public class AnnotationPersistenceXMLMet
                     if ((AccessController.doPrivileged(J2DoPrivHelper
                         .isAnnotationPresentAction(((Field) member).getType(),
                             xmlTypeClass))).booleanValue()) {
-                        field = _repos.addXMLMetaData(((Field) member).getType()
-                            , member.getName());
+                        field = _repos.addXMLClassMetaData(((Field) member).getType());
                         parseXmlRootElement(((Field) member).getType(), field);
                         populateFromReflection(((Field) member).getType()
                             , field);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java?rev=940093&r1=940092&r2=940093&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
Sat May  1 19:00:23 2010
@@ -573,10 +573,10 @@ public class PersistenceMetaDataFactory
             (repos.getConfiguration());
     }
 
-    public void loadXMLMetaData(FieldMetaData fmd) {
+    public void loadXMLMetaData(Class<?> cls) {
         AnnotationPersistenceXMLMetaDataParser parser
             = getXMLAnnotationParser();
-        parser.parse(fmd);
+        parser.parse(cls);
     }
     
     private static String UNDERSCORE = "_";



Mime
View raw message