You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2010/02/25 15:59:53 UTC

svn commit: r916306 - in /incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main: java/org/apache/aries/jpa/blueprint/aries/impl/ resources/META-INF/blueprint/ resources/org/ resources/org/apache/ resources/org/apache/aries/ resources/org/apache/aries/...

Author: timothyjward
Date: Thu Feb 25 14:59:53 2010
New Revision: 916306

URL: http://svn.apache.org/viewvc?rev=916306&view=rev
Log:
ARIES-202 : Separate the JPA blueprint integration from managed persistence contexts

Added:
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/org/
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/org/apache/
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/org/apache/aries/
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/namespace/
Modified:
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java
    incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/META-INF/blueprint/jpa.xml

Modified: incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java?rev=916306&r1=916305&r2=916306&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java (original)
+++ incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java Thu Feb 25 14:59:53 2010
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
@@ -42,6 +43,7 @@
 import org.apache.aries.jpa.container.PersistenceUnitConstants;
 import org.apache.aries.jpa.container.context.PersistenceContextProvider;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
 import org.osgi.service.blueprint.reflect.BeanProperty;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -104,7 +106,9 @@
     private static final String ACTIVATION_EAGER = "EAGER";
     /** The {@link PersistenceManager} to register contexts with */
     private PersistenceContextProvider manager;
-
+    /** Used to indicate whether the PersistenceContextProvider is available */
+    private final AtomicBoolean contextsAvailable = new AtomicBoolean();
+    
     public void setManager(PersistenceContextProvider manager) {
         this.manager = manager;
     }
@@ -168,8 +172,13 @@
             properties.put(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE,
                     parseType(element));
             properties.putAll(parseJPAProperties(element, context));
-
-            manager.registerContext(unitName, client, properties);
+            if(contextsAvailable.get()) {
+                manager.registerContext(unitName, client, properties);
+            } else {
+                _logger.warn("The bundle {} is a client of persistence unit {} with properties {}, but no PersistenceContextProvider is available in the runtime. " +
+                		"The blueprint for this bundle will not start correctly unless the managed persistence context is registered through some other mechanism",
+                		new Object[] {client.getSymbolicName() + "_" + client.getVersion(), unitName, properties});
+            }
         }
 
         // Create a new Bean to replace the one passed in
@@ -217,8 +226,28 @@
                 .error("The JPA namespace handler was called to parse a top level element.");
         throw new UnsupportedOperationException();
     }
+    
+    /**
+     * Called when a {@link PersistenceContextProvider} is available
+     * @param ref
+     */
+    public void contextAvailable(ServiceReference ref) {
+        boolean log = contextsAvailable.compareAndSet(false, true);
+      
+        if(log && _logger.isDebugEnabled())
+            _logger.debug("Managed persistence context support is now available for use with the Aries Blueprint container");
+    }
 
     /**
+     * Called when a {@link PersistenceContextProvider} is no longer available
+     * @param ref
+     */
+    public void contextUnavailable(ServiceReference ref) {
+        contextsAvailable.set(false);
+        _logger.warn("Managed persistence context support is no longer available for use with the Aries Blueprint container");
+    }
+    
+    /**
      * Create a BeanProperty that will inject a JPA resource into a bean
      * 
      * @param element
@@ -469,6 +498,5 @@
         public boolean isProcessor() {
             return delegate.isProcessor();
         }
-        
     }
 }

Modified: incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/META-INF/blueprint/jpa.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/META-INF/blueprint/jpa.xml?rev=916306&r1=916305&r2=916306&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/META-INF/blueprint/jpa.xml (original)
+++ incubator/aries/trunk/jpa/jpa-blueprint-aries/src/main/resources/META-INF/blueprint/jpa.xml Thu Feb 25 14:59:53 2010
@@ -21,16 +21,20 @@
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
             
-  <service interface="org.apache.aries.blueprint.NamespaceHandler">
+  <service ref="namespaceHandler" interface="org.apache.aries.blueprint.NamespaceHandler">
     <service-properties>
-      <entry key="osgi.service.blueprint.namespace" value="http://aries.apache.org/xmlns/jpa/v1.0.0"/>
+      <entry key="osgi.service.blueprint.namespace" 
+             value="http://aries.apache.org/xmlns/jpa/v1.0.0"/>
     </service-properties>
-    <bean class="org.apache.aries.jpa.container.context.namespace.NSHandler">
-      <property name="manager" ref="persistenceContextProvider" />
-    </bean>
   </service>
   
-  <reference id="persistenceContextProvider" 
-       interface="org.apache.aries.jpa.container.context.PersistenceContextProvider"/>
+  <bean id="namespaceHandler" class="org.apache.aries.jpa.container.context.namespace.NSHandler">
+    <property name="manager" ref="persistenceContextProvider" />
+  </bean>
   
+  <reference id="persistenceContextProvider" availability="optional"
+       interface="org.apache.aries.jpa.container.context.PersistenceContextProvider">
+    <reference-listener ref="namespaceHandler" bind-method="contextAvailable" 
+            unbind-method="contextUnavailable"/>
+  </reference>
 </blueprint>
\ No newline at end of file