aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1738840 - in /aries/trunk/jpa: itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/ jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/
Date Tue, 12 Apr 2016 18:06:15 GMT
Author: timothyjward
Date: Tue Apr 12 18:06:15 2016
New Revision: 1738840

URL: http://svn.apache.org/viewvc?rev=1738840&view=rev
Log:
[ARIES-1530] Support plugins when using the EclipseLink adapter

Modified:
    aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/EclipseAdditionalTest.java
    aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkPersistenceProvider.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/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/EclipseAdditionalTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/EclipseAdditionalTest.java?rev=1738840&r1=1738839&r2=1738840&view=diff
==============================================================================
--- aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/EclipseAdditionalTest.java
(original)
+++ aries/trunk/jpa/itests/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/EclipseAdditionalTest.java
Tue Apr 12 18:06:15 2016
@@ -15,24 +15,35 @@
  */
 package org.apache.aries.jpa.container.itest;
 
+import static javax.persistence.spi.PersistenceUnitTransactionType.RESOURCE_LOCAL;
+import static org.junit.Assert.assertEquals;
 import static org.ops4j.pax.exam.CoreOptions.streamBundle;
+import static org.osgi.service.jdbc.DataSourceFactory.OSGI_JDBC_DRIVER_CLASS;
 
 import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
 
 import javax.persistence.EntityManagerFactory;
 
 import org.apache.aries.jpa.itest.AbstractJPAItest;
+import org.eclipse.persistence.config.SessionCustomizer;
+import org.eclipse.persistence.sessions.Session;
 import org.junit.Assert;
 import org.junit.Test;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
 import org.osgi.framework.Constants;
+import org.osgi.service.jdbc.DataSourceFactory;
 import org.osgi.service.jpa.EntityManagerFactoryBuilder;
 
 public class EclipseAdditionalTest extends AbstractJPAItest {
 
-    @Test
+	private static final String CUSTOMIZER_CALLED = "org.apache.aries.jpa.itest.eclipse.customizer";
+
+	@Test
     public void testContextCreationWithStartingBundle() throws Exception {
         getBundleByName("org.apache.aries.jpa.container.itest.bundle.eclipselink").start();
         getEMF("script-test-unit");
@@ -42,6 +53,30 @@ public class EclipseAdditionalTest exten
     public void testEntityManagerFactoryBuilderWithIncompletePersistenceUnit() throws Exception
{
         getService(EntityManagerFactoryBuilder.class, "(osgi.unit.name=incompleteTestUnit)",
1000);
     }
+
+    @Test
+    public void testEntityManagerFactoryBuilderWithIncompletePersistenceUnitAddPlugin() throws
Exception {
+    	EntityManagerFactoryBuilder builder = getService(EntityManagerFactoryBuilder.class,
"(osgi.unit.name=incompleteTestUnit)", 1000);
+    	
+    	DataSourceFactory dsf = getService(DataSourceFactory.class, 
+    			"(" + OSGI_JDBC_DRIVER_CLASS + "=org.apache.derby.jdbc.EmbeddedDriver)");
+       
+    	Properties jdbcProps = new Properties();
+    	jdbcProps.setProperty("url", "jdbc:derby:memory:DSFTEST;create=true");
+    	
+    	Map<String, Object> props = new HashMap<String, Object>();
+    	props.put("javax.persistence.nonJtaDataSource", dsf.createDataSource(jdbcProps));
+    	props.put("javax.persistence.transactionType", RESOURCE_LOCAL.name());
+    	
+    	props.put("org.apache.aries.jpa.eclipselink.plugin.types", SessionCustomizerImpl.class);
+    	props.put("eclipselink.session.customizer", SessionCustomizerImpl.class.getName());
+    	
+    	EntityManagerFactory emf = builder.createEntityManagerFactory(props);
+    	emf.createEntityManager();
+		assertEquals("invoked", emf
+    			.getProperties().get(CUSTOMIZER_CALLED));
+    	
+    }
     
     @Test(expected = IllegalStateException.class)
     public void testEntityManagerFactoryWithIncompletePersistenceUnit() throws Exception
{
@@ -64,7 +99,15 @@ public class EclipseAdditionalTest exten
             derbyDSF(), //
             testBundleEclipseLink().noStart(),//
             streamBundle(testBundle)
-        // debug()
+//         ,debug()
         };
     }
+
+	public static class SessionCustomizerImpl implements SessionCustomizer {
+	
+		@Override
+		public void customize(Session arg0) throws Exception {
+			arg0.setProperty(CUSTOMIZER_CALLED, "invoked");
+		}
+	}
 }

