本文整理汇总了Java中org.apache.tomcat.jdbc.pool.DataSource.close方法的典型用法代码示例。如果您正苦于以下问题:Java DataSource.close方法的具体用法?Java DataSource.close怎么用?Java DataSource.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.jdbc.pool.DataSource
的用法示例。
在下文中一共展示了DataSource.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test2PoolCleaners
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
@Test
public void test2PoolCleaners() throws Exception {
datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(2000);
datasource.getPoolProperties().setTestWhileIdle(true);
DataSource ds2 = new DataSource(datasource.getPoolProperties());
Assert.assertEquals("Pool cleaner should not be started yet.",0,ConnectionPool.getPoolCleaners().size() );
Assert.assertNull("Pool timer should be null", ConnectionPool.getPoolTimer());
Assert.assertEquals("Pool cleaner threads should not be present.",0, countPoolCleanerThreads());
datasource.getConnection().close();
ds2.getConnection().close();
Assert.assertEquals("Pool cleaner should have 2 cleaner.",2,ConnectionPool.getPoolCleaners().size() );
Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());
Assert.assertEquals("Pool cleaner threads should be 1.",1, countPoolCleanerThreads());
datasource.close();
Assert.assertEquals("Pool cleaner should have 1 cleaner.",1,ConnectionPool.getPoolCleaners().size() );
Assert.assertNotNull("Pool timer should not be null", ConnectionPool.getPoolTimer());
ds2.close();
Assert.assertEquals("Pool shutdown, no cleaners should be present.",0,ConnectionPool.getPoolCleaners().size() );
Assert.assertNull("Pool timer should be null after shutdown", ConnectionPool.getPoolTimer());
Assert.assertEquals("Pool cleaner threads should not be present after close.",0, countPoolCleanerThreads());
}
示例2: NestWipeDB
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
/**
* For wiping the test database before running tests, so we know they are atomic
* @throws SQLException
* @throws IOException
*/
protected static void NestWipeDB() throws SQLException, IOException {
// Wipe the DB so we know the tests are atomic.
// First read the repeatable SQL DB schema into memory.
String dbSchema = null;
try (Scanner scanner = new Scanner(new File(DBCREATESCRIPT_PATH));) {
dbSchema = scanner.useDelimiter("\\A").next();
}
if (dbSchema == null) {
throw new IOException("Unable to load repeatable database schema");
}
// Next wipe the db
DataSource dsTest = Common.getNestDS(DBCONFIGPATH_TEST);
try (
Connection conn = dsTest.getConnection();
Statement st = conn.createStatement();
) {
boolean hasResults = st.execute(dbSchema);
}
dsTest.close();
}
示例3: dbDeleteEntities
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
/**
* Remove the created entities directly via the db so we don't worry about bugs in DELETE.
* @param entitiesList These should be names of tables in the database!
* @param ids This should have keys for each value in entitiesList!
* @return
* @throws SQLException
* @throws IOException
*/
protected static boolean dbDeleteEntities(List<String> entitiesList, Map<String,Long> ids) throws SQLException, IOException {
DataSource dsTest = Common.getNestDS(DBCONFIGPATH_TEST);
for(int i = entitiesList.size()-1; i >= 0; i--) {
// Get the entities to delete
final String tablename = entitiesList.get(i);
Long id = ids.get(tablename);
// It's late, okay!?
final String columnname = (!tablename.equals("users"))? tablename+"_id" : "user_id";
try (
Connection conn = dsTest.getConnection();
Statement st = conn.createStatement();
) {
boolean hasResults = st.execute("DELETE FROM "+tablename+" WHERE "+columnname+" = "+id+";");
}
}
dsTest.close();
return true;
}
示例4: close
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
/**
* 커넥션 종료
*
* @작성자 : KYJ
* @작성일 : 2015. 11. 17.
* @param con
* @throws Exception
*/
public static void close(DataSource con) throws Exception {
if (con != null) {
try {
con.close();
LOGGER.debug("Close Database Connection Request...");
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
con.close();
}
}
con = null;
}
示例5: closePool
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
/**
* This method closes apache jdbc connection pool.
*/
@Override
public void closePool() {
DataSource ds = getDataSource();
if (ds != null) {
// Closes the pool and all idle connections. true parameter is for close the active
// connections too.
ds.close(true);
}
super.closePool();
}
示例6: TestDatabaseConnects
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
/**
* Test that the handler can connect to the test db server using the Common method
* @throws IOException
* @throws SQLException
*/
@Test
public void TestDatabaseConnects() throws IOException, SQLException {
// Load the db config properties
DataSource dsTest = Common.getNestDS(dbConfigPathTest);
Connection conn = dsTest.getConnection();
Statement st = conn.createStatement();
ResultSet rsh = st.executeQuery("SELECT 1;");
assertTrue(rsh.isBeforeFirst());
rsh.close();
st.close();
conn.close();
dsTest.close();
}
示例7: ProdDatabaseConnects
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
/**
* Test that the handler can connect to the prod db server using the Common method
* @throws IOException
* @throws SQLException
*/
@Test
public void ProdDatabaseConnects() throws IOException, SQLException {
// Load the db config properties
DataSource dsProd = Common.getNestDS(dbConfigPathProd);
Connection conn = dsProd.getConnection();
Statement st = conn.createStatement();
ResultSet rsh = st.executeQuery("SELECT 1;");
assertTrue(rsh.isBeforeFirst());
rsh.close();
st.close();
conn.close();
dsProd.close();
}
示例8: cleanUp
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
@Override
public void cleanUp(javax.sql.DataSource dataSource) {
DataSource pooledDataSource;
if (dataSource instanceof DataSource) {
pooledDataSource = ObjectUtils.cast(dataSource, DataSource.class);
pooledDataSource.close();
}
}
示例9: start
import org.apache.tomcat.jdbc.pool.DataSource; //导入方法依赖的package包/类
@Override
public void start() {
PoolProperties p = new PoolProperties();
p.setUrl(this.conURL);
p.setDriverClassName(this.driverName);
p.setUsername(this.username);
p.setPassword(this.password);
p.setJmxEnabled(false);
if (this.testSql != null && this.testSql.trim().length() > 0) {
p.setValidationQuery(this.testSql);
p.setTestWhileIdle(true);
p.setTimeBetweenEvictionRunsMillis(15 * 1000);
boolean tbf = AppProperties.getAsBoolean(
"TomcatJdbcPool_TestOnBorrow", false);
p.setTestOnBorrow(tbf);// 获取之前是否校验
p.setTestOnReturn(false);
p.setValidationInterval(30000);
}
p.setMaxActive(this.max);
p.setMaxIdle(this.max);
p.setInitialSize(this.min);
p.setMinIdle(min);
int maxwaitfornoconn = AppProperties.getAsInt("TomcatJdbcPool_MaxWait",
30 * 1000);
p.setMaxWait(maxwaitfornoconn);
boolean removeAbandonedFlag = AppProperties.getAsBoolean(
"TomcatJdbcPool_RemoveAbandoned", false);
if (removeAbandonedFlag) {
p.setLogAbandoned(true);
p.setRemoveAbandoned(true);
p.setRemoveAbandonedTimeout(AppProperties.getAsInt(
"TomcatJdbcPool_RemoveAbandonedTimeout", 60));
}
// p.setMinEvictableIdleTimeMillis(30000);
p.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer");
datasource = new DataSource();
datasource.setPoolProperties(p);
try {
datasource.createPool();
} catch (SQLException e) {
datasource.close();
throw new AppRuntimeException("start tomcat pool err", e);
}
}