当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionState类代码示例

本文整理汇总了Java中org.apache.tomcat.jdbc.pool.interceptor.ConnectionState的典型用法代码示例。如果您正苦于以下问题:Java ConnectionState类的具体用法?Java ConnectionState怎么用?Java ConnectionState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionState类属于org.apache.tomcat.jdbc.pool.interceptor包,在下文中一共展示了ConnectionState类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDefaultCatalog

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
@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");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:TestConnectionState.java

示例2: testAutoCommitFalse

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
@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());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:TestConnectionState.java

示例3: testAutoCommitFalse

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
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();
    assertFalse("Auto commit should be false",c1.getAutoCommit());
    c1.setAutoCommit(true);
    assertTrue("Auto commit should be true",c1.getAutoCommit());
    c1.close();
    c1 = d1.getConnection();
    assertFalse("Auto commit should be false for a reused connection",c1.getAutoCommit());
    d1.close(true);
    assertTrue("Connection should be closed",c1.isClosed());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:18,代码来源:TestConnectionState.java

示例4: testDefaultCatalog

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
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();
    assertEquals("Catalog should be information_schema",c1.getCatalog(),"information_schema");
    c1.close();
    c1 = d1.getConnection();
    assertEquals("Catalog should be information_schema",c1.getCatalog(),"information_schema");
    c1.setCatalog("mysql");
    assertEquals("Catalog should be information_schema",c1.getCatalog(),"mysql");
    c1.close();
    c1 = d1.getConnection();
    assertEquals("Catalog should be information_schema",c1.getCatalog(),"information_schema");
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:18,代码来源:TestConnectionState.java

示例5: connect

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
/**
 * Connects the underlying connection to the database.
 * @throws SQLException if the method {@link #release()} has been called.
 * @throws SQLException if driver instantiation fails
 * @throws SQLException if a call to {@link java.sql.Driver#connect(String, java.util.Properties)} fails.
 * @throws SQLException if default properties are configured and a call to
 * {@link java.sql.Connection#setAutoCommit(boolean)}, {@link java.sql.Connection#setCatalog(String)},
 * {@link java.sql.Connection#setTransactionIsolation(int)} or {@link java.sql.Connection#setReadOnly(boolean)} fails.
 */
public void connect() throws SQLException {
    if (released.get()) throw new SQLException("A connection once released, can't be reestablished.");
    if (connection != null) {
        try {
            this.disconnect(false);
        } catch (Exception x) {
            log.debug("Unable to disconnect previous connection.", x);
        } //catch
    } //end if
    if (poolProperties.getDataSource()==null && poolProperties.getDataSourceJNDI()!=null) {
        //TODO lookup JNDI name
    }

    if (poolProperties.getDataSource()!=null) {
        connectUsingDataSource();
    } else {
        connectUsingDriver();
    }

    //set up the default state, unless we expect the interceptor to do it
    if (poolProperties.getJdbcInterceptors()==null || poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getName())<0 ||
            poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getSimpleName())<0) {
        if (poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION) connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
        if (poolProperties.getDefaultReadOnly()!=null) connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
        if (poolProperties.getDefaultAutoCommit()!=null) connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
        if (poolProperties.getDefaultCatalog()!=null) connection.setCatalog(poolProperties.getDefaultCatalog());
    }
    this.discarded = false;
    this.lastConnected = System.currentTimeMillis();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:40,代码来源:PooledConnection.java

示例6: setUp

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    this.datasource.setUrl("jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");
    this.datasource.setJdbcInterceptors(ConnectionState.class.getName());
    this.datasource.setDefaultTransactionIsolation(-55);
    this.datasource.setInitialSize(1);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:8,代码来源:Bug50571.java

示例7: testAutoCommitTrue

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
@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());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:TestConnectionState.java

示例8: connect

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
/**
 * Connects the underlying connection to the database.
 * @throws SQLException if the method {@link #release()} has been called.
 * @throws SQLException if driver instantiation fails
 * @throws SQLException if a call to {@link java.sql.Driver#connect(String, java.util.Properties)} fails.
 * @throws SQLException if default properties are configured and a call to 
 * {@link java.sql.Connection#setAutoCommit(boolean)}, {@link java.sql.Connection#setCatalog(String)}, 
 * {@link java.sql.Connection#setTransactionIsolation(int)} or {@link java.sql.Connection#setReadOnly(boolean)} fails.  
 */
public void connect() throws SQLException {
    if (released.get()) throw new SQLException("A connection once released, can't be reestablished.");
    if (connection != null) {
        try {
            this.disconnect(false);
        } catch (Exception x) {
            log.debug("Unable to disconnect previous connection.", x);
        } //catch
    } //end if
    if (poolProperties.getDataSource()==null && poolProperties.getDataSourceJNDI()!=null) {
        //TODO lookup JNDI name
    }
    
    if (poolProperties.getDataSource()!=null) {
        connectUsingDataSource();
    } else {
        connectUsingDriver();
    }
    
    //set up the default state, unless we expect the interceptor to do it
    if (poolProperties.getJdbcInterceptors()==null || poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getName())<0) {
        if (poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION) connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
        if (poolProperties.getDefaultReadOnly()!=null) connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
        if (poolProperties.getDefaultAutoCommit()!=null) connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
        if (poolProperties.getDefaultCatalog()!=null) connection.setCatalog(poolProperties.getDefaultCatalog());
    }        
    this.discarded = false;
    this.lastConnected = System.currentTimeMillis();
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:39,代码来源:PooledConnection.java

示例9: setUp

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();
    this.datasource.setUrl("jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE");
    this.datasource.setJdbcInterceptors(ConnectionState.class.getName());
    this.datasource.setDefaultTransactionIsolation(-55);
    this.datasource.setInitialSize(1);
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:9,代码来源:Bug50571.java

示例10: testAutoCommitTrue

import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState; //导入依赖的package包/类
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();
    assertTrue("Auto commit should be true",c1.getAutoCommit());
    c1.setAutoCommit(false);
    assertFalse("Auto commit should be false",c1.getAutoCommit());
    c1.close();
    c1 = d1.getConnection();
    assertTrue("Auto commit should be true for a reused connection",c1.getAutoCommit());
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:15,代码来源:TestConnectionState.java


注:本文中的org.apache.tomcat.jdbc.pool.interceptor.ConnectionState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。