Modified: aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkPersistenceProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkPersistenceProvider.java?rev=1738840&r1=1738839&r2=1738840&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkPersistenceProvider.java
(original)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/EclipseLinkPersistenceProvider.java
Tue Apr 12 18:06:15 2016
@@ -27,7 +27,7 @@ import javax.persistence.spi.ProviderUti
 
 import org.osgi.framework.Bundle;
 
-@SuppressWarnings("rawtypes")
+@SuppressWarnings({"rawtypes", "unchecked"})
 final class EclipseLinkPersistenceProvider implements PersistenceProvider {
     private final PersistenceProvider delegate;
     private final Bundle eclipeLinkBundle;
@@ -47,14 +47,14 @@ final class EclipseLinkPersistenceProvid
         return delegate.createEntityManagerFactory(arg0, arg1);
     }
 
-    @Override
+	@Override
     public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo punit,
Map props) {
-        return delegate.createContainerEntityManagerFactory(new PersistenceUnitProxyWithTargetServer(punit,
eclipeLinkBundle), props);
+        return delegate.createContainerEntityManagerFactory(new PersistenceUnitProxyWithTargetServer(punit,
eclipeLinkBundle, props), props);
     }
 
     @Override
     public void generateSchema(PersistenceUnitInfo punit, Map arg1) {
-        delegate.generateSchema(new PersistenceUnitProxyWithTargetServer(punit, eclipeLinkBundle),
arg1);
+        delegate.generateSchema(new PersistenceUnitProxyWithTargetServer(punit, eclipeLinkBundle,
arg1), arg1);
     }
 
     @Override

Modified: 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=1738840&r1=1738839&r2=1738840&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java
(original)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/PersistenceUnitProxyWithTargetServer.java
Tue Apr 12 18:06:15 2016
@@ -20,6 +20,7 @@ package org.apache.aries.jpa.eclipselink
 
 import java.net.URL;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.persistence.SharedCacheMode;
@@ -41,10 +42,10 @@ public class PersistenceUnitProxyWithTar
   private final PersistenceUnitInfo delegate;
     private final ClassLoader unionClassLoader; 
     
-    public PersistenceUnitProxyWithTargetServer(PersistenceUnitInfo info, Bundle b) {
+    public PersistenceUnitProxyWithTargetServer(PersistenceUnitInfo info, Bundle b, Map<String,
Object> arg1) {
         delegate = info;
         unionClassLoader = new UnionClassLoader(delegate.getClassLoader(), b, 
-            FrameworkUtil.getBundle(getClass()));
+            FrameworkUtil.getBundle(getClass()), arg1);
     }
 
     @Override

Modified: 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=1738840&r1=1738839&r2=1738840&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java
(original)
+++ aries/trunk/jpa/jpa-container-eclipselink-adapter/src/main/java/org/apache/aries/jpa/eclipselink/adapter/UnionClassLoader.java
Tue Apr 12 18:06:15 2016
@@ -23,6 +23,9 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleReference;
@@ -35,15 +38,33 @@ public final class UnionClassLoader exte
     private static final Logger LOG = LoggerFactory.getLogger(UnionClassLoader.class);
     private final Bundle eclipseLinkBundle;
     private final Bundle adaptorBundle;
+    private final Map<String, Class<?>> registeredPlugins = new HashMap<String,
Class<?>>();
 
-    public UnionClassLoader(ClassLoader parentLoader, Bundle b, Bundle adaptor) {
+    public UnionClassLoader(ClassLoader parentLoader, Bundle b, Bundle adaptor, Map<String,
Object> arg1) {
         super(parentLoader);
         this.eclipseLinkBundle = b;
         this.adaptorBundle = adaptor;
+        
+        //Populate the plugins
+        
+        Object o = arg1 == null ? null : arg1.get("org.apache.aries.jpa.eclipselink.plugin.types");
+       
+        if(o instanceof Class) {
+        	Class<?> c = (Class<?>) o;
+        	registeredPlugins.put(c.getName(), c);
+        } else if (o instanceof Collection) {
+        	for(Object o2 : (Collection<?>) o) {
+        		Class<?> c = (Class<?>) o2;
+            	registeredPlugins.put(c.getName(), c);
+        	}
+        }
     }
 
     @Override
     protected Class<?> findClass(String name) throws ClassNotFoundException {
+    	if(registeredPlugins.containsKey(name)) {
+    		return registeredPlugins.get(name);
+    	}
         if ("org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSServer".equals(name)

             || "org.apache.aries.jpa.eclipselink.adapter.platform.OSGiTSWrapper".equals(name))
{
             return loadTempClass(name);



Mime
View raw message