use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.
the class DatabaseTablePrefixTest method shouldPerformDatabaseSchemaOperationCreate.
@Test
public void shouldPerformDatabaseSchemaOperationCreate() throws Exception {
// both process engines will be using this datasource.
PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");
// create two schemas is the database
Connection connection = pooledDataSource.getConnection();
connection.createStatement().execute("drop schema if exists SCHEMA1");
connection.createStatement().execute("drop schema if exists SCHEMA2");
connection.createStatement().execute("create schema SCHEMA1");
connection.createStatement().execute("create schema SCHEMA2");
connection.close();
// configure & build two different process engines, each having a separate table prefix
ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDbMetricsReporterActivate(false).setDatabaseSchemaUpdate(// disable auto create/drop schema
"NO_CHECK");
config1.setDatabaseTablePrefix("SCHEMA1.");
config1.setUseSharedSqlSessionFactory(true);
ProcessEngine engine1 = config1.buildProcessEngine();
ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine2").setDataSource(pooledDataSource).setDbMetricsReporterActivate(false).setDatabaseSchemaUpdate(// disable auto create/drop schema
"NO_CHECK");
config2.setDatabaseTablePrefix("SCHEMA2.");
config2.setUseSharedSqlSessionFactory(true);
ProcessEngine engine2 = config2.buildProcessEngine();
// create the tables in SCHEMA1
connection = pooledDataSource.getConnection();
connection.createStatement().execute("set schema SCHEMA1");
engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
connection.close();
// create the tables in SCHEMA2
connection = pooledDataSource.getConnection();
connection.createStatement().execute("set schema SCHEMA2");
engine2.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA2");
connection.close();
// engine:
try {
engine1.getRepositoryService().createDeployment().addClasspathResource("org/camunda/bpm/engine/test/api/cfg/oneJobProcess.bpmn20.xml").deploy();
assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count());
assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count());
} finally {
engine1.close();
engine2.close();
ProcessEngineConfigurationImpl.cachedSqlSessionFactory = null;
}
}
use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.
the class ForceCloseMybatisConnectionPoolTest method testForceCloseMybatisConnectionPoolTrue.
@Test
public void testForceCloseMybatisConnectionPoolTrue() {
// given
// that the process engine is configured with forceCloseMybatisConnectionPool = true
ProcessEngineConfigurationImpl configurationImpl = new StandaloneInMemProcessEngineConfiguration().setJdbcUrl("jdbc:h2:mem:camunda-forceclose").setProcessEngineName("engine-forceclose").setForceCloseMybatisConnectionPool(true);
ProcessEngine processEngine = configurationImpl.buildProcessEngine();
PooledDataSource pooledDataSource = (PooledDataSource) configurationImpl.getDataSource();
PoolState state = pooledDataSource.getPoolState();
// then
// if the process engine is closed
processEngine.close();
// the idle connections are closed
Assert.assertTrue(state.getIdleConnectionCount() == 0);
}
use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.
the class ConnectionPoolTest method testMyBatisConnectionPoolProperlyConfigured.
public void testMyBatisConnectionPoolProperlyConfigured() {
ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/camunda/bpm/engine/test/api/cfg/connection-pool.camunda.cfg.xml");
ProcessEngine engine = config.buildProcessEngine();
// Expected values
int maxActive = 25;
int maxIdle = 10;
int maxCheckoutTime = 30000;
int maxWaitTime = 25000;
Integer jdbcStatementTimeout = 300;
assertEquals(maxActive, config.getJdbcMaxActiveConnections());
assertEquals(maxIdle, config.getJdbcMaxIdleConnections());
assertEquals(maxCheckoutTime, config.getJdbcMaxCheckoutTime());
assertEquals(maxWaitTime, config.getJdbcMaxWaitTime());
assertEquals(jdbcStatementTimeout, config.getJdbcStatementTimeout());
// Verify that these properties are correctly set in the MyBatis datasource
Configuration sessionFactoryConfiguration = config.getDbSqlSessionFactory().getSqlSessionFactory().getConfiguration();
DataSource datasource = sessionFactoryConfiguration.getEnvironment().getDataSource();
assertTrue(datasource instanceof PooledDataSource);
PooledDataSource pooledDataSource = (PooledDataSource) datasource;
assertEquals(maxActive, pooledDataSource.getPoolMaximumActiveConnections());
assertEquals(maxIdle, pooledDataSource.getPoolMaximumIdleConnections());
assertEquals(maxCheckoutTime, pooledDataSource.getPoolMaximumCheckoutTime());
assertEquals(maxWaitTime, pooledDataSource.getPoolTimeToWait());
assertEquals(jdbcStatementTimeout, sessionFactoryConfiguration.getDefaultStatementTimeout());
engine.close();
}
use of org.apache.ibatis.datasource.pooled.PooledDataSource in project Activiti by Activiti.
the class ConnectionPoolTest method testMyBatisConnectionPoolProperlyConfigured.
public void testMyBatisConnectionPoolProperlyConfigured() {
ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/engine/test/db/connection-pool.activiti.cfg.xml");
config.buildProcessEngine();
// Expected values
int maxActive = 25;
int maxIdle = 10;
int maxCheckoutTime = 30000;
int maxWaitTime = 25000;
assertThat(config.getJdbcMaxActiveConnections()).isEqualTo(maxActive);
assertThat(config.getJdbcMaxIdleConnections()).isEqualTo(maxIdle);
assertThat(config.getJdbcMaxCheckoutTime()).isEqualTo(maxCheckoutTime);
assertThat(config.getJdbcMaxWaitTime()).isEqualTo(maxWaitTime);
// Verify that these properties are correctly set in the MyBatis
// datasource
DataSource datasource = config.getDbSqlSessionFactory().getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource();
assertThat(datasource).isInstanceOf(PooledDataSource.class);
PooledDataSource pooledDataSource = (PooledDataSource) datasource;
assertThat(pooledDataSource.getPoolMaximumActiveConnections()).isEqualTo(maxActive);
assertThat(pooledDataSource.getPoolMaximumIdleConnections()).isEqualTo(maxIdle);
assertThat(pooledDataSource.getPoolMaximumCheckoutTime()).isEqualTo(maxCheckoutTime);
assertThat(pooledDataSource.getPoolTimeToWait()).isEqualTo(maxWaitTime);
}
use of org.apache.ibatis.datasource.pooled.PooledDataSource in project tutorials by eugenp.
the class MyBatisUtil method buildqlSessionFactory.
public static SqlSessionFactory buildqlSessionFactory() {
DataSource dataSource = new PooledDataSource(DRIVER, URL, USERNAME, PASSWORD);
Environment environment = new Environment("Development", new JdbcTransactionFactory(), dataSource);
Configuration configuration = new Configuration(environment);
configuration.addMapper(PersonMapper.class);
configuration.addMapper(AddressMapper.class);
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory factory = builder.build(configuration);
return factory;
}
Aggregations