List of usage examples for org.apache.ibatis.datasource.pooled PooledDataSource getConnection
@Override
public Connection getConnection() throws SQLException
From source file:org.activiti.engine.test.db.DatabaseTablePrefixTest.java
License:Apache License
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();// w ww .j av a 2 s . c o m // configure & build two different process engines, each having a separate table prefix ProcessEngineConfigurationImpl config1 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config2.setDatabaseTablePrefix("SCHEMA2."); 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(); // if I deploy a process to one engine, it is not visible to the other // engine: try { engine1.getRepositoryService().createDeployment() .addClasspathResource("org/activiti/engine/test/db/oneJobProcess.bpmn20.xml").deploy(); assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count()); assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count()); } finally { engine1.close(); engine2.close(); } }
From source file:org.activiti.upgrade.helper.UpgradeUtil.java
License:Apache License
public static ProcessEngine getProcessEngine(String configResource) { ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration .createProcessEngineConfigurationFromResource(configResource); // When the 'old version' tests are run, we drop the schema always once for the first test if (!DATABASE_DROPPED && isTestRunningAgainstOldVersion()) { synchronized (DATABASE_DROPPED) { if (!DATABASE_DROPPED) { LOG.info("JdbcDriver = " + processEngineConfiguration.getJdbcDriver()); LOG.info("JdbcURL = " + processEngineConfiguration.getJdbcUrl()); LOG.info("JdbcUser = " + processEngineConfiguration.getJdbcUsername()); LOG.info("JdbcPassword = " + processEngineConfiguration.getJdbcPassword()); PooledDataSource dataSource = new PooledDataSource(processEngineConfiguration.getJdbcDriver(), processEngineConfiguration.getJdbcUrl(), processEngineConfiguration.getJdbcUsername(), processEngineConfiguration.getJdbcPassword()); DatabaseConnection connection = null; Database database = null; try { connection = new JdbcConnection(dataSource.getConnection()); database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); Liquibase liquibase = new Liquibase((String) null, new ClassLoaderResourceAccessor(), database);// w w w . j a v a 2 s . c o m LOG.info("Dropping upgrade database..."); liquibase.dropAll(); } catch (Exception exception) { exception.printStackTrace(); if (connection != null) { try { connection.close(); } catch (DatabaseException e) { e.printStackTrace(); } } if (database != null) { try { database.close(); } catch (DatabaseException e) { e.printStackTrace(); } } } LOG.info("Dropping upgrade database completed"); DATABASE_DROPPED = true; } } } // Buidling the process engine will also recreate the schema (in that particular version) return processEngineConfiguration.buildProcessEngine(); }
From source file:org.activiti5.engine.test.db.DatabaseTablePrefixTest.java
License:Apache License
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();/* w w w . ja v a2s .c o m*/ // configure & build two different process engines, each having a separate table prefix ProcessEngineConfigurationImpl config1 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); config1.setActiviti5CompatibilityEnabled(true); config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config2.setDatabaseTablePrefix("SCHEMA2."); config2.setActiviti5CompatibilityEnabled(true); 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(); // if I deploy a process to one engine, it is not visible to the other engine: try { engine1.getRepositoryService().createDeployment() .addClasspathResource("org/activiti5/engine/test/db/oneJobProcess.bpmn20.xml") .deploymentProperty(DeploymentProperties.DEPLOY_AS_ACTIVITI5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count()); assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count()); } finally { engine1.close(); engine2.close(); } }
From source file:org.camunda.bpm.engine.test.api.cfg.DatabaseTablePrefixTest.java
License:Apache License
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: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();//from ww w . j a v a 2 s.c o m // configure & build two different process engines, each having a separate table prefix ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine2").setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config2.setDatabaseTablePrefix("SCHEMA2."); 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(); // if I deploy a process to one engine, it is not visible to the other // 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(); } }
From source file:org.camunda.bpm.engine.test.api.cfg.DatabaseTableSchemaTest.java
License:Apache License
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();/*from w w w . j av a 2s . c om*/ ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine1") // disable auto create/drop schema .setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK"); config1.setDatabaseTablePrefix(SCHEMA_NAME + "."); config1.setDatabaseSchema(SCHEMA_NAME); 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(); }
From source file:org.camunda.bpm.engine.test.api.cfg.DatabaseTableSchemaTest.java
License:Apache License
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()//from w w w . j a v a2 s . c o m .execute("create table " + SCHEMA_NAME + "." + PREFIX_NAME + "SOME_TABLE(id varchar(64));"); connection.close(); ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine1") // disable auto create/drop schema .setDataSource(pooledDataSource).setDatabaseSchemaUpdate("NO_CHECK"); config1.setDatabaseTablePrefix(SCHEMA_NAME + "." + PREFIX_NAME); config1.setDatabaseSchema(SCHEMA_NAME); 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(); }
From source file:org.camunda.bpm.engine.test.db.DatabaseTablePrefixTest.java
License:Apache License
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: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();/*from w ww.j a v a 2s.c o m*/ // configure & build two different process engines, each having a separate table prefix ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine2").setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config2.setDatabaseTablePrefix("SCHEMA2."); 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(); // if I deploy a process to one engine, it is not visible to the other // engine: try { engine1.getRepositoryService().createDeployment() .addClasspathResource("org/camunda/bpm/engine/test/db/oneJobProcess.bpmn20.xml").deploy(); assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count()); assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count()); } finally { engine1.close(); engine2.close(); } }
From source file:org.flowable.engine.test.db.DatabaseTablePrefixTest.java
License:Apache License
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();//w ww . ja v a2 s .c o m // configure & build two different process engines, each having a // separate table prefix ProcessEngineConfigurationImpl config1 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema 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(); // if I deploy a process to one engine, it is not visible to the other // engine: try { engine1.getRepositoryService().createDeployment() .addClasspathResource("org/flowable/engine/test/db/oneJobProcess.bpmn20.xml").deploy(); assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count()); assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count()); } finally { engine1.close(); engine2.close(); } }
From source file:org.flowable.upgrade.DbDropUtil.java
License:Apache License
public static boolean dropDatabaseTable(String jdbcDriver, String jdbcUrl, String jdbcUser, String jdbcPassword) {/*from w w w. j a v a 2 s . co m*/ LOGGER.info("JdbcDriver = " + jdbcDriver); LOGGER.info("JdbcURL = " + jdbcUrl); LOGGER.info("JdbcUser = " + jdbcPassword); PooledDataSource dataSource = new PooledDataSource(jdbcDriver, jdbcUrl, jdbcUser, jdbcPassword); DatabaseConnection connection = null; Database database = null; try { connection = new JdbcConnection(dataSource.getConnection()); database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); Liquibase liquibase = new Liquibase((String) null, new ClassLoaderResourceAccessor(), database); liquibase.dropAll(); } catch (Exception exception) { exception.printStackTrace(); if (connection != null) { try { connection.close(); } catch (DatabaseException e) { e.printStackTrace(); } } if (database != null) { try { database.close(); } catch (DatabaseException e) { e.printStackTrace(); } } } return true; }