當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSource.close方法代碼示例

本文整理匯總了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());
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:27,代碼來源:PoolCleanerTest.java

示例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();
}
 
開發者ID:FrancisG-Massey,項目名稱:Capstone2016,代碼行數:28,代碼來源:NestHttpTests.java

示例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;
}
 
開發者ID:FrancisG-Massey,項目名稱:Capstone2016,代碼行數:30,代碼來源:NestHttpTests.java

示例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;
}
 
開發者ID:callakrsos,項目名稱:Gargoyle,代碼行數:21,代碼來源:ConnectionManager.java

示例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();
}
 
開發者ID:mauyr,項目名稱:openbravo-brazil,代碼行數:14,代碼來源:JdbcExternalConnectionPool.java

示例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();
}
 
開發者ID:FrancisG-Massey,項目名稱:Capstone2016,代碼行數:20,代碼來源:DBConnectTests.java

示例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();
}
 
開發者ID:FrancisG-Massey,項目名稱:Capstone2016,代碼行數:20,代碼來源:DBConnectTests.java

示例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();
}
   }
 
開發者ID:levants,項目名稱:lightmare,代碼行數:10,代碼來源:InitTomcat.java

示例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);
	}
}
 
開發者ID:jbeetle,項目名稱:BJAF3.x,代碼行數:46,代碼來源:TomcatJdbcPool.java


注:本文中的org.apache.tomcat.jdbc.pool.DataSource.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。