本文整理汇总了Java中org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection方法的典型用法代码示例。如果您正苦于以下问题:Java PooledDataSource.getConnection方法的具体用法?Java PooledDataSource.getConnection怎么用?Java PooledDataSource.getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ibatis.datasource.pooled.PooledDataSource
的用法示例。
在下文中一共展示了PooledDataSource.getConnection方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldNotFailCallingToStringOverAnInvalidConnection
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Test
public void shouldNotFailCallingToStringOverAnInvalidConnection() throws Exception {
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
Connection c = ds.getConnection();
c.close();
c.toString();
}
示例2: assertProductsTableExistsAndLoaded
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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();
}
}
示例3: testPerformDatabaseSchemaOperationCreateTwice
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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();
}
示例4: testTablePresentWithSchemaAndPrefix
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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();
}
示例5: afterPropertiesSet
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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();
}
示例6: ShouldReturnRealConnection
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Test
public void ShouldReturnRealConnection() throws Exception {
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
Connection c = ds.getConnection();
JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c);
c.close();
}
示例7: assertProductsTableExistsAndLoaded
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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());
conn.close();
} finally {
ds.forceCloseAll();
}
}
示例8: ShouldReturnRealConnection
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Test
public void ShouldReturnRealConnection() throws Exception {
PooledDataSource ds = createPooledDataSource(JPETSTORE_PROPERTIES);
Connection c = ds.getConnection();
JDBCConnection realConnection = (JDBCConnection) PooledDataSource.unwrapConnection(c);
}
示例9: shouldReconnectWhenServerKilledLeakedConnection
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Ignore("See the comments")
@Test
public void shouldReconnectWhenServerKilledLeakedConnection() throws Exception {
// See #748
// Requirements:
// 1. MySQL JDBC driver dependency.
// 2. MySQL server instance with the following.
// - CREATE DATABASE `test`;
// - SET GLOBAL wait_timeout=3;
// 3. Tweak the connection info below.
final String URL = "jdbc:mysql://localhost:3306/test";
final String USERNAME = "admin";
final String PASSWORD = "";
Connection con;
PooledDataSource ds = new PooledDataSource();
ds.setDriver("com.mysql.jdbc.Driver");
ds.setUrl(URL);
ds.setUsername(USERNAME);
ds.setPassword(PASSWORD);
ds.setPoolMaximumActiveConnections(1);
ds.setPoolMaximumIdleConnections(1);
ds.setPoolTimeToWait(1000);
ds.setPoolMaximumCheckoutTime(2000);
ds.setPoolPingEnabled(true);
ds.setPoolPingQuery("select 1");
ds.setDefaultAutoCommit(true);
// MySQL wait_timeout * 1000 or less. (unit:ms)
ds.setPoolPingConnectionsNotUsedFor(1000);
con = ds.getConnection();
exexuteQuery(con);
// Simulate connection leak by not closing.
// con.close();
// Wait for disconnected from mysql...
Thread.sleep(TimeUnit.SECONDS.toMillis(3));
// Should return usable connection.
con = ds.getConnection();
exexuteQuery(con);
con.close();
}
示例10: testPerformDatabaseSchemaOperationCreate
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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);
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);
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();
}
}
示例11: testPerformDatabaseSchemaOperationCreate
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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.setValidateFlowable5EntitiesEnabled(false);
config1.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
config1.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(false);
ProcessEngine engine1 = config1.buildProcessEngine();
ProcessEngineConfigurationImpl config2 = (ProcessEngineConfigurationImpl) ProcessEngineConfigurationImpl.createStandaloneInMemProcessEngineConfiguration().setDataSource(pooledDataSource)
.setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
config2.setDatabaseTablePrefix("SCHEMA2.");
config2.setValidateFlowable5EntitiesEnabled(false);
config2.getPerformanceSettings().setValidateExecutionRelationshipCountConfigOnBoot(false);
config2.getPerformanceSettings().setValidateTaskRelationshipCountConfigOnBoot(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();
}
}
示例12: testPerformDatabaseSchemaOperationCreate
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
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.");
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();
}
}
示例13: shouldPerformDatabaseSchemaOperationCreate
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@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;
}
}
示例14: shouldReconnectWhenServerKilledLeakedConnection
import org.apache.ibatis.datasource.pooled.PooledDataSource; //导入方法依赖的package包/类
@Ignore("See the comments")
@Test
public void shouldReconnectWhenServerKilledLeakedConnection() throws Exception {
// See #748
// Requirements:
// 1. MySQL JDBC driver dependency.
// 2. MySQL server instance with the following.
// - CREATE DATABASE `test`;
// - SET GLOBAL wait_timeout=3;
// 3. Tweak the connection info below.
final String URL = "jdbc:mysql://localhost:3306/test";
final String USERNAME = "admin";
final String PASSWORD = "";
PooledDataSource ds = new PooledDataSource();
ds.setDriver("com.mysql.jdbc.Driver");
ds.setUrl(URL);
ds.setUsername(USERNAME);
ds.setPassword(PASSWORD);
ds.setPoolMaximumActiveConnections(1);
ds.setPoolMaximumIdleConnections(1);
ds.setPoolTimeToWait(1000);
ds.setPoolMaximumCheckoutTime(2000);
ds.setPoolPingEnabled(true);
ds.setPoolPingQuery("select 1");
ds.setDefaultAutoCommit(true);
// MySQL wait_timeout * 1000 or less. (unit:ms)
ds.setPoolPingConnectionsNotUsedFor(1000);
Connection con = ds.getConnection();
exexuteQuery(con);
// Simulate connection leak by not closing.
// con.close();
// Wait for disconnected from mysql...
Thread.sleep(TimeUnit.SECONDS.toMillis(3));
con.close();
// Should return usable connection.
con = ds.getConnection();
exexuteQuery(con);
con.close();
}