incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r900525 - in /incubator/aries/trunk/jpa/jpa-container-context: ./ main/test/java/ main/test/resources/ src/main/java/org/apache/aries/jpa/container/context/ src/main/resources/OSGI-INF/blueprint/ src/test/ src/test/java/ src/test/java/org/ ...
Date Mon, 18 Jan 2010 19:49:05 GMT
Author: mahrwald
Date: Mon Jan 18 19:49:05 2010
New Revision: 900525

URL: http://svn.apache.org/viewvc?rev=900525&view=rev
Log:
ARIES-118 Add a bit of glue code and move tests to correct directory

Added:
    incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
    incubator/aries/trunk/jpa/jpa-container-context/src/test/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/java/org/apache/aries/jpa/container/context/namespace/
      - copied from r900379, incubator/aries/trunk/jpa/jpa-container-context/main/test/java/org/apache/aries/jpa/container/context/namespace/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/resources/
    incubator/aries/trunk/jpa/jpa-container-context/src/test/resources/jpa.xml
      - copied unchanged from r900379, incubator/aries/trunk/jpa/jpa-container-context/main/test/resources/jpa.xml
Removed:
    incubator/aries/trunk/jpa/jpa-container-context/main/test/java/
    incubator/aries/trunk/jpa/jpa-container-context/main/test/resources/
Modified:
    incubator/aries/trunk/jpa/jpa-container-context/   (props changed)
    incubator/aries/trunk/jpa/jpa-container-context/src/main/resources/OSGI-INF/blueprint/jpa.xml

Propchange: incubator/aries/trunk/jpa/jpa-container-context/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jan 18 19:49:05 2010
@@ -0,0 +1,4 @@
+target
+.settings
+.classpath
+.project

Added: incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java?rev=900525&view=auto
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
(added)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/GlobalPersistenceManager.java
Mon Jan 18 19:49:05 2010
@@ -0,0 +1,97 @@
+/**
+ * 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.aries.jpa.container.context;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import org.apache.aries.jpa.container.context.impl.PersistenceContextManager;
+import org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.SynchronousBundleListener;
+
+public class GlobalPersistenceManager implements PersistenceManager, SynchronousBundleListener
{
+
+  private JTAPersistenceContextRegistry registry;
+  
+  private Map<Bundle, PersistenceContextManager> managers = 
+    new WeakHashMap<Bundle, PersistenceContextManager>();
+  
+  private Map<Bundle, Set<String>> persistenceContexts = 
+    new HashMap<Bundle, Set<String>>();
+  
+
+  public void setRegistry(JTAPersistenceContextRegistry registry) {
+    this.registry = registry;
+  }
+  
+  public void registerContext(String unitName, Bundle client, HashMap<String, Object>
properties) {
+    Bundle frameworkBundle = client.getBundleContext().getBundle(0);
+    PersistenceContextManager manager = null;
+    
+    synchronized (this) {
+      if (managers.containsKey(frameworkBundle)) {
+        manager = managers.get(frameworkBundle);
+      } else {
+        manager = new PersistenceContextManager(frameworkBundle.getBundleContext(), registry);
+        managers.put(frameworkBundle, manager);
+        frameworkBundle.getBundleContext().addBundleListener(this);
+      }
+      
+      if (!persistenceContexts.containsKey(client)) {
+        persistenceContexts.put(client, new HashSet<String>());
+      }
+      
+      persistenceContexts.get(client).add(unitName);
+    }
+    
+    manager.registerContext(unitName, client, properties);
+  }
+
+  public void bundleChanged(BundleEvent event) {
+    Bundle bundle = event.getBundle();
+    
+    if (event.getType() == event.STOPPING) {
+      Set<String> contextsToBeRemoved = Collections.emptySet();
+      Bundle frameworkBundle = bundle.getBundleContext().getBundle(0);
+      PersistenceContextManager manager = null;
+      
+      synchronized (this) {
+        if (persistenceContexts.containsKey(bundle)) {
+          contextsToBeRemoved = persistenceContexts.get(bundle);
+          persistenceContexts.remove(bundle);
+          
+          manager = managers.get(frameworkBundle);
+          if (manager == null)
+            throw new IllegalStateException();
+        }        
+      }
+      
+      for (String context : contextsToBeRemoved) {
+        manager.unregisterContext(context, bundle);
+      }
+    }
+  }
+
+}

Modified: incubator/aries/trunk/jpa/jpa-container-context/src/main/resources/OSGI-INF/blueprint/jpa.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jpa/jpa-container-context/src/main/resources/OSGI-INF/blueprint/jpa.xml?rev=900525&r1=900524&r2=900525&view=diff
==============================================================================
--- incubator/aries/trunk/jpa/jpa-container-context/src/main/resources/OSGI-INF/blueprint/jpa.xml
(original)
+++ incubator/aries/trunk/jpa/jpa-container-context/src/main/resources/OSGI-INF/blueprint/jpa.xml
Mon Jan 18 19:49:05 2010
@@ -30,7 +30,9 @@
     </bean>
   </service>
   
-  <!-- TODO define persistenceManager bean -->
+  <bean id="persistenceManager" class="org.apache.aries.jpa.container.context">
+    <property name="registry" ref="JtaPersistenceContextRegistry" />
+  </bean>
   
   <bean id="JtaPersistenceContextRegistry" 
     class="org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry">



Mime
View raw message