Search in sources :

Example 16 with PoolingDataSource

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

the class JbpmJUnitTestCase method setupPoolingDataSource.

public static PoolingDataSource setupPoolingDataSource() {
    PoolingDataSource pds = new PoolingDataSource();
    pds.setUniqueName("jdbc/jbpm-ds");
    pds.setClassName("org.h2.jdbcx.JdbcDataSource");
    pds.getDriverProperties().put("user", "sa");
    pds.getDriverProperties().put("password", "");
    pds.getDriverProperties().put("url", "jdbc:h2:tcp://localhost/~/jbpm-db;MVCC=true");
    pds.getDriverProperties().put("driverClassName", "org.h2.Driver");
    pds.init();
    return pds;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource)

Example 17 with PoolingDataSource

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

the class ParallelAsyncJobsTest method setupPoolingDataSource.

@Override
protected PoolingDataSource setupPoolingDataSource() {
    Properties dsProps = PersistenceUtil.getDatasourceProperties();
    String jdbcUrl = dsProps.getProperty("url");
    String driverClass = dsProps.getProperty("driverClassName");
    // Setup the datasource
    PoolingDataSource ds1 = PersistenceUtil.setupPoolingDataSource(dsProps, "jdbc/jbpm-ds", false);
    if (driverClass.startsWith("org.h2")) {
        ds1.getDriverProperties().setProperty("url", jdbcUrl);
    }
    ds1.getDriverProperties().setProperty("POOL_CONNECTIONS", "false");
    ds1.init();
    return ds1;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource) Properties(java.util.Properties)

Example 18 with PoolingDataSource

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

the class DBUserGroupCallbackImplTest method setup.

@Before
public void setup() {
    Properties dsProps = loadDataSourceProperties();
    pds = new PoolingDataSource();
    pds.setUniqueName("jdbc/jbpm-ds");
    pds.setClassName(dsProps.getProperty("className"));
    for (String propertyName : new String[] { "user", "password" }) {
        pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName));
    }
    setDatabaseSpecificDataSourceProperties(pds, dsProps);
    pds.init();
    prepareDb();
    props = new Properties();
    props.setProperty(DBUserGroupCallbackImpl.DS_JNDI_NAME, "jdbc/jbpm-ds");
    props.setProperty(DBUserGroupCallbackImpl.PRINCIPAL_QUERY, "select userId from Users where userId = ?");
    props.setProperty(DBUserGroupCallbackImpl.ROLES_QUERY, "select groupId from Groups where groupId = ?");
    props.setProperty(DBUserGroupCallbackImpl.USER_ROLES_QUERY, "select groupId from Groups where userId = ?");
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource) Properties(java.util.Properties) Before(org.junit.Before)

Example 19 with PoolingDataSource

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

the class PersistenceUtil method setupWithPoolingDataSource.

/**
 * This method does all of the setup for the test and returns a HashMap
 * containing the persistence objects that the test might need.
 *
 * @param persistenceUnitName
 *            The name of the persistence unit used by the test.
 * @return HashMap<String Object> with persistence objects, such as the
 *         EntityManagerFactory and DataSource
 */
public static HashMap<String, Object> setupWithPoolingDataSource(final String persistenceUnitName, String dataSourceName) {
    HashMap<String, Object> context = new HashMap<String, Object>();
    // set the right jdbc url
    Properties dsProps = getDatasourceProperties();
    String jdbcUrl = dsProps.getProperty("url");
    String driverClass = dsProps.getProperty("driverClassName");
    boolean startH2TcpServer = false;
    if (jdbcUrl.matches("jdbc:h2:tcp:.*")) {
        startH2TcpServer = true;
    }
    // Setup the datasource
    PoolingDataSource ds1 = setupPoolingDataSource(dsProps, dataSourceName, startH2TcpServer);
    if (driverClass.startsWith("org.h2")) {
        ds1.getDriverProperties().setProperty("url", jdbcUrl);
    }
    ds1.init();
    context.put(DATASOURCE, ds1);
    // Setup persistence
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);
    context.put(ENTITY_MANAGER_FACTORY, emf);
    return context;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource) HashMap(java.util.HashMap) EntityManagerFactory(javax.persistence.EntityManagerFactory) Properties(java.util.Properties)

Example 20 with PoolingDataSource

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

the class AsyncTaskTransactionTest method setupPoolingDataSource.

@Override
protected PoolingDataSource setupPoolingDataSource() {
    Properties dsProps = PersistenceUtil.getDatasourceProperties();
    String jdbcUrl = dsProps.getProperty("url");
    String driverClass = dsProps.getProperty("driverClassName");
    // Setup the datasource
    PoolingDataSource ds1 = PersistenceUtil.setupPoolingDataSource(dsProps, "jdbc/jbpm-ds", false);
    if (driverClass.startsWith("org.h2")) {
        ds1.getDriverProperties().setProperty("url", jdbcUrl);
    }
    ds1.getDriverProperties().setProperty("POOL_CONNECTIONS", "false");
    ds1.init();
    return ds1;
}
Also used : PoolingDataSource(org.jbpm.test.util.PoolingDataSource) Properties(java.util.Properties)

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