geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rotty3...@apache.org
Subject svn commit: r1854440 - in /geronimo/specs/trunk: ./ geronimo-jpa_2.2_spec/ geronimo-jpa_2.2_spec/src/main/java/javax/persistence/ geronimo-jpa_2.2_spec/src/main/java/javax/persistence/spi/ geronimo-jpa_2.2_spec/src/main/java/org/apache/geronimo/specs/jpa/
Date Wed, 27 Feb 2019 01:08:47 GMT
Author: rotty3000
Date: Wed Feb 27 01:08:46 2019
New Revision: 1854440

URL: http://svn.apache.org/viewvc?rev=1854440&view=rev
Log:
GERONIMO-6711 Use new style of OSGi integration via Service Loader Mediator for JPA 2.2

Note how much cleaner this is code wise!

Signed-off-by: Raymond Auge <rotty3000@apache.org>

Removed:
    geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
    geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
Modified:
    geronimo/specs/trunk/geronimo-jpa_2.2_spec/pom.xml
    geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/Persistence.java
    geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
    geronimo/specs/trunk/pom.xml

Modified: geronimo/specs/trunk/geronimo-jpa_2.2_spec/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.2_spec/pom.xml?rev=1854440&r1=1854439&r2=1854440&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.2_spec/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-jpa_2.2_spec/pom.xml Wed Feb 27 01:08:46 2019
@@ -8,7 +8,7 @@
     "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 
+     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
@@ -58,49 +58,6 @@
     <url>http://svn.apache.org/viewcvs.cgi/geronimo/specs/trunk/geronimo-jpa_2.2_spec/</url>
   </scm>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.core</artifactId>
-      <version>1.4.0</version>
-      <scope>compile</scope>
-      <optional>true</optional>
-      <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>compile</scope>
-      <optional>true</optional>
-      <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>
-    <dependency>
-      <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-osgi-locator</artifactId>
-      <version>1.0</version>
-      <scope>provided</scope>
-    </dependency>
-  </dependencies>
-
   <build>
     <pluginManagement>
       <plugins>
@@ -117,43 +74,43 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
-        <version>3.5.0</version>
+        <version>3.5.0</version><!--$NO-MVN-MAN-VER$-->
         <configuration>
           <instructions>
             <Bundle-SymbolicName>${project.groupId}.${project.artifactId};singleton=true</Bundle-SymbolicName>
             <Bundle-Activator>org.apache.geronimo.specs.jpa.PersistenceActivator</Bundle-Activator>
-            <Specification-Title>JSR-338 Java Persistence API 2.1</Specification-Title>
+            <Specification-Title>JSR-338 Java Persistence API 2.2</Specification-Title>
             <Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor>
-            <Specification-Version>2.1</Specification-Version>
-            <Private-Package>org.apache.geronimo.specs.jpa.*;org.apache.geronimo.osgi.locator</Private-Package>
+            <Specification-Version>2.2</Specification-Version>
             <!-- The OSGi specification requires these packages be exported as 1.1.  Unfortunately,
                  there are bundles out there that are currently expecting to use a 2.0 version.
 The duplicate
                  package exports are done to prevent breaking those packages -->
             <Export-Package>
-              javax.persistence;version=1.2;jpa=2.1,
-              javax.persistence.criteria;version=1.2;jpa=2.1,
-              javax.persistence.metamodel;version=1.2;jpa=2.1,
-              javax.persistence.spi;version=1.2;jpa=2.1,
-              javax.persistence;version=2.1,
-              javax.persistence.criteria;version=2.1,
-              javax.persistence.metamodel;version=2.1,
-              javax.persistence.spi;version=2.1
+              javax.persistence;version=1.3;jpa=2.2,
+              javax.persistence.criteria;version=1.3;jpa=2.2,
+              javax.persistence.metamodel;version=1.3;jpa=2.2,
+              javax.persistence.spi;version=1.3;jpa=2.2,
+              javax.persistence;version=2.2,
+              javax.persistence.criteria;version=2.2,
+              javax.persistence.metamodel;version=2.2,
+              javax.persistence.spi;version=2.2
             </Export-Package>
             <!-- bnd is not correctly handling these imports using wildcards, so they
                  need to be explicitly specified -->
             <Import-Package>
