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 2011/07/26 21:35:50 UTC
svn commit: r1151218 - in
/aries/trunk/jpa/jpa-container-eclipselink-adapter: ./
src/main/java/org/apache/aries/jpa/eclipselink/adapter/
Author: timothyjward
Date: Tue Jul 26 19:35:49 2011
New Revision: 1151218
URL: http://svn.apache.org/viewvc?rev=1151218&view=rev
Log:
ARIES-691 : Allow EclipseLink adapter to work with multiple EclipseLink bundles concurrently
Added:
aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkProviderService.java
aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java
aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java
Modified:
aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml
aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/Activator.java
Modified: aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml?rev=1151218&r1=1151217&r2=1151218&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml (original)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/pom.xml Tue Jul 26 19:35:49 2011
@@ -38,8 +38,10 @@
<aries.osgi.export.pkg>org.apache.aries.jpa.eclipselink.adapter.platform</aries.osgi.export.pkg>
<aries.osgi.import.pkg>
javax.persistence*;version="[1.1,2.1)",
+ !org.eclipse.persistence.*,
*
</aries.osgi.import.pkg>
+ <aries.osgi.failok>true</aries.osgi.failok>
<aries.osgi.activator>org.apache.aries.jpa.eclipselink.adapter.Activator</aries.osgi.activator>
</properties>
@@ -76,6 +78,12 @@
<version>0.3.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.aries</groupId>
+ <artifactId>org.apache.aries.util</artifactId>
+ <version>0.4-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
Modified: aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/Activator.java?rev=1151218&r1=1151217&r2=1151218&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/Activator.java (original)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/Activator.java Tue Jul 26 19:35:49 2011
@@ -18,30 +18,19 @@
*/
package org.apache.aries.jpa.eclipselink.adapter;
-import java.lang.reflect.Constructor;
-import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
-import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.persistence.EntityManagerFactory;
-import javax.persistence.SharedCacheMode;
-import javax.persistence.ValidationMode;
-import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceProvider;
-import javax.persistence.spi.PersistenceUnitInfo;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.persistence.spi.ProviderUtil;
-import javax.sql.DataSource;
-import org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer;
+import org.apache.aries.jpa.eclipselink.adapter.EclipseLinkProviderService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -67,8 +56,8 @@ import org.slf4j.LoggerFactory;
* </ul>
*/
public class Activator implements BundleActivator, BundleListener {
- private static final String ECLIPSELINK_JPA_PROVIDER_BUNDLE_SYMBOLIC_NAME = "org.eclipse.persistence.jpa";
- private static final String ECLIPSELINK_JPA_PROVIDER_CLASS_NAME = "org.eclipse.persistence.jpa.PersistenceProvider";
+ public static final String ECLIPSELINK_JPA_PROVIDER_BUNDLE_SYMBOLIC_NAME = "org.eclipse.persistence.jpa";
+ public static final String ECLIPSELINK_JPA_PROVIDER_CLASS_NAME = "org.eclipse.persistence.jpa.PersistenceProvider";
private final ConcurrentMap<Bundle, ServiceRegistration> registeredProviders = new ConcurrentHashMap<Bundle, ServiceRegistration>();
private static final Logger logger = LoggerFactory.getLogger(Activator.class);
@@ -76,144 +65,6 @@ public class Activator implements Bundle
private ServiceTracker tracker;
private BundleContext context;
- /**
- * Wrapper {@link PersistenceUnitInfo} object that adds the eclipselink.target-server setting (if not present)
- * and makes sure we can load {@link OSGiTSServer} from the unit's classloader.
- */
- private static class PersistenceUnitProxyWithTargetServer implements PersistenceUnitInfo {
- private final PersistenceUnitInfo delegate;
-
- public PersistenceUnitProxyWithTargetServer(PersistenceUnitInfo info) {
- delegate = info;
- }
-
- public void addTransformer(ClassTransformer arg0) {
- delegate.addTransformer(arg0);
- }
-
- public boolean excludeUnlistedClasses() {
- return delegate.excludeUnlistedClasses();
- }
-
- public ClassLoader getClassLoader() {
- ClassLoader unionClassLoader = new ClassLoader(delegate.getClassLoader()) {
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- return Activator.class.getClassLoader().loadClass(name);
- }
- };
-
- return unionClassLoader;
- }
-
- public List<URL> getJarFileUrls() {
- return delegate.getJarFileUrls();
- }
-
- public DataSource getJtaDataSource() {
- return delegate.getJtaDataSource();
- }
-
- public List<String> getManagedClassNames() {
- return delegate.getManagedClassNames();
- }
-
- public List<String> getMappingFileNames() {
- return delegate.getMappingFileNames();
- }
-
- public ClassLoader getNewTempClassLoader() {
- return delegate.getNewTempClassLoader();
- }
-
- public DataSource getNonJtaDataSource() {
- return delegate.getNonJtaDataSource();
- }
-
- public String getPersistenceProviderClassName() {
- return delegate.getPersistenceProviderClassName();
- }
-
- public String getPersistenceUnitName() {
- return delegate.getPersistenceUnitName();
- }
-
- public URL getPersistenceUnitRootUrl() {
- return delegate.getPersistenceUnitRootUrl();
- }
-
- public String getPersistenceXMLSchemaVersion() {
- return delegate.getPersistenceXMLSchemaVersion();
- }
-
- public Properties getProperties() {
- Properties props = delegate.getProperties();
-
- if (props == null) {
- props = new Properties();
- }
-
- if (!!!props.containsKey("eclipselink.target-server")) {
- props.put("eclipselink.target-server", OSGiTSServer.class.getName());
- }
-
- return props;
- }
-
- public SharedCacheMode getSharedCacheMode() {
- return delegate.getSharedCacheMode();
- }
-
- public PersistenceUnitTransactionType getTransactionType() {
- return delegate.getTransactionType();
- }
-
- public ValidationMode getValidationMode() {
- return delegate.getValidationMode();
- }
- }
-
- /**
- * Service factory for generating the Eclipselink OSGi compatible provider. It proxies the provider so that
- * we can go in at entity manager creation time and set the eclipselink target-server to be {@link OSGiTSServer}.
- */
- private static class EclipseLinkProviderService implements ServiceFactory {
- private final Bundle eclipseLinkJpaBundle;
-
- public EclipseLinkProviderService(Bundle b) {
- eclipseLinkJpaBundle = b;
- }
-
- public Object getService(Bundle bundle, ServiceRegistration registration) {
- logger.debug("Requested EclipseLink Provider service");
-
- try {
- Class<? extends PersistenceProvider> providerClass = eclipseLinkJpaBundle.loadClass(ECLIPSELINK_JPA_PROVIDER_CLASS_NAME);
- Constructor<? extends PersistenceProvider> con = providerClass.getConstructor();
- final PersistenceProvider provider = con.newInstance();
-
- return new PersistenceProvider() {
- public ProviderUtil getProviderUtil() {
- return provider.getProviderUtil();
- }
-
- public EntityManagerFactory createEntityManagerFactory(String arg0, Map arg1) {
- return provider.createEntityManagerFactory(arg0, arg1);
- }
-
- public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo punit, Map props) {
- return provider.createContainerEntityManagerFactory(new PersistenceUnitProxyWithTargetServer(punit), props);
- }
- };
-
- } catch (Exception e) {
- logger.error("Got exception trying to instantiate the EclipseLink provider", e);
- return null;
- }
- }
-
- public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {}
- }
-
public void start(BundleContext ctx) {
logger.debug("Starting EclipseLink adapter");
Added: aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkProviderService.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkProviderService.java?rev=1151218&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkProviderService.java (added)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkProviderService.java Tue Jul 26 19:35:49 2011
@@ -0,0 +1,80 @@
+/*
+// * 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 WARRANTIESOR 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.eclipselink.adapter;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.spi.PersistenceProvider;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.ProviderUtil;
+
+import org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Service factory for generating the Eclipselink OSGi compatible provider. It proxies the provider so that
+ * we can go in at entity manager creation time and set the eclipselink target-server to be {@link OSGiTSServer}.
+ */
+public class EclipseLinkProviderService implements ServiceFactory {
+ private static final Logger logger = LoggerFactory.getLogger(Activator.class);
+
+ private final Bundle eclipseLinkJpaBundle;
+
+ public EclipseLinkProviderService(Bundle b) {
+ eclipseLinkJpaBundle = b;
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ logger.debug("Requested EclipseLink Provider service");
+
+ try {
+ Class<? extends PersistenceProvider> providerClass = eclipseLinkJpaBundle.loadClass(Activator.ECLIPSELINK_JPA_PROVIDER_CLASS_NAME);
+ Constructor<? extends PersistenceProvider> con = providerClass.getConstructor();
+ final PersistenceProvider provider = con.newInstance();
+
+ return new PersistenceProvider() {
+ public ProviderUtil getProviderUtil() {
+ return provider.getProviderUtil();
+ }
+
+ public EntityManagerFactory createEntityManagerFactory(String arg0, Map arg1) {
+ return provider.createEntityManagerFactory(arg0, arg1);
+ }
+
+ public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo punit, Map props) {
+ return provider.createContainerEntityManagerFactory(new PersistenceUnitProxyWithTargetServer(punit,
+ eclipseLinkJpaBundle), props);
+ }
+ };
+
+ } catch (Exception e) {
+ logger.error("Got exception trying to instantiate the EclipseLink provider", e);
+ return null;
+ }
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {}
+}
\ No newline at end of file
Added: aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java?rev=1151218&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java (added)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java Tue Jul 26 19:35:49 2011
@@ -0,0 +1,129 @@
+/*
+// * 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 WARRANTIESOR 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.eclipselink.adapter;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+
+import javax.persistence.SharedCacheMode;
+import javax.persistence.ValidationMode;
+import javax.persistence.spi.ClassTransformer;
+import javax.persistence.spi.PersistenceUnitInfo;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.sql.DataSource;
+
+import org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * Wrapper {@link PersistenceUnitInfo} object that adds the eclipselink.target-server setting (if not present)
+ * and makes sure we can load {@link OSGiTSServer} from the unit's classloader.
+ */
+public class PersistenceUnitProxyWithTargetServer implements PersistenceUnitInfo {
+ private final PersistenceUnitInfo delegate;
+ private final ClassLoader unionClassLoader;
+
+ public PersistenceUnitProxyWithTargetServer(PersistenceUnitInfo info, Bundle b) {
+ delegate = info;
+ unionClassLoader = new UnionClassLoader(delegate.getClassLoader(), b,
+ FrameworkUtil.getBundle(getClass()));
+ }
+
+ public void addTransformer(ClassTransformer arg0) {
+ delegate.addTransformer(arg0);
+ }
+
+ public boolean excludeUnlistedClasses() {
+ return delegate.excludeUnlistedClasses();
+ }
+
+ public ClassLoader getClassLoader() {
+ return unionClassLoader;
+ }
+
+ public List<URL> getJarFileUrls() {
+ return delegate.getJarFileUrls();
+ }
+
+ public DataSource getJtaDataSource() {
+ return delegate.getJtaDataSource();
+ }
+
+ public List<String> getManagedClassNames() {
+ return delegate.getManagedClassNames();
+ }
+
+ public List<String> getMappingFileNames() {
+ return delegate.getMappingFileNames();
+ }
+
+ public ClassLoader getNewTempClassLoader() {
+ return delegate.getNewTempClassLoader();
+ }
+
+ public DataSource getNonJtaDataSource() {
+ return delegate.getNonJtaDataSource();
+ }
+
+ public String getPersistenceProviderClassName() {
+ return delegate.getPersistenceProviderClassName();
+ }
+
+ public String getPersistenceUnitName() {
+ return delegate.getPersistenceUnitName();
+ }
+
+ public URL getPersistenceUnitRootUrl() {
+ return delegate.getPersistenceUnitRootUrl();
+ }
+
+ public String getPersistenceXMLSchemaVersion() {
+ return delegate.getPersistenceXMLSchemaVersion();
+ }
+
+ public Properties getProperties() {
+ Properties props = delegate.getProperties();
+
+ if (props == null) {
+ props = new Properties();
+ }
+
+ if (!!!props.containsKey("eclipselink.target-server")) {
+ props.put("eclipselink.target-server",
+ "org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer");
+ }
+
+ return props;
+ }
+
+ public SharedCacheMode getSharedCacheMode() {
+ return delegate.getSharedCacheMode();
+ }
+
+ public PersistenceUnitTransactionType getTransactionType() {
+ return delegate.getTransactionType();
+ }
+
+ public ValidationMode getValidationMode() {
+ return delegate.getValidationMode();
+ }
+}
+
\ No newline at end of file
Added: aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java?rev=1151218&view=auto
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java (added)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java Tue Jul 26 19:35:49 2011
@@ -0,0 +1,66 @@
+/*
+// * 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 WARRANTIESOR 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.eclipselink.adapter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.aries.util.io.IOUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleReference;
+
+public final class UnionClassLoader extends ClassLoader implements BundleReference{
+
+ private final Bundle eclipseLinkBundle;
+ private final Bundle adaptorBundle;
+
+ public UnionClassLoader(ClassLoader parentLoader, Bundle b, Bundle adaptor) {
+ super(parentLoader);
+ this.eclipseLinkBundle = b;
+ this.adaptorBundle = adaptor;
+ }
+
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+
+ if("org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer".equals(name) ||
+ "org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSWrapper".equals(name)) {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ InputStream is = getClass().getClassLoader().getResourceAsStream(
+ name.replace('.', '/') + ".class");
+
+ if(is == null)
+ throw new ClassNotFoundException(name);
+
+
+ try {
+ IOUtils.copy(is, baos);
+ } catch (IOException ioe) {
+ throw new ClassNotFoundException(name, ioe);
+ }
+ return defineClass(name, baos.toByteArray(), 0, baos.size());
+ }
+ return eclipseLinkBundle.loadClass(name);
+ }
+
+ public Bundle getBundle() {
+ return adaptorBundle;
+ }
+}
\ No newline at end of file