Skip to content

Commit

Permalink
Extending PersistenceUtil to handle differently named datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Rietveld committed Mar 16, 2012
1 parent ed04ab3 commit 4bd3b3f
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,23 @@ public class PersistenceUtil {
public static String DATASOURCE = "org.droolsjbpm.persistence.datasource";

/**
* @see #setupWithPoolingDataSource(String, boolean)
* @see #setupWithPoolingDataSource(String, String, boolean)
* @param persistenceUnitName The name of the persistence unit to be used.
* @return test context
*/
public static HashMap<String, Object> setupWithPoolingDataSource(String persistenceUnitName) {
return setupWithPoolingDataSource(persistenceUnitName, true);
}

/**
* @see #setupWithPoolingDataSource(String, String, boolean)
* @param persistenceUnitName The name of the persistence unit to be used.
* @return test context
*/
public static HashMap<String, Object> setupWithPoolingDataSource(String persistenceUnitName, boolean testMarshalling) {
return setupWithPoolingDataSource(persistenceUnitName, "jdbc/testDS1", true);
}

/**
* This method does all of the setup for the test and returns a HashMap
* containing the persistence objects that the test might need.
Expand All @@ -88,7 +97,7 @@ public static HashMap<String, Object> setupWithPoolingDataSource(String persiste
* @return HashMap<String Object> with persistence objects, such as the
* EntityManagerFactory and DataSource
*/
public static HashMap<String, Object> setupWithPoolingDataSource(final String persistenceUnitName, final boolean testMarshalling) {
public static HashMap<String, Object> setupWithPoolingDataSource(final String persistenceUnitName, String dataSourceName, final boolean testMarshalling) {
HashMap<String, Object> context = new HashMap<String, Object>();

// set the right jdbc url
Expand Down Expand Up @@ -128,7 +137,7 @@ public static HashMap<String, Object> setupWithPoolingDataSource(final String pe
}

// Setup the datasource
PoolingDataSource ds1 = setupPoolingDataSource(dsProps);
PoolingDataSource ds1 = setupPoolingDataSource(dsProps, dataSourceName);
if( driverClass.startsWith("org.h2") ) {
if( ! TEST_MARSHALLING ) {
jdbcUrl += "tcp://localhost/JPADroolsFlow";
Expand Down Expand Up @@ -207,16 +216,25 @@ public static void cleanUp(HashMap<String, Object> context) {

}

/**
* This method uses the "jdbc/testDS1" datasource, which is the default.
* @param dsProps The properties used to setup the data source.
* @return a PoolingDataSource
*/
public static PoolingDataSource setupPoolingDataSource(Properties dsProps) {
return setupPoolingDataSource(dsProps, "jdbc/testDS1");
}

/**
* This sets up a Bitronix PoolingDataSource.
*
* @return PoolingDataSource that has been set up but _not_ initialized.
*/
public static PoolingDataSource setupPoolingDataSource(Properties dsProps) {
public static PoolingDataSource setupPoolingDataSource(Properties dsProps, String datasourceName) {
PoolingDataSource pds = new PoolingDataSource();

// The name must match what's in the persistence.xml!
pds.setUniqueName("jdbc/testDS1");
pds.setUniqueName(datasourceName);

pds.setClassName(dsProps.getProperty("className"));

Expand Down

0 comments on commit 4bd3b3f

Please sign in to comment.