-              javax.persistence;version=1.2,
-              javax.persistence.criteria;version=1.2,
-              javax.persistence.metamodel;version=1.2,
-              javax.persistence.spi;version=1.2,
-              javax.sql;resolution:=optional,
-              org.osgi.framework;resolution:=optional,
-              org.osgi.util.tracker;resolution:=optional,
-              org.apache.geronimo.osgi.registry.api;resolution:=optional
+              javax.persistence;version=1.3,
+              javax.persistence.criteria;version=1.3,
+              javax.persistence.metamodel;version=1.3,
+              javax.persistence.spi;version=1.3,
+              javax.sql;resolution:=optional
             </Import-Package>
             <Provide-Capability><![CDATA[
-               osgi.contract;osgi.contract=JavaJPA;uses:="${packages;NAMED;javax.*}";version:List<Version>='2.1,2.0,1.0'
+              osgi.contract;osgi.contract=JavaJPA;uses:="${packages;NAMED;javax.*}";version:List<Version>='2.2,2.1,2.0,1.0'
             ]]></Provide-Capability>
+            <Require-Capability><![CDATA[
+              osgi.serviceloader;filter:="(osgi.serviceloader=javax.persistence.spi.PersistenceProvider)";cardinality:=multiple,
+              osgi.extender;filter:="(osgi.extender=osgi.serviceloader.processor)"
+            ]]></Require-Capability>
           </instructions>
           <unpackBundle>true</unpackBundle>
         </configuration>

Modified: geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/Persistence.java?rev=1854440&r1=1854439&r2=1854440&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/Persistence.java
(original)
+++ geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/Persistence.java
Wed Feb 27 01:08:46 2019
@@ -26,8 +26,6 @@ package javax.persistence;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -41,8 +39,6 @@ import javax.persistence.spi.Persistence
 import javax.persistence.spi.PersistenceProviderResolverHolder;
 import javax.persistence.spi.ProviderUtil;
 
-import org.apache.geronimo.osgi.locator.ProviderLocator;
-
 /**
  * Bootstrap class to obtain {@link javax.persistence.EntityManagerFactory}
  * references.
@@ -88,45 +84,6 @@ public class Persistence {
         List<PersistenceProvider> providers = getProviders();
 
         /*
-         * Geronimo/OpenJPA 1.0 unique behavior - Start by loading a provider
-         * explicitly specified in the properties and return any exceptions.
-         * The spec doesn't forbid providers that aren't a service - it only
-         * states that they "should" be implemented as services in Sect. 9.2.
-         *
-         * For 2.0 - We only perform the above behavior if the specified
-         * provider is not in the discovered list.
-         *
-         * Note: This special non-spec defined case will rethrow any encountered
-         * Exceptions as a PersistenceException.
-         */
-        Object propVal = props.get(PERSISTENCE_PROVIDER_PROPERTY);
-        if ((propVal != null) && (propVal instanceof String)) {
-            boolean isLoaded = false;
-            String providerName = propVal.toString();
-            // search the discovered providers for this explicit provider
-            for (PersistenceProvider provider : providers) {
-                if (provider.getClass().getName().compareTo(providerName) == 0) {
-                    isLoaded = true;
-                    break;
-                }
-            }
-            /*
-             * Only try to explicitly create this provider if we didn't
-             * find it as a service, while rethrowing any exceptions to
-             * match the old 1.0 behavior
-             */
-            if (!isLoaded) {
-                factory = createFactory(
-                    providerName.toString(),
-                    persistenceUnitName,
-                    props);
-                if (factory != null) {
-                    return factory;
-                }
-            }
-        }
-
-        /*
          * Now, the default JPA2 behavior of loading a provider from our resolver
          *
          * Note:  Change in behavior from 1.0, which always returned exceptions:
@@ -187,38 +144,6 @@ public class Persistence {
         }
     }
 
-    /*
-     * Geronimo/OpenJPA private helper code for PERSISTENCE_PROVIDER_PROPERTY
-     * @return EntityManagerFactory or null
-     * @throws PersistenceException
-     */
-    private static EntityManagerFactory createFactory(String providerName,
-            String persistenceUnitName, Map properties)
-            throws PersistenceException {
-
-        Class<?> providerClass;
-
-        // get our class loader
-        ClassLoader cl = PrivClassLoader.get(null);
-        if (cl == null)
-            cl = PrivClassLoader.get(Persistence.class);
-
-        try {
-            providerClass = ProviderLocator.loadClass(providerName, Persistence.class, cl);
-        } catch (Exception e) {
-            throw new PersistenceException("Invalid or inaccessible explicit provider class:
" +
-                providerName, e);
-        }
-        try {
-            PersistenceProvider provider = (PersistenceProvider) providerClass.newInstance();
-            return provider.createEntityManagerFactory(persistenceUnitName, properties);
-        } catch (Exception e) {
-            throw new PersistenceException("Explicit error returned from provider: " +
-                providerName + " for PU: " + persistenceUnitName, e);
-        }
-    }
-
-
     /**
      * Geronimo/OpenJPA private helper code for creating a PersistenceException
      * @param msg String to use as the exception message
@@ -285,8 +210,6 @@ public class Persistence {
          * @see javax.persistence.PersistenceUtil#isLoaded(java.lang.Object, java.lang.String)
          */
             public boolean isLoaded(Object entity, String attributeName) {
-                boolean isLoaded = true;
-
                 // Get the list of persistence providers from the resolver
                 List<PersistenceProvider> pps = getProviders();
 
@@ -352,30 +275,5 @@ public class Persistence {
             }
     }
 
