List of usage examples for org.apache.ibatis.datasource.pooled PooledDataSource PooledDataSource
public PooledDataSource(ClassLoader driverClassLoader, String driver, String url, String username,
String password)
From source file:com.raise.orgs.impl.cfg.ProcessEngineConfigurationImpl.java
License:Apache License
protected void initDataSource() { if (dataSource == null) { if (dataSourceJndiName != null) { try { dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName); } catch (Exception e) { throw new ActivitiException( "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e); }//from w w w .j a va 2s .co m } else if (jdbcUrl != null) { if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) { throw new ActivitiException( "DataSource or JDBC properties have to be specified in a process engine configuration"); } log.debug("initializing datasource to db: {}", jdbcUrl); PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword); if (jdbcMaxActiveConnections > 0) { pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections); } if (jdbcMaxIdleConnections > 0) { pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections); } if (jdbcMaxCheckoutTime > 0) { pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime); } if (jdbcMaxWaitTime > 0) { pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime); } if (jdbcPingEnabled == true) { pooledDataSource.setPoolPingEnabled(true); if (jdbcPingQuery != null) { pooledDataSource.setPoolPingQuery(jdbcPingQuery); } pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor); } if (jdbcDefaultTransactionIsolationLevel > 0) { pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel); } dataSource = pooledDataSource; } if (dataSource instanceof PooledDataSource) { // ACT-233: connection pool of Ibatis is not properely initialized if this is not called! ((PooledDataSource) dataSource).forceCloseAll(); } } if (databaseType == null) { initDatabaseType(); } }
From source file:org.activiti.crystalball.simulator.impl.cfg.SimulationEngineConfigurationImpl.java
License:Apache License
protected void initDataSource() { if (dataSource == null) { if (dataSourceJndiName != null) { try { dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName); } catch (Exception e) { throw new ActivitiException( "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e); }//ww w.j a va2 s .c o m } else if (jdbcUrl != null) { if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) { throw new ActivitiException( "DataSource or JDBC properties have to be specified in a process engine configuration"); } log.fine("initializing datasource to db: " + jdbcUrl); PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword); if (jdbcMaxActiveConnections > 0) { pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections); } if (jdbcMaxIdleConnections > 0) { pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections); } if (jdbcMaxCheckoutTime > 0) { pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime); } if (jdbcMaxWaitTime > 0) { pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime); } if (jdbcPingEnabled == true) { pooledDataSource.setPoolPingEnabled(true); if (jdbcPingQuery != null) { pooledDataSource.setPoolPingQuery(jdbcPingQuery); } pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor); } dataSource = pooledDataSource; } if (dataSource instanceof PooledDataSource) { // ACT-233: connection pool of Ibatis is not properely initialized if this is not called! ((PooledDataSource) dataSource).forceCloseAll(); } } if (databaseType == null) { initDatabaseType(); } }
From source file:org.activiti.engine.AbstractEngineConfiguration.java
License:Apache License
protected void initDataSource() { if (dataSource == null) { if (dataSourceJndiName != null) { try { dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName); } catch (Exception e) { throw new ActivitiException( "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e); }//from w w w.j a va 2s .c o m } else if (jdbcUrl != null) { if ((jdbcDriver == null) || (jdbcUsername == null)) { throw new ActivitiException( "DataSource or JDBC properties have to be specified in a process engine configuration"); } logger.debug("initializing datasource to db: {}", jdbcUrl); if (logger.isInfoEnabled()) { logger.info("Configuring Datasource with following properties (omitted password for security)"); logger.info("datasource driver: " + jdbcDriver); logger.info("datasource url : " + jdbcUrl); logger.info("datasource user name : " + jdbcUsername); } PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword); if (jdbcMaxActiveConnections > 0) { pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections); } if (jdbcMaxIdleConnections > 0) { pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections); } if (jdbcMaxCheckoutTime > 0) { pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime); } if (jdbcMaxWaitTime > 0) { pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime); } if (jdbcPingEnabled == true) { pooledDataSource.setPoolPingEnabled(true); if (jdbcPingQuery != null) { pooledDataSource.setPoolPingQuery(jdbcPingQuery); } pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor); } if (jdbcDefaultTransactionIsolationLevel > 0) { pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel); } dataSource = pooledDataSource; } if (dataSource instanceof PooledDataSource) { // ACT-233: connection pool of Ibatis is not properly // initialized if this is not called! ((PooledDataSource) dataSource).forceCloseAll(); } } if (databaseType == null) { initDatabaseType(); } }
From source file:org.activiti.engine.impl.persistence.db.DbSqlSessionFactory.java
License:Apache License
public void configurationCompleted(ProcessEngineConfiguration processEngineConfiguration) { this.databaseName = processEngineConfiguration.getDatabaseName(); this.idGenerator = processEngineConfiguration.getIdGenerator(); this.statementMappings = databaseSpecificStatements.get(processEngineConfiguration.getDatabaseName()); DataSource dataSource = processEngineConfiguration.getDataSource(); if (dataSource == null) { String jdbcDriver = processEngineConfiguration.getJdbcDriver(); String jdbcUrl = processEngineConfiguration.getJdbcUrl(); String jdbcUsername = processEngineConfiguration.getJdbcUsername(); String jdbcPassword = processEngineConfiguration.getJdbcPassword(); if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) { throw new ActivitiException( "DataSource or JDBC properties have to be specified in a process engine configuration"); }//from w w w.ja va 2 s. c om dataSource = new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword); } TransactionFactory transactionFactory = null; if (processEngineConfiguration.isLocalTransactions()) { transactionFactory = new JdbcTransactionFactory(); } else { transactionFactory = new ManagedTransactionFactory(); } this.sqlSessionFactory = createSessionFactory(dataSource, transactionFactory); }
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();/*from w ww . j av 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."); 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.impl.persistence.IbatisPersistenceSessionFactory.java
License:Apache License
public IbatisPersistenceSessionFactory(VariableTypes variableTypes, IdGenerator idGenerator, String databaseName, String jdbcDriver, String jdbcUrl, String jdbcUsername, String jdbcPassword) { this(variableTypes, idGenerator, databaseName, new PooledDataSource(Thread.currentThread().getContextClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword), true);//from www . j ava 2 s. c o m }
From source file:org.activiti.MybatisMultiTenantDatasourceConfiguration.java
License:Apache License
public DataSource getDataSource() { logger.info("Creating datasource for tenant " + tenantId + " at jdbc url " + jdbcUrl); DataSource dataSource = null; if (jdbcUrl != null) { if ((jdbcDriver == null) || (jdbcUsername == null)) { throw new ActivitiException( "DataSource or JDBC properties have to be specified in a process engine configuration"); }/*w w w. j a v a 2 s.c om*/ PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword); if (jdbcMaxActiveConnections > 0) { pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections); } if (jdbcMaxIdleConnections > 0) { pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections); } if (jdbcMaxCheckoutTime > 0) { pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime); } if (jdbcMaxWaitTime > 0) { pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime); } if (jdbcPingEnabled == true) { pooledDataSource.setPoolPingEnabled(true); if (jdbcPingQuery != null) { pooledDataSource.setPoolPingQuery(jdbcPingQuery); } pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor); } if (jdbcDefaultTransactionIsolationLevel > 0) { pooledDataSource.setDefaultTransactionIsolationLevel(jdbcDefaultTransactionIsolationLevel); } dataSource = pooledDataSource; } if (dataSource instanceof PooledDataSource) { // ACT-233: connection pool of Ibatis is not properly // initialized if this is not called! ((PooledDataSource) dataSource).forceCloseAll(); } return dataSource; }
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();/*from ww w . j av a2 s . co 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.cockpit.plugin.base.util.DbSchemaPrefixTestHelper.java
License:Apache License
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();// w w w . j ava 2s.c om ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration() .setProcessEngineName("DatabaseTablePrefixTest-engine1").setDataSource(dataSource) .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(); }
From source file:org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.java
License:Apache License
protected void initDataSource() { if (dataSource == null) { if (dataSourceJndiName != null) { try { dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName); } catch (Exception e) { throw new ProcessEngineException( "couldn't lookup datasource from " + dataSourceJndiName + ": " + e.getMessage(), e); }//from www . j a v a2 s.c om } else if (jdbcUrl != null) { if ((jdbcDriver == null) || (jdbcUrl == null) || (jdbcUsername == null)) { throw new ProcessEngineException( "DataSource or JDBC properties have to be specified in a process engine configuration"); } PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword); if (jdbcMaxActiveConnections > 0) { pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections); } if (jdbcMaxIdleConnections > 0) { pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections); } if (jdbcMaxCheckoutTime > 0) { pooledDataSource.setPoolMaximumCheckoutTime(jdbcMaxCheckoutTime); } if (jdbcMaxWaitTime > 0) { pooledDataSource.setPoolTimeToWait(jdbcMaxWaitTime); } if (jdbcPingEnabled == true) { pooledDataSource.setPoolPingEnabled(true); if (jdbcPingQuery != null) { pooledDataSource.setPoolPingQuery(jdbcPingQuery); } pooledDataSource.setPoolPingConnectionsNotUsedFor(jdbcPingConnectionNotUsedFor); } dataSource = pooledDataSource; } if (dataSource instanceof PooledDataSource) { // ACT-233: connection pool of Ibatis is not properely initialized if this is not called! ((PooledDataSource) dataSource).forceCloseAll(); } } if (databaseType == null) { initDatabaseType(); } }