Search in sources :

Example 1 with PoolingDataSource

use of org.jbpm.test.util.PoolingDataSource in project jbpm by kiegroup.

the class ExecutorTestUtil method setupPoolingDataSource.

public static PoolingDataSource setupPoolingDataSource() {
    Properties dsProps = getDatasourceProperties();
    PoolingDataSource pds = PersistenceUtil.setupPoolingDataSource(dsProps, "jdbc/jbpm-ds", false);
    pds.init();
    return pds;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource) Properties(java.util.Properties)

Example 2 with PoolingDataSource

use of org.jbpm.test.util.PoolingDataSource in project jbpm-work-items by kiegroup.

the class JPAWorkItemHandlerTest method setupPoolingDataSource.

public static PoolingDataSource setupPoolingDataSource() {
    h2Server = new TestH2Server();
    h2Server.start();
    PoolingDataSource pds = new PoolingDataSource();
    pds.setUniqueName("jpaWIH");
    pds.setClassName("org.h2.jdbcx.JdbcDataSource");
    pds.getDriverProperties().put("user", "sa");
    pds.getDriverProperties().put("url", "jdbc:h2:mem:jpa-wih;MVCC=true");
    pds.getDriverProperties().put("driverClassName", "org.h2.Driver");
    pds.init();
    return pds;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource)

Example 3 with PoolingDataSource

use of org.jbpm.test.util.PoolingDataSource in project jbpm by kiegroup.

the class AbstractCaseServicesBaseTest method buildDatasource.

protected void buildDatasource() {
    ds = new PoolingDataSource();
    ds.setUniqueName("jdbc/testDS1");
    // NON XA CONFIGS
    ds.setClassName("org.h2.jdbcx.JdbcDataSource");
    ds.getDriverProperties().put("user", "sa");
    ds.getDriverProperties().put("password", "sasa");
    ds.getDriverProperties().put("URL", "jdbc:h2:mem:mydb");
    ds.init();
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource)

Example 4 with PoolingDataSource

use of org.jbpm.test.util.PoolingDataSource in project jbpm by kiegroup.

the class PersistenceUtil method cleanUp.

/**
 * This method should be called in the @After method of a test to clean up
 * the persistence unit and datasource.
 *
 * @param context
 *            A HashMap generated by
 *            {@link org.drools.persistence.util.PersistenceUtil setupWithPoolingDataSource(String)}
 */
public static void cleanUp(Map<String, Object> context) {
    if (context != null) {
        Object emfObject = context.remove(ENTITY_MANAGER_FACTORY);
        if (emfObject != null) {
            try {
                EntityManagerFactory emf = (EntityManagerFactory) emfObject;
                emf.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
        Object ds1Object = context.remove(DATASOURCE);
        if (ds1Object != null) {
            try {
                PoolingDataSource ds1 = (PoolingDataSource) ds1Object;
                ds1.close();
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource) EntityManagerFactory(javax.persistence.EntityManagerFactory)

Example 5 with PoolingDataSource

use of org.jbpm.test.util.PoolingDataSource in project jbpm by kiegroup.

the class PersistenceUtil method setupPoolingDataSource.

/**
 * This sets up a PoolingDataSource.
 *
 * @return PoolingDataSource that has been set up but _not_ initialized.
 */
public static PoolingDataSource setupPoolingDataSource(Properties dsProps, String datasourceName, boolean startServer) {
    PoolingDataSource pds = new PoolingDataSource();
    // The name must match what's in the persistence.xml!
    pds.setUniqueName(datasourceName);
    pds.setClassName(dsProps.getProperty("className"));
    for (String propertyName : new String[] { "user", "password" }) {
        pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
    }
    String driverClass = dsProps.getProperty("driverClassName");
    if (driverClass.startsWith("org.h2") || driverClass.startsWith("org.hsqldb")) {
        if (startServer) {
            h2Server.start();
        }
    }
    setDatabaseSpecificDataSourceProperties(pds, dsProps);
    return pds;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource)

Aggregations

PoolingDataSource (org.jbpm.test.util.PoolingDataSource)22 Properties (java.util.Properties)12 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 Before (org.junit.Before)2 File (java.io.File)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1