[maven-release-plugin] copy for tag geronimo-jpa_2.2_spec-1.0
git-svn-id: https://svn.apache.org/repos/asf/geronimo/specs/tags/geronimo-jpa_2.2_spec-1.0@1854573 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index a37cc0f..762995a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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/tags/geronimo-jpa_2.2_spec-1.0</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,42 @@
<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>
diff --git a/src/main/java/javax/persistence/Persistence.java b/src/main/java/javax/persistence/Persistence.java
index 27a89ff..067a5b5 100644
--- a/src/main/java/javax/persistence/Persistence.java
+++ b/src/main/java/javax/persistence/Persistence.java
@@ -26,8 +26,6 @@
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.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 @@
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 @@
}
}
- /*
- * 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 @@
* @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 @@
}
}
- /**
- * 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();
- }
- }
}
diff --git a/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java b/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
index c91efa4..5d8133c 100644
--- a/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
+++ b/src/main/java/javax/persistence/spi/PersistenceProviderResolverHolder.java
@@ -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 @@
*/
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 @@
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);
}
diff --git a/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java b/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
deleted file mode 100644
index 1c4e123..0000000
--- a/src/main/java/org/apache/geronimo/specs/jpa/PersistenceActivator.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * 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;
-import org.apache.geronimo.osgi.locator.Activator;
-
-/**
- * Used to discover/resolve JPA providers in an OSGi environment.
- *
- * @version $Rev$ $Date$
- */
-public class PersistenceActivator extends Activator 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 {
- super.start(arg0);
- // 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;
-
- super.stop(arg0);
- }
-
-
- /* (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);
- }
-
-}
diff --git a/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java b/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
deleted file mode 100644
index b71692c..0000000
--- a/src/main/java/org/apache/geronimo/specs/jpa/PersistenceTracker.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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);
- }
-
-}