Search in sources :

Example 1 with DataSourceProxy

use of org.apache.tomcat.jdbc.pool.DataSourceProxy in project tomcat by apache.

the class TestConnectionState method testAutoCommitTrue.

@Test
public void testAutoCommitTrue() throws Exception {
    DataSourceProxy d1 = this.createDefaultDataSource();
    d1.setMaxActive(1);
    d1.setJdbcInterceptors(ConnectionState.class.getName());
    d1.setDefaultAutoCommit(Boolean.TRUE);
    d1.setMinIdle(1);
    Connection c1 = d1.getConnection();
    Assert.assertTrue("Auto commit should be true", c1.getAutoCommit());
    c1.setAutoCommit(false);
    Assert.assertFalse("Auto commit should be false", c1.getAutoCommit());
    c1.close();
    c1 = d1.getConnection();
    Assert.assertTrue("Auto commit should be true for a reused connection", c1.getAutoCommit());
}
Also used : DataSourceProxy(org.apache.tomcat.jdbc.pool.DataSourceProxy) Connection(java.sql.Connection) ConnectionState(org.apache.tomcat.jdbc.pool.interceptor.ConnectionState) Test(org.junit.Test)

Example 2 with DataSourceProxy

use of org.apache.tomcat.jdbc.pool.DataSourceProxy in project metacat by Netflix.

the class DataSourceManager method close.

/**
 * Closes all the data sources stored in the manager.
 */
@PreDestroy
public void close() {
    final Iterator<DataSource> iter = dataSources.values().iterator();
    while (iter.hasNext()) {
        final DataSourceProxy dataSource = (DataSourceProxy) iter.next();
        if (dataSource != null) {
            dataSource.close();
        }
        iter.remove();
    }
}
Also used : DataSourceProxy(org.apache.tomcat.jdbc.pool.DataSourceProxy) DataSource(javax.sql.DataSource) PreDestroy(javax.annotation.PreDestroy)

Example 3 with DataSourceProxy

use of org.apache.tomcat.jdbc.pool.DataSourceProxy in project tomcat by apache.

the class TestConnectionState method testAutoCommitFalse.

@Test
public void testAutoCommitFalse() throws Exception {
    DataSourceProxy d1 = this.createDefaultDataSource();
    d1.setMaxActive(1);
    d1.setMinIdle(1);
    d1.setMaxIdle(1);
    d1.setJdbcInterceptors(ConnectionState.class.getName());
    d1.setDefaultAutoCommit(Boolean.FALSE);
    Connection c1 = d1.getConnection();
    Assert.assertFalse("Auto commit should be false", c1.getAutoCommit());
    c1.setAutoCommit(true);
    Assert.assertTrue("Auto commit should be true", c1.getAutoCommit());
    c1.close();
    c1 = d1.getConnection();
    Assert.assertFalse("Auto commit should be false for a reused connection", c1.getAutoCommit());
    d1.close(true);
    Assert.assertTrue("Connection should be closed", c1.isClosed());
}
Also used : DataSourceProxy(org.apache.tomcat.jdbc.pool.DataSourceProxy) Connection(java.sql.Connection) ConnectionState(org.apache.tomcat.jdbc.pool.interceptor.ConnectionState) Test(org.junit.Test)

Example 4 with DataSourceProxy

use of org.apache.tomcat.jdbc.pool.DataSourceProxy in project tomcat by apache.

the class TestConnectionState method testDefaultCatalog.

@Test
public void testDefaultCatalog() throws Exception {
    DataSourceProxy d1 = this.createDefaultDataSource();
    d1.setMaxActive(1);
    d1.setJdbcInterceptors(ConnectionState.class.getName());
    d1.setDefaultCatalog("information_schema");
    d1.setMinIdle(1);
    Connection c1 = d1.getConnection();
    Assert.assertEquals("Catalog should be information_schema", c1.getCatalog(), "information_schema");
    c1.close();
    c1 = d1.getConnection();
    Assert.assertEquals("Catalog should be information_schema", c1.getCatalog(), "information_schema");
    c1.setCatalog("mysql");
    Assert.assertEquals("Catalog should be information_schema", c1.getCatalog(), "mysql");
    c1.close();
    c1 = d1.getConnection();
    Assert.assertEquals("Catalog should be information_schema", c1.getCatalog(), "information_schema");
}
Also used : DataSourceProxy(org.apache.tomcat.jdbc.pool.DataSourceProxy) Connection(java.sql.Connection) ConnectionState(org.apache.tomcat.jdbc.pool.interceptor.ConnectionState) Test(org.junit.Test)

Aggregations

DataSourceProxy (org.apache.tomcat.jdbc.pool.DataSourceProxy)4 Connection (java.sql.Connection)3 ConnectionState (org.apache.tomcat.jdbc.pool.interceptor.ConnectionState)3 Test (org.junit.Test)3 PreDestroy (javax.annotation.PreDestroy)1 DataSource (javax.sql.DataSource)1