openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r908621 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/conf/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-kernel/src/main/resources/org/apache/openjpa/meta/ openjpa-persistence/src/main/java/org/apache...
Date Wed, 10 Feb 2010 18:24:29 GMT
Author: faywang
Date: Wed Feb 10 18:23:59 2010
New Revision: 908621

URL: http://svn.apache.org/viewvc?rev=908621&view=rev
Log:
OPENJPA-1460: resolve visibility scope of orm.xml

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
    openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java?rev=908621&r1=908620&r2=908621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java
Wed Feb 10 18:23:59 2010
@@ -179,7 +179,7 @@
     private Collection<String> supportedOptions = new HashSet<String>(33);
     private final StoreFacadeTypeRegistry _storeFacadeRegistry = new StoreFacadeTypeRegistry();
     private BrokerFactoryEventManager _brokerFactoryEventManager = new BrokerFactoryEventManager(this);
-        
+    private Map<String, Object> _peMap; //contains persistence environment-specific
info    
 
     /**
      * Default constructor. Attempts to load global properties.
@@ -1727,5 +1727,13 @@
     public void setCacheDistributionPolicyInstance(CacheDistributionPolicy policy) {
         cacheDistributionPolicyPlugin.set(policy);
     }
+
+    public void setPersistenceEnvironment(Map<String, Object> peMap) {
+        this._peMap = peMap;
+    }
+
+    public Map<String, Object> getPersistenceEnvironment() {
+        return _peMap;
+    }
 }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java?rev=908621&r1=908620&r2=908621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/AbstractCFMetaDataFactory.java
Wed Feb 10 18:23:59 2010
@@ -39,6 +39,8 @@
 import java.util.zip.ZipInputStream;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.conf.OpenJPAConfigurationImpl;
 import org.apache.openjpa.lib.meta.ClassArgParser;
 import org.apache.openjpa.lib.meta.ClasspathMetaDataIterator;
 import org.apache.openjpa.lib.meta.FileMetaDataIterator;
@@ -76,6 +78,9 @@
     protected Collection<String> cpath = null;
 
     private Set<String> _typeNames = null;
+    public static final String PERSISTENCE_UNIT_ROOT_URL = "PersistenceUnitRootUrl";
+    public static final String MAPPING_FILE_NAMES = "MappingFileNames";
+    public static final String JAR_FILE_URLS = "JarFiles";
 
     /**
      * Set of {@link File}s of metadata files or directories supplied by user.
@@ -752,8 +757,52 @@
                     if (log.isTraceEnabled())
                         log.trace(_loc.get("scanning-resource", rsrc));
                     mitr = new ResourceMetaDataIterator(rsrc, loader);
+                    OpenJPAConfiguration conf = repos.getConfiguration();
+                    Map peMap = null;
+                    if (conf instanceof OpenJPAConfigurationImpl)
+                        peMap = ((OpenJPAConfigurationImpl)conf).getPersistenceEnvironment();
+                    URL puUrl = peMap == null ? null : (URL) peMap.get(PERSISTENCE_UNIT_ROOT_URL);
+                    List<String> mappingFileNames = 
+                        peMap == null ? null : (List<String>) peMap.get(MAPPING_FILE_NAMES);
+                    List<URL> jars = peMap == null ? null : (List<URL>)peMap.get(JAR_FILE_URLS);
+                    String puUrlString = puUrl == null ? null : puUrl.toString();
+                    if (log.isTraceEnabled())
+                        log.trace(_loc.get("pu-root-url", puUrlString));
+
+                    List<URL> urls = new ArrayList<URL>(3);
                     while (mitr.hasNext()) {
                         url = (URL) mitr.next();
+                        String urlString = url.toString();
+                        if (log.isTraceEnabled())
+                            log.trace(_loc.get("resource-url", urlString));
+                        if (peMap != null) {
+                            if (puUrlString != null && urlString.indexOf(puUrlString)
!= -1) 
+                                urls.add(url);
+                            if (mappingFileNames != null && mappingFileNames.size()
!= 0) {
+                                for (String mappingFileName : mappingFileNames) {
+                                    if (log.isTraceEnabled())
+                                        log.trace(_loc.get("mapping-file-name", mappingFileName));
+                                    if (urlString.indexOf(mappingFileName) != -1)
+                                        urls.add(url);
+                                }
+                            }
+
+                            if (jars != null && jars.size() != 0) {
+                                for (URL jarUrl : jars) {
+                                    if (log.isTraceEnabled())
+                                        log.trace(_loc.get("jar-file-url", jarUrl));
+                                    if (urlString.indexOf(jarUrl.toString()) != -1)
+                                        urls.add(url);
+                                }
+                            }
+                        } else {
+                            urls.add(url);
+                        }
+                    }
+                    mitr.close();
+
+                    for (Object obj : urls) {
+                        url = (URL) obj;
                         clss = cparser.parseTypeNames(new URLMetaDataIterator
                             (url));
                         List<String> newNames = Arrays.asList(clss);
@@ -763,7 +812,6 @@
                         names.addAll(newNames);
                         mapPersistentTypeNames(url, clss);
                     }
-                    mitr.close();
                 }
             }
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties?rev=908621&r1=908620&r2=908621&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/resources/org/apache/openjpa/meta/localizer.properties
Wed Feb 10 18:23:59 2010
@@ -357,4 +357,6 @@
 repos-initializeEager-error: Unexpected error during early loading of entity metadata during
initialization. \
     See nested stacktrace for details.	  
 pu-root-url: The persistent unit root url is "{0}"
-resource-url: The resource url is "{0}"   
\ No newline at end of file
+resource-url: The resource url is "{0}"   
+mapping-file-name: Mapping file name is "{0}"
+jar-file-url: Jar file url is "{0}"
\ No newline at end of file

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=908621&r1=908620&r2=908621&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
Wed Feb 10 18:23:59 2010
@@ -22,6 +22,7 @@
 import java.lang.instrument.IllegalClassFormatException;
 import java.security.AccessController;
 import java.security.ProtectionDomain;
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.persistence.EntityManager;
@@ -46,6 +47,7 @@
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
+import org.apache.openjpa.meta.AbstractCFMetaDataFactory;
 import org.apache.openjpa.meta.MetaDataModes;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.persistence.validation.ValidationUtils;
@@ -186,6 +188,9 @@
                     log.warn(_loc.get("transformer-registration-error", pui));
                 }
             }
+            OpenJPAConfiguration conf = factory.getConfiguration();
+            setPersistenceEnvironmentInfo(conf, pui);
+            _log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
 
             // Create appropriate LifecycleEventManager
             loadValidator(factory);
@@ -203,6 +208,20 @@
         }
     }
 
+    public void setPersistenceEnvironmentInfo(OpenJPAConfiguration conf, PersistenceUnitInfo
pui) {
+        // OPENJPA-1460 Fix scope visibility of orm.xml when it is packaged in both ear file
and war file
+        if (conf instanceof OpenJPAConfigurationImpl) {
+            Map<String, Object> peMap =((OpenJPAConfigurationImpl)conf).getPersistenceEnvironment();
+            if (peMap == null) {
+                peMap = new HashMap<String, Object>();
+                ((OpenJPAConfigurationImpl)conf).setPersistenceEnvironment(peMap);
+            }
+            peMap.put(AbstractCFMetaDataFactory.PERSISTENCE_UNIT_ROOT_URL, pui.getPersistenceUnitRootUrl());
+            peMap.put(AbstractCFMetaDataFactory.MAPPING_FILE_NAMES, pui.getMappingFileNames());
+            peMap.put(AbstractCFMetaDataFactory.JAR_FILE_URLS, pui.getJarFileUrls());
+        }
+    }
+    
     /*
      * Returns a ProviderUtil for use with entities managed by this
      * persistence provider.



Mime
View raw message