geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r828047 - in /geronimo/specs/trunk/geronimo-jpa_2.0_spec: ./ src/main/java/javax/persistence/spi/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/geronimo/ src/main/java/org/apache/geronimo/specs/ src/main/java/org/apa...
Date Wed, 21 Oct 2009 15:30:17 GMT
Author: dwoods
Date: Wed Oct 21 15:30:17 2009
New Revision: 828047

URL: http://svn.apache.org/viewvc?rev=828047&view=rev
Log:
GERONIMO-4410 Add support for resolving/loading providers in an OSGi environment

Added:
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
  (with props)
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
Modified:
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/pom.xml
    geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java

Modified: geronimo/specs/trunk/geronimo-jpa_2.0_spec/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/pom.xml?rev=828047&r1=828046&r2=828047&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.0_spec/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-jpa_2.0_spec/pom.xml Wed Oct 21 15:30:17 2009
@@ -56,6 +56,50 @@
         <url>http://svn.apache.org/viewcvs.cgi/geronimo/specs/trunk/geronimo-jpa_2.0_spec/</url>
     </scm>
 
+    <dependencies>
+<!--
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+-->
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>1.4.0</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.osgi.foundation</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>1.2.0</version>
+            <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.osgi.core</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>org.osgi.foundation</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>javax.servlet</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+    </dependencies>
+
     <build>
         <pluginManagement>
             <plugins>
@@ -74,8 +118,21 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Export-Package>javax.persistence*;version=2.0</Export-Package>
+                        <Bundle-SymbolicName>${groupId}.${artifactId};singleton=
+true</Bundle-SymbolicName>
+                        <Bundle-Activator>org.apache.geronimo.specs.jpa.PersistenceActivator</Bundle-Activator>
+                        <Specification-Title>JSR-317 Java Persistence API 2.0</Specification-Title>
+                        <Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor>
+                        <Specification-Version>2.0</Specification-Version>
+                        <Private-Package>org.apache.geronimo.specs.jpa.*</Private-Package>
+                        <Export-Package>javax.persistence.*;version=2.0</Export-Package>
+                        <Import-Package>javax.persistence.*;version=2.0,javax.sql;resolution:=optional,org.osgi.framework;resolution:=optional,org.osgi.util.tracker;resolution:=optional</Import-Package>
+                        <!-- Eclipse metadata
+                        <Eclipse-Autostart>false</Eclipse-Autostart>
+                        <Bundle-ClassPath>.</Bundle-ClassPath>
+                        -->
                     </instructions>
+                    <unpackBundle>true</unpackBundle>
                 </configuration>
             </plugin>
         </plugins>

Modified: geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java?rev=828047&r1=828046&r2=828047&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
(original)
+++ geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
Wed Oct 21 15:30:17 2009
@@ -51,11 +51,15 @@
     }
     
     public static void setPersistenceProviderResolver(PersistenceProviderResolver resolver)
{
+        if (persistenceResolver != null) {
+            persistenceResolver.clearCachedProviders();
+            persistenceResolver = null;
+        }
         if (resolver != null) {
-            if (persistenceResolver != null) {
-                persistenceResolver.clearCachedProviders();
-            }
             persistenceResolver = resolver;
+        } else {
+            // handle removing a resolver for OSGi environments
+            persistenceResolver = new DefaultPersistenceProviderResolver();
         }
     }
     

Added: geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java?rev=828047&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
(added)
+++ geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
Wed Oct 21 15:30:17 2009
@@ -0,0 +1,108 @@
+/**
+ *  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.geronimo.specs.jpa;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceProviderResolver;
+import javax.persistence.spi.PersistenceProviderResolverHolder;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * Used to discover/resolve JPA providers in an OSGi environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PersistenceActivator implements BundleActivator, PersistenceProviderResolver
{
+
+    public static final String PERSISTENCE_PROVIDER = PersistenceProvider.class.getName();
+
+    private Map<String, PersistenceProvider> providers = new WeakHashMap<String,
PersistenceProvider>();
+    private BundleContext ctx = null;
+    private ServiceTracker tracker = null;
+
+    /* (non-Javadoc)
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+     */
+    public void start(BundleContext arg0) throws Exception {
+        // bundle context for later ServiceReference lookups
+        ctx = arg0;
+        
+        // track providers as they register themselves
+        ServiceTrackerCustomizer customizer = new PersistenceTracker(this);
+        tracker = new ServiceTracker(ctx, PERSISTENCE_PROVIDER, customizer);
+        tracker.open();
+
+        // configure JPA provider resolver for OSGi
+        PersistenceProviderResolverHolder.setPersistenceProviderResolver(this);
+    }
+
+    /* (non-Javadoc)
+     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+     */
+    public void stop(BundleContext arg0) throws Exception {
+        // cleanup provider tracker
+        tracker.close();
+        tracker = null;
+        
+        // cleanup providers and remove ourselves as a JPA provider resolver
+        PersistenceProviderResolverHolder.setPersistenceProviderResolver(null);
+        providers.clear();
+        
+        // cleanup context
+        ctx = null;
+    }
+
+    
+    /* (non-Javadoc)
+     * @see javax.persistence.spi.PersistenceProviderResolver#clearCachedProviders()
+     */
+    public void clearCachedProviders() {
+        // no-op - handled by stop() in OSGi environment
+    }
+
+    /* (non-Javadoc)
+     * @see javax.persistence.spi.PersistenceProviderResolver#getPersistenceProviders()
+     */
+    public List<PersistenceProvider> getPersistenceProviders() {
+        return new ArrayList<PersistenceProvider>(providers.values());
+    }
+
+    protected PersistenceProvider addProvider(ServiceReference ref) {
+        PersistenceProvider provider = (PersistenceProvider) ctx.getService(ref);
+        String name = (String) ref.getProperty(PERSISTENCE_PROVIDER);
+        providers.put(name, provider);
+        return provider;
+    }
+    
+    protected void removeProvider(ServiceReference ref) {
+        String name = (String) ref.getProperty(PERSISTENCE_PROVIDER);
+        providers.remove(name);
+    }
+
+}

Propchange: geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java?rev=828047&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
(added)
+++ geronimo/specs/trunk/geronimo-jpa_2.0_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
Wed Oct 21 15:30:17 2009
@@ -0,0 +1,57 @@
+/**
+ *  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.geronimo.specs.jpa;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+/**
+ * Used to track JPA service providers in an OSGi environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PersistenceTracker implements ServiceTrackerCustomizer {
+
+    private PersistenceActivator activator;
+    
+    public PersistenceTracker(PersistenceActivator activator) {
+        this.activator = activator;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
+     */
+    public Object addingService(ServiceReference arg0) {
+        return activator.addProvider(arg0);
+    }
+
+    /* (non-Javadoc)
+     * @see org.osgi.util.tracker.ServiceTrackerCustomizer#modifiedService(org.osgi.framework.ServiceReference,
java.lang.Object)
+     */
+    public void modifiedService(ServiceReference arg0, Object arg1) {
+        // handle as a remove - modify is unsupported
+        removedService(arg0, arg1);
+    }
+
+    /* (non-Javadoc)
+     * @see org.osgi.util.tracker.ServiceTrackerCustomizer#removedService(org.osgi.framework.ServiceReference,
java.lang.Object)
+     */
+    public void removedService(ServiceReference arg0, Object arg1) {
+        activator.removeProvider(arg0);
+    }
+
+}



Mime
View raw message