Java Code Examples for org.apache.ibatis.datasource.pooled.PooledDataSource#getConnection()
The following examples show how to use
org.apache.ibatis.datasource.pooled.PooledDataSource#getConnection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PooledDataSourceTest.java From mybaties with Apache License 2.0 | 6 votes |
@Test public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); Connection c = ds.getConnection(); c.close(); c.toString(); }
Example 2
Source File: PooledDataSourceTest.java From mybatis with Apache License 2.0 | 6 votes |
@Test public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); Connection c = ds.getConnection(); c.close(); c.toString(); }
Example 3
Source File: DatabaseTablePrefixTest.java From flowable-engine with Apache License 2.0 | 5 votes |
protected DataSource createDataSourceAndSchema() throws SQLException { // both process engines will be using this datasource. PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), "org.h2.Driver", "jdbc:h2:mem:flowable-db-table-prefix-test;DB_CLOSE_DELAY=1000", "sa", ""); // create two schemas is the database Connection connection = pooledDataSource.getConnection(); connection.createStatement().execute("drop schema if exists SCHEMA1 cascade"); connection.createStatement().execute("drop schema if exists SCHEMA2 cascade"); connection.createStatement().execute("create schema SCHEMA1"); connection.createStatement().execute("create schema SCHEMA2"); connection.close(); return pooledDataSource; }
Example 4
Source File: ScriptRunnerTest.java From mybaties with Apache License 2.0 | 5 votes |
private void assertProductsTableExistsAndLoaded() throws IOException, SQLException { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); try { Connection conn = ds.getConnection(); SqlRunner executor = new SqlRunner(conn); List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT"); assertEquals(16, products.size()); } finally { ds.forceCloseAll(); } }
Example 5
Source File: ScriptRunnerTest.java From mybatis with Apache License 2.0 | 5 votes |
private void assertProductsTableExistsAndLoaded() throws IOException, SQLException { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); try { Connection conn = ds.getConnection(); SqlRunner executor = new SqlRunner(conn); List<Map<String, Object>> products = executor.selectAll("SELECT * FROM PRODUCT"); assertEquals(16, products.size()); } finally { ds.forceCloseAll(); } }
Example 6
Source File: DatabaseTableSchemaTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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") // disable auto create/drop schema .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(); }
Example 7
Source File: DatabaseTableSchemaTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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") // disable auto create/drop schema .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(); }
Example 8
Source File: DbSchemaPrefixTestHelper.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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("NO_CHECK"); // disable auto create/drop schema 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(); }
Example 9
Source File: DatabaseTablePrefixTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
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("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/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(); } }
Example 10
Source File: DatabaseTablePrefixTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
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("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(); } }
Example 11
Source File: DatabaseTablePrefixTest.java From flowable-engine with Apache License 2.0 | 4 votes |
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("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); config1.setFlowable5CompatibilityEnabled(true); config1.setValidateFlowable5EntitiesEnabled(false); config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false); config1.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false); config1.setEventRegistryConfigurator(new CustomEventRegistryEngineConfigurator()); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl .createStandaloneInMemProcessEngineConfiguration() .setDataSource(pooledDataSource) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema config2.setDatabaseTablePrefix("SCHEMA2."); config2.setFlowable5CompatibilityEnabled(true); config2.setValidateFlowable5EntitiesEnabled(false); config2.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false); config2.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false); config2.setEventRegistryConfigurator(new CustomEventRegistryEngineConfigurator()); 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") .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .deploy(); assertEquals(1, engine1.getRepositoryService().createDeploymentQuery().count()); assertEquals(0, engine2.getRepositoryService().createDeploymentQuery().count()); } finally { engine1.close(); engine2.close(); } }
Example 12
Source File: PooledDataSourceTest.java From mybaties with Apache License 2.0 | 4 votes |
@Test public void ShouldReturnRealConnection() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); Connection c = ds.getConnection(); JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c); }
Example 13
Source File: PooledDataSourceTest.java From mybatis with Apache License 2.0 | 4 votes |
@Test public void ShouldReturnRealConnection() throws Exception { PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES); Connection c = ds.getConnection(); JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c); }
Example 14
Source File: DatabaseTablePrefixTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@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("NO_CHECK"); // disable auto create/drop schema config1.setDatabaseTablePrefix("SCHEMA1."); config1.setUseSharedSqlSessionFactory(true); ProcessEngine engine1 = config1.buildProcessEngine(); ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine2") .setDataSource(pooledDataSource) .setDbMetricsReporterActivate(false) .setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema 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(); // 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(); ProcessEngineConfigurationImpl.cachedSqlSessionFactory = null; } }