-    /**
-     * Geronimo/OpenJPA private helper code for handling class loaders
-     */
-    private static class PrivClassLoader implements PrivilegedAction<ClassLoader> {
-        private final Class<?> c;
-
-        public static ClassLoader get(Class<?> c) {
-            final PrivClassLoader action = new PrivClassLoader(c);
-            if (System.getSecurityManager() != null)
-                return AccessController.doPrivileged(action);
-            else
-                return action.run();
-        }
-
-        private PrivClassLoader(Class<?> c) {
-            this.c = c;
-        }
-
-        public ClassLoader run() {
-            if (c != null)
-                return c.getClassLoader();
-            else
-                return Thread.currentThread().getContextClassLoader();
-        }
-    }
 }
 

Modified: geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java?rev=1854440&r1=1854439&r2=1854440&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
(original)
+++ geronimo/specs/trunk/geronimo-jpa_2.2_spec/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
Wed Feb 27 01:08:46 2019
@@ -25,22 +25,15 @@
 
 package javax.persistence.spi;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.List;
+import java.util.ServiceLoader;
 import java.util.WeakHashMap;
 
 import javax.persistence.PersistenceException;
 
-import org.apache.geronimo.osgi.locator.ProviderLocator;
-
 /**
  * Contains Geronimo implemented code as required by the JPA spec.
  *
@@ -80,9 +73,6 @@ public class PersistenceProviderResolver
      */
     private static class DefaultPersistenceProviderResolver implements PersistenceProviderResolver
{
 
-        private static final String SERVICES_FILENAME = "META-INF/services/" +
-            PersistenceProvider.class.getName();
-
         // cache of providers per class loader
         private volatile WeakHashMap<ClassLoader, List<PersistenceProvider>>
providerCache =
             new WeakHashMap<ClassLoader, List<PersistenceProvider>>();
@@ -105,18 +95,11 @@ public class PersistenceProviderResolver
                 providers = new ArrayList<PersistenceProvider>();
                 try {
                     // add each one to our list
-                    List<Object> serviceProviders = ProviderLocator.getServices(PersistenceProvider.class.getName(),
this.getClass(), cl);
-                    for (Object o : serviceProviders) {
-                        providers.add((PersistenceProvider)o);
+                    for (PersistenceProvider provider : ServiceLoader.load(PersistenceProvider.class,
cl)) {
+                        providers.add(provider);
                     }
                     // cache the discovered providers
                     providerCache.put(cl, providers);
-                } catch (ClassNotFoundException e) {
-                    throw new PersistenceException("Failed to load provider from META-INF/services",
e);
-                } catch (InstantiationException e) {
-                    throw new PersistenceException("Failed to load provider from META-INF/services",
e);
-                } catch (IllegalAccessException e) {
-                    throw new PersistenceException("Failed to load provider from META-INF/services",
e);
                 } catch (Exception e) {
                     throw new PersistenceException("Failed to load provider from META-INF/services",
e);
                 }

Modified: geronimo/specs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/pom.xml?rev=1854440&r1=1854439&r2=1854440&view=diff
==============================================================================
--- geronimo/specs/trunk/pom.xml (original)
+++ geronimo/specs/trunk/pom.xml Wed Feb 27 01:08:46 2019
@@ -178,7 +178,6 @@
                 <!-- WS Metadata 2.1           NONE -->
                 <!-- JSF 2.3                   NONE -->
                 <module>geronimo-annotation_1.3_spec</module>
-                <!-- JPA 2.2                   NONE -->
                 <module>geronimo-jpa_2.2_spec</module>
                 <module>geronimo-validation_2.0_spec</module>
                 <!-- Managed Beans 1.0         NONE -->



Mime
View raw message