aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1162076 - in /aries/trunk/jpa/jpa-container/src: main/java/org/apache/aries/jpa/container/impl/ main/resources/org/apache/aries/jpa/container/nls/ test/java/org/apache/aries/jpa/container/
Date Fri, 26 Aug 2011 12:15:09 GMT
Author: timothyjward
Date: Fri Aug 26 12:15:09 2011
New Revision: 1162076

URL: http://svn.apache.org/viewvc?rev=1162076&view=rev
Log:
ARIES-718: Support persistence units in EJB Bundles

Modified:
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
    aries/trunk/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties
    aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java?rev=1162076&r1=1162075&r2=1162076&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleHelper.java
Fri Aug 26 12:15:09 2011
@@ -49,6 +49,8 @@ public class PersistenceBundleHelper
   public static final String PERSISTENCE_UNIT_HEADER = "Meta-Persistence";
   /** The Web-ContextPath header (as defined in the web application bundle spec) */
   public static final String WEB_CONTEXT_PATH_HEADER = "Web-ContextPath";
+  /** The Export-EJB header (as defined in the web application bundle spec) */
+  public static final String EXPORT_EJB_HEADER = "Export-EJB";
 
   /**
    * This method locates persistence descriptor files based on a combination of
@@ -66,12 +68,13 @@ public class PersistenceBundleHelper
     Dictionary<String, String> headers = bundle.getHeaders();
     String metaPersistence = headers.get(PERSISTENCE_UNIT_HEADER);
     String webContextPath = headers.get(WEB_CONTEXT_PATH_HEADER);
+    String exportEJB = headers.get(EXPORT_EJB_HEADER);
     
     String bundleIdentity = bundle.getSymbolicName() + '/' + bundle.getVersion();
     
     Collection<String> locations;
     
-    if (metaPersistence == null) {
+    if (metaPersistence == null && exportEJB == null) {
       if(webContextPath == null) {
         return Collections.emptySet();
       } else {
@@ -79,7 +82,7 @@ public class PersistenceBundleHelper
        
         String bundleClassPath = headers.get(Constants.BUNDLE_CLASSPATH);
         
-        locations = findWABClassPathLocations(bundleClassPath);
+        locations = findPersistenceXmlOnClassPath(bundleClassPath);
 
         if(_logger.isInfoEnabled())
           _logger.info(NLS.MESSAGES.getMessage("wab.without.meta.persistence.header", bundleIdentity,
WEB_CONTEXT_PATH_HEADER, PERSISTENCE_UNIT_HEADER, locations));
@@ -91,7 +94,9 @@ public class PersistenceBundleHelper
       locations = new HashSet<String>();
       locations.add(PERSISTENCE_XML);
       
-      if(!!!metaPersistence.isEmpty()) {
+      if(exportEJB != null && metaPersistence == null){
+        _logger.info(NLS.MESSAGES.getMessage("ejb.without.meta.persistence.header", bundleIdentity,
EXPORT_EJB_HEADER, PERSISTENCE_UNIT_HEADER, locations));
+      } else if(!!!metaPersistence.isEmpty()) {
         //Split apart the header to get the individual entries
         for (String s : metaPersistence.split(",")) {
           locations.add(s.trim());
@@ -133,7 +138,7 @@ public class PersistenceBundleHelper
     return persistenceXmlFiles;
   }
 
-  private static Collection<String> findWABClassPathLocations(String bundleClassPath)
{
+  private static Collection<String> findPersistenceXmlOnClassPath(String bundleClassPath)
{
     
     Collection<String> locations = new HashSet<String>();
     

Modified: aries/trunk/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties?rev=1162076&r1=1162075&r2=1162076&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties
(original)
+++ aries/trunk/jpa/jpa-container/src/main/resources/org/apache/aries/jpa/container/nls/jpaContainerMessages.properties
Fri Aug 26 12:15:09 2011
@@ -44,6 +44,13 @@ no.overlap.for.version.range=There was n
 wab.without.meta.persistence.header=The bundle {0} specifies the {1} header; it does not
specify the {2} header. \
  This bundle will be scanned for persistence descriptors in the locations: {3} using the
rules defined by the \
  JPA specification for finding persistence descriptors for web applications.
+# {0} The bundle identity
+# {1} The Web-ContextPath header
+# {2} The Meta-Persistence header
+# {3} The locations
+ejb.without.meta.persistence.header=The bundle {0} specifies the {1} header; it does not
specify the {2} header. \
+ This bundle will be scanned for persistence descriptors in the locations: {3} using the
rules defined by the \
+ JPA specification for finding persistence descriptors for ejb applications.
 # {0} The location
 # {1} The bundle identity
 exception.while.locating.descriptor=There was an exception while locating the persistence
descriptor at location \

Modified: aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java?rev=1162076&r1=1162075&r2=1162076&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
(original)
+++ aries/trunk/jpa/jpa-container/src/test/java/org/apache/aries/jpa/container/PersistenceBundleLifecycleTest.java
Fri Aug 26 12:15:09 2011
@@ -225,6 +225,29 @@ public class PersistenceBundleLifecycleT
     testSuccessfulCreationEvent(ref, extenderContext, 3);
     testSuccessfulRegistrationEvent(ref, extenderContext, 3, "webInfClassesOnClassPath",
"jarOne", "jarTwo");
   }
+  
+  @Test
+  public void testManager_EJBNoMetaPersistence() throws Exception {
+   
+    
+    BundleContext extenderContext = preExistingBundleSetup();
+    
+    Hashtable<String,String> hash1 = new Hashtable<String, String>();
+    hash1.put("javax.persistence.provider", "no.such.Provider");
+    ServiceRegistration reg = persistenceBundle.getBundleContext().registerService(new String[]
{PersistenceProvider.class.getName()} ,
+        pp, hash1 );
+    
+    ServiceReference ref = reg.getReference();
+    setupEJBBundle();
+    
+    mgr.start(extenderContext);
+    
+    
+    Skeleton.getSkeleton(persistenceBundle).assertCalledExactNumberOfTimes(new MethodCall(Bundle.class,
"getEntry", String.class), 1);
+    
+    testSuccessfulCreationEvent(ref, extenderContext, 1);
+    testSuccessfulRegistrationEvent(ref, extenderContext, 1, "root");
+  }
 
   @Test
   public void testManager_OnePreExistingPersistenceBundle_OneExistingProvider() throws Exception
@@ -1264,6 +1287,13 @@ public class PersistenceBundleLifecycleT
     skel.setReturnValue(new MethodCall(Bundle.class, "getVersion"), new Version("0.0.0"));
     
   }
+  
+  private void setupEJBBundle() throws Exception {
+    
+    setupWABBundle();
+    persistenceBundle.getHeaders().remove("Web-ContextPath");
+    persistenceBundle.getHeaders().put("Export-EJB", "");
+  }
 
   private void buildJarFile(Skeleton skel, URL root, String filePath, String pUnitName) throws
URISyntaxException,
       IOException, FileNotFoundException {



Mime
View raw message