aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1602134 - in /aries/trunk/jpa: jpa-container-advancedtestbundle/src/main/resources/META-INF/ jpa-container-itest/ jpa-container-itest/src/test/java/org/apache/aries/jpa/advanced/features/itest/ jpa-container-itest/src/test/java/org/apache/...
Date Thu, 12 Jun 2014 12:05:57 GMT
Author: cschneider
Date: Thu Jun 12 12:05:56 2014
New Revision: 1602134

URL: http://svn.apache.org/r1602134
Log:
ARIES-1208 Allow more flexible configuration of DataSourceFactory

Modified:
    aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/resources/META-INF/persistence.xml
    aries/trunk/jpa/jpa-container-itest/pom.xml
    aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/advanced/features/itest/OpenjpaWeavingAndAnnotationScanningTest.java
    aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerDataSourceFactoryTest.java
    aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
    aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DataSourceFactoryDataSource.java
    aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java

Modified: aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/resources/META-INF/persistence.xml?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/resources/META-INF/persistence.xml
(original)
+++ aries/trunk/jpa/jpa-container-advancedtestbundle/src/main/resources/META-INF/persistence.xml
Thu Jun 12 12:05:56 2014
@@ -27,7 +27,7 @@
     <properties>
       <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
-      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:TEST;create=true"/>
+      <property name="javax.persistence.jdbc.databaseName" value="memory:TEST;create=true"/>
       <property name="eclipselink.target-database" value="Derby"/>     
       <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
       <property name="eclipselink.ddl-generation.output-mode" value="database" />

Modified: aries/trunk/jpa/jpa-container-itest/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/pom.xml?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/pom.xml (original)
+++ aries/trunk/jpa/jpa-container-itest/pom.xml Thu Jun 12 12:05:56 2014
@@ -252,6 +252,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+    		<groupId>org.ops4j.pax.jdbc</groupId>
+    		<artifactId>pax-jdbc-derby</artifactId>
+		    <version>0.3.0</version>
+		</dependency>
+        <dependency>
             <groupId>org.apache.servicemix.bundles</groupId>
             <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
             <version>2.1_3_4</version>

Modified: aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/advanced/features/itest/OpenjpaWeavingAndAnnotationScanningTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/advanced/features/itest/OpenjpaWeavingAndAnnotationScanningTest.java?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/advanced/features/itest/OpenjpaWeavingAndAnnotationScanningTest.java
(original)
+++ aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/advanced/features/itest/OpenjpaWeavingAndAnnotationScanningTest.java
Thu Jun 12 12:05:56 2014
@@ -22,22 +22,21 @@ import java.util.Arrays;
 
 import org.apache.aries.jpa.container.advanced.itest.bundle.entities.Car;
 import org.apache.openjpa.enhance.PersistenceCapable;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 
 // TODO The Test persistence unit does not seem to be created. Reenable when this works 
-@Ignore
 public class OpenjpaWeavingAndAnnotationScanningTest extends JPAWeavingAndAnnotationScanningTest
{
 
 	@Configuration
 	public Option[] openjpaConfig() {
 		return options(
-				baseOptions(), 
+				baseOptions(),
+				openJpa(),
+				derbyDataSourceFactory(),
 				ariesJpa(),
 				transactionWrapper(),
-				openJpa(),
 
 				testBundleAdvanced()
 				);
@@ -45,6 +44,7 @@ public class OpenjpaWeavingAndAnnotation
 
 	@Test
 	public void testClassIsWoven() throws Exception {
+		showBundles();
 		getEMF(TEST_UNIT);
 		assertTrue("Not PersistenceCapable", Arrays.asList(Car.class.getInterfaces())
 				.contains(PersistenceCapable.class));

Modified: aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerDataSourceFactoryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerDataSourceFactoryTest.java?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerDataSourceFactoryTest.java
(original)
+++ aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/container/itest/JPAContainerDataSourceFactoryTest.java
Thu Jun 12 12:05:56 2014
@@ -19,49 +19,36 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNull;
 import static org.ops4j.pax.exam.CoreOptions.options;
 
-import java.sql.Driver;
-import java.sql.SQLException;
-import java.util.Hashtable;
-import java.util.Properties;
-
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
-import javax.sql.ConnectionPoolDataSource;
-import javax.sql.DataSource;
-import javax.sql.XADataSource;
 import javax.transaction.UserTransaction;
 
 import org.apache.aries.jpa.container.itest.entities.Car;
 import org.apache.aries.jpa.itest.AbstractJPAItest;
-import org.apache.derby.jdbc.EmbeddedDataSource;
-import org.apache.derby.jdbc.EmbeddedXADataSource;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.jdbc.DataSourceFactory;
 
 public class JPAContainerDataSourceFactoryTest extends AbstractJPAItest {
 	private static final String DSF_TEST_UNIT = "dsf-test-unit";
 	private static final String DSF_XA_TEST_UNIT = "dsf-xa-test-unit";
+	private static final String DERBY_DS_FACTORY_SYMBOLIC_NAME = "org.ops4j.pax.jdbc.derby";
 	
-	@SuppressWarnings("rawtypes")
-	private ServiceRegistration reg;
-
 	@Before
-	public void waitStartup() throws InvalidSyntaxException {
+	public void waitStartup() throws InvalidSyntaxException, BundleException {
 		getEMF(TEST_UNIT);
 		assertNull(getEMFRefs(DSF_TEST_UNIT));
 		assertNull(getEMFRefs(DSF_XA_TEST_UNIT));
-		reg = registerDataSourceFactory();
+		context().getBundleByName(DERBY_DS_FACTORY_SYMBOLIC_NAME).start();
 	}
 	
 	@After
-	public void shutDown() throws InvalidSyntaxException {
-		reg.unregister();
+	public void shutDown() throws InvalidSyntaxException, BundleException {
+		context().getBundleByName(DERBY_DS_FACTORY_SYMBOLIC_NAME).stop();
 		assertNull(getEMFRefs(DSF_TEST_UNIT));
 		assertNull(getEMFRefs(DSF_XA_TEST_UNIT));
 	}
@@ -110,44 +97,6 @@ public class JPAContainerDataSourceFacto
 		em.close();
 	}
 
-	private static class DerbyDataSourceFactory implements DataSourceFactory {
-
-		public DataSource createDataSource(Properties props)
-				throws SQLException {
-			EmbeddedDataSource ds = new EmbeddedDataSource();
-			ds.setDatabaseName("memory:TEST");
-			ds.setCreateDatabase("create");
-			return ds;
-		}
-
-		public ConnectionPoolDataSource createConnectionPoolDataSource(
-				Properties props) throws SQLException {
-			// TODO Auto-generated method stub
-			return null;
-		}
-
-		public XADataSource createXADataSource(Properties props)
-				throws SQLException {
-			EmbeddedXADataSource ds = new EmbeddedXADataSource();
-			ds.setDatabaseName("memory:TEST");
-			ds.setCreateDatabase("create");
-			return ds;
-		}
-
-		public Driver createDriver(Properties props) throws SQLException {
-			// TODO Auto-generated method stub
-			return null;
-		}
-
-	}
-
-	@SuppressWarnings({ "rawtypes", "unchecked" })
-	private ServiceRegistration registerDataSourceFactory() {
-		Hashtable<String, Object> props = new Hashtable();
-		props.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS,	"org.apache.derby.jdbc.EmbeddedDriver");
-		return context().registerService(DataSourceFactory.class.getName(), new DerbyDataSourceFactory(),
props);
-	}
-
 	private Car createCar() {
 		Car c = new Car();
 		c.setNumberPlate("123456");
@@ -174,6 +123,7 @@ public class JPAContainerDataSourceFacto
 				ariesJpa(),
 				transactionWrapper(),
 				openJpa(),
+				derbyDataSourceFactory().noStart(),
 				testBundle()
 				);
 	}

Modified: aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
(original)
+++ aries/trunk/jpa/jpa-container-itest/src/test/java/org/apache/aries/jpa/itest/AbstractJPAItest.java
Thu Jun 12 12:05:56 2014
@@ -168,6 +168,10 @@ public abstract class AbstractJPAItest e
 		return mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.testds").versionAsInProject();
 	}
 	
+	protected MavenArtifactProvisionOption derbyDataSourceFactory() {
+		return mavenBundle("org.ops4j.pax.jdbc", "pax-jdbc-derby").versionAsInProject();
+	}
+	
 	protected MavenArtifactProvisionOption testBundle() {
 		return mavenBundle("org.apache.aries.jpa", "org.apache.aries.jpa.container.itest.bundle").versionAsInProject();
 	}

Modified: aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml (original)
+++ aries/trunk/jpa/jpa-container-testbundle/src/main/resources/META-INF/persistence.xml Thu
Jun 12 12:05:56 2014
@@ -69,7 +69,7 @@
      <!-- These properties are creating the database on the fly. We are using them to
avoid the tests having
           to create a database  -->
       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
-      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:TEST;create=true"/>
+      <property name="javax.persistence.jdbc.databaseName" value="memory:TEST;create=true"/>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
      <property name="openjpa.jdbc.DBDictionary" value="derby"/>
     </properties>
@@ -83,7 +83,7 @@
      <!-- These properties are creating the database on the fly. We are using them to
avoid the tests having
           to create a database  -->
       <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
-      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:TEST;create=true"/>
+      <property name="javax.persistence.jdbc.databaseName" value="memory:TEST;create=true"/>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
      <property name="openjpa.jdbc.DBDictionary" value="derby"/>
     </properties>

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/impl/PersistenceBundleManager.java
Thu Jun 12 12:05:56 2014
@@ -65,6 +65,8 @@ import org.slf4j.LoggerFactory;
 
 /**
  * This class locates, parses and manages persistence units defined in OSGi bundles.
+ * It also keeps track of PersistenceProvider services and delegates the EMF creation to
the 
+ * matching PersistenceProvider
  */
 public class PersistenceBundleManager implements BundleTrackerCustomizer, ServiceTrackerCustomizer,
BundleActivator
 {

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DataSourceFactoryDataSource.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DataSourceFactoryDataSource.java?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DataSourceFactoryDataSource.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/DataSourceFactoryDataSource.java
Thu Jun 12 12:05:56 2014
@@ -49,18 +49,10 @@ public class DataSourceFactoryDataSource
   private final AtomicReference<SingleServiceTracker<DataSourceFactory>> trackerRef
=
     new AtomicReference<SingleServiceTracker<DataSourceFactory>>();
   
-  public DataSourceFactoryDataSource(Bundle bundle, String driverName, String dbURL, 
-      String dbUserName, String dbPassword, boolean jta) {
+  public DataSourceFactoryDataSource(Bundle bundle, String driverName, Properties props,
boolean jta) {
     this.persistenceBundle = bundle;
     this.driverName = driverName;
-    props = new Properties();
-    if(dbURL != null)
-      props.setProperty(DataSourceFactory.JDBC_URL, dbURL);
-    if(dbUserName != null)
-      props.setProperty(DataSourceFactory.JDBC_USER, dbUserName);
-    if(dbPassword != null)
-      props.setProperty(DataSourceFactory.JDBC_PASSWORD, dbPassword);
-    
+    this.props = props;
     this.jta = jta;
   }
 

Modified: aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java?rev=1602134&r1=1602133&r2=1602134&view=diff
==============================================================================
--- aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
(original)
+++ aries/trunk/jpa/jpa-container/src/main/java/org/apache/aries/jpa/container/unit/impl/PersistenceUnitInfoImpl.java
Thu Jun 12 12:05:56 2014
@@ -68,6 +68,7 @@ public class PersistenceUnitInfoImpl imp
   
   /** Logger */
   private static final Logger _logger = LoggerFactory.getLogger("org.apache.aries.jpa.container");
+  private static final String JDBC_PREFIX = "javax.persistence.jdbc.";
   
   public PersistenceUnitInfoImpl (Bundle b, ParsedPersistenceUnit parsedData, 
       final ServiceReference providerRef, Boolean globalUsedatasourcefactory)
@@ -141,11 +142,8 @@ public class PersistenceUnitInfoImpl imp
             _logger.debug(NLS.MESSAGES.getMessage("using.datasource.factory", getPersistenceUnitName(),
                 bundle.getSymbolicName(), bundle.getVersion()));
           
-          jtaDSFDS.compareAndSet(null, new DataSourceFactoryDataSource(bundle, driverName,
-              props.getProperty("javax.persistence.jdbc.url"), 
-              props.getProperty("javax.persistence.jdbc.user"), 
-              props.getProperty("javax.persistence.jdbc.password"),
-              getTransactionType() == PersistenceUnitTransactionType.JTA));
+          boolean jta = getTransactionType() == PersistenceUnitTransactionType.JTA;
+          jtaDSFDS.compareAndSet(null, new DataSourceFactoryDataSource(bundle, driverName,
getDsProps(props), jta)); 
           toReturn = jtaDSFDS.get();
         }
       }
@@ -153,6 +151,7 @@ public class PersistenceUnitInfoImpl imp
     return toReturn;
   }
 
+
   @SuppressWarnings("unchecked")
   public List<String> getManagedClassNames() {
     List<String> classes = (List<String>) unit.getPersistenceXmlMetadata().get(ParsedPersistenceUnit.MANAGED_CLASSES);
@@ -197,11 +196,7 @@ public class PersistenceUnitInfoImpl imp
             _logger.debug(NLS.MESSAGES.getMessage("using.datasource.factory", getPersistenceUnitName(),
                 bundle.getSymbolicName(), bundle.getVersion()));
           
-          nonJtaDSFDS.compareAndSet(null, new DataSourceFactoryDataSource(bundle, driverName,
-              props.getProperty("javax.persistence.jdbc.url"), 
-              props.getProperty("javax.persistence.jdbc.user"), 
-              props.getProperty("javax.persistence.jdbc.password"),
-              false));
+          nonJtaDSFDS.compareAndSet(null, new DataSourceFactoryDataSource(bundle, driverName,
getDsProps(props), false));
           toReturn = nonJtaDSFDS.get();
         }
       }
@@ -291,4 +286,22 @@ public class PersistenceUnitInfoImpl imp
     }
   }
   
+  /**
+   * Return all properties that start with the prefix JDBC_PREFIX and cut off that prefix.
+   * 
+   * @param props
+   * @return
+   */
+  private Properties getDsProps(Properties props) {
+	  Properties dsProps = new Properties();
+	  for (Object keyO : props.keySet()) {
+		  String key = (String)keyO;
+		  if (key.startsWith(JDBC_PREFIX) && !key.equals(JDBC_PREFIX + "driver")) {
+			  dsProps.put(key.substring(JDBC_PREFIX.length()), props.get(key));
+		  }
+	  }
+	  return dsProps;
+  }
+
+  
 }
\ No newline at end of file



Mime
View raw message