Search in sources :

Example 1 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.

the class ForceCloseMybatisConnectionPoolTest method testForceCloseMybatisConnectionPoolFalse.

@Test
public void testForceCloseMybatisConnectionPoolFalse() {
    // given
    // that the process engine is configured with forceCloseMybatisConnectionPool = false
    ProcessEngineConfigurationImpl configurationImpl = new StandaloneInMemProcessEngineConfiguration().setJdbcUrl("jdbc:h2:mem:camunda-forceclose").setProcessEngineName("engine-forceclose").setForceCloseMybatisConnectionPool(false);
    ProcessEngine processEngine = configurationImpl.buildProcessEngine();
    PooledDataSource pooledDataSource = (PooledDataSource) configurationImpl.getDataSource();
    PoolState state = pooledDataSource.getPoolState();
    int idleConnections = state.getIdleConnectionCount();
    // then
    // if the process engine is closed
    processEngine.close();
    // the idle connections are not closed
    Assert.assertEquals(state.getIdleConnectionCount(), idleConnections);
    pooledDataSource.forceCloseAll();
    Assert.assertTrue(state.getIdleConnectionCount() == 0);
}
Also used : PoolState(org.apache.ibatis.datasource.pooled.PoolState) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) StandaloneInMemProcessEngineConfiguration(org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) Test(org.junit.Test)

Example 2 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.

the class DatabaseTableSchemaTest method testPerformDatabaseSchemaOperationCreateTwice.

public void testPerformDatabaseSchemaOperationCreateTwice() 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", "");
    Connection connection = pooledDataSource.getConnection();
    connection.createStatement().execute("drop schema if exists " + SCHEMA_NAME);
    connection.createStatement().execute("create schema " + SCHEMA_NAME);
    connection.close();
    ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK");
    config1.setDatabaseTablePrefix(SCHEMA_NAME + ".");
    config1.setDatabaseSchema(SCHEMA_NAME);
    config1.setDbMetricsReporterActivate(false);
    ProcessEngine engine1 = config1.buildProcessEngine();
    // create the tables for the first time
    connection = pooledDataSource.getConnection();
    connection.createStatement().execute("set schema " + SCHEMA_NAME);
    engine1.getManagementService().databaseSchemaUpgrade(connection, "", SCHEMA_NAME);
    connection.close();
    // create the tables for the second time; here we shouldn't crash since the
    // session should tell us that the tables are already present and
    // databaseSchemaUpdate is set to noop
    connection = pooledDataSource.getConnection();
    connection.createStatement().execute("set schema " + SCHEMA_NAME);
    engine1.getManagementService().databaseSchemaUpgrade(connection, "", SCHEMA_NAME);
    engine1.close();
}
Also used : Connection(java.sql.Connection) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 3 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.

the class DatabaseTableSchemaTest method testTablePresentWithSchemaAndPrefix.

public void testTablePresentWithSchemaAndPrefix() throws SQLException {
    PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000", "sa", "");
    Connection connection = pooledDataSource.getConnection();
    connection.createStatement().execute("drop schema if exists " + SCHEMA_NAME);
    connection.createStatement().execute("create schema " + SCHEMA_NAME);
    connection.createStatement().execute("create table " + SCHEMA_NAME + "." + PREFIX_NAME + "SOME_TABLE(id varchar(64));");
    connection.close();
    ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK");
    config1.setDatabaseTablePrefix(SCHEMA_NAME + "." + PREFIX_NAME);
    config1.setDatabaseSchema(SCHEMA_NAME);
    config1.setDbMetricsReporterActivate(false);
    ProcessEngine engine = config1.buildProcessEngine();
    CommandExecutor commandExecutor = config1.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            DbSqlSession sqlSession = commandContext.getSession(DbSqlSession.class);
            assertTrue(sqlSession.isTablePresent("SOME_TABLE"));
            return null;
        }
    });
    engine.close();
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) Connection(java.sql.Connection) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) DbSqlSession(org.camunda.bpm.engine.impl.db.sql.DbSqlSession)

Example 4 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project camunda-bpm-platform by camunda.

the class DbSchemaPrefixTestHelper method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    dataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000;MVCC=TRUE;", "sa", "");
    // create schema in the
    Connection connection = dataSource.getConnection();
    connection.createStatement().execute("drop schema if exists SCHEMA1");
    connection.createStatement().execute("create schema SCHEMA1");
    connection.close();
    ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration().setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(dataSource).setDbMetricsReporterActivate(false).setDatabaseSchemaUpdate(// disable auto create/drop schema
    "NO_CHECK");
    config1.setDatabaseTablePrefix("SCHEMA1.");
    ProcessEngine engine1 = config1.buildProcessEngine();
    // create the tables in SCHEMA1
    connection = dataSource.getConnection();
    connection.createStatement().execute("set schema SCHEMA1");
    engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
    connection.close();
    engine1.close();
}
Also used : Connection(java.sql.Connection) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 5 with PooledDataSource

use of org.apache.ibatis.datasource.pooled.PooledDataSource in project Activiti by Activiti.

the class DatabaseTablePrefixTest method testPerformDatabaseSchemaOperationCreate.

public void testPerformDatabaseSchemaOperationCreate() throws Exception {
    // both process engines will be using this datasource.
    PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:activiti-test;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 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl.createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource).setDatabaseSchemaUpdate(// disable auto create/drop schema
    "NO_CHECK");
    config1.setDatabaseTablePrefix("SCHEMA1.");
    config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
    ProcessEngine engine1 = config1.buildProcessEngine();
    ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl.createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource).setDatabaseSchemaUpdate(// disable auto create/drop schema
    "NO_CHECK");
    config2.setDatabaseTablePrefix("SCHEMA2.");
    config2.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
    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/activiti/engine/test/db/oneJobProcess.bpmn20.xml").deploy();
        assertThat(engine1.getRepositoryService().createDeploymentQuery().count()).isEqualTo(1);
        assertThat(engine2.getRepositoryService().createDeploymentQuery().count()).isEqualTo(0);
    } finally {
        engine1.close();
        engine2.close();
    }
}
Also used : Connection(java.sql.Connection) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) PooledDataSource(org.apache.ibatis.datasource.pooled.PooledDataSource) ProcessEngine(org.activiti.engine.ProcessEngine)

Aggregations

PooledDataSource (org.apache.ibatis.datasource.pooled.PooledDataSource)20 Connection (java.sql.Connection)11 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)7 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)7 DataSource (javax.sql.DataSource)5 BaseDataTest (org.apache.ibatis.BaseDataTest)4 JDBCConnection (org.hsqldb.jdbc.JDBCConnection)4 Test (org.junit.Test)4 Test (org.junit.jupiter.api.Test)4 Properties (java.util.Properties)3 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 PoolState (org.apache.ibatis.datasource.pooled.PoolState)2 Configuration (org.apache.ibatis.session.Configuration)2 StandaloneInMemProcessEngineConfiguration (org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1