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


Java PoolableConnectionFactory.setDefaultReadOnly方法代码示例

本文整理汇总了Java中org.apache.commons.dbcp2.PoolableConnectionFactory.setDefaultReadOnly方法的典型用法代码示例。如果您正苦于以下问题:Java PoolableConnectionFactory.setDefaultReadOnly方法的具体用法?Java PoolableConnectionFactory.setDefaultReadOnly怎么用?Java PoolableConnectionFactory.setDefaultReadOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.dbcp2.PoolableConnectionFactory的用法示例。


在下文中一共展示了PoolableConnectionFactory.setDefaultReadOnly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPool

import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
public static DataSource createPool(ConnectionFactory connectionFactory, int isolation) {
 
 
 
   PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
       connectionFactory, null);
   poolableConnectionFactory.setMaxConnLifetimeMillis(3000);
   poolableConnectionFactory.setDefaultAutoCommit(false);
   poolableConnectionFactory.setDefaultReadOnly(true);
   poolableConnectionFactory
       .setDefaultTransactionIsolation(isolation);
   ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(
       poolableConnectionFactory);
   poolableConnectionFactory.setPool(connectionPool);
   PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(
       connectionPool);
   return dataSource;
}
 
开发者ID:objectof-group,项目名称:objectof,代码行数:19,代码来源:ISql.java

示例2: setUp

import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    // create a GeronimoTransactionManager for testing
    transactionManager = new TransactionManagerImpl();

    // create a driver connection factory
    final Properties properties = new Properties();
    properties.setProperty("user", "username");
    properties.setProperty("password", "password");
    final ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);

    // wrap it with a LocalXAConnectionFactory
    final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(transactionManager, connectionFactory);

    // create the pool object factory
    final PoolableConnectionFactory factory =
        new PoolableConnectionFactory(xaConnectionFactory, null);
    factory.setValidationQuery("SELECT DUMMY FROM DUAL");
    factory.setDefaultReadOnly(Boolean.TRUE);
    factory.setDefaultAutoCommit(Boolean.TRUE);

    // create the pool
    pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setMaxTotal(getMaxTotal());
    pool.setMaxWaitMillis(getMaxWaitMillis());

    // finally create the datasource
    ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry());
    ds.setAccessToUnderlyingConnectionAllowed(true);
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:32,代码来源:TestManagedDataSource.java

示例3: setUp

import org.apache.commons.dbcp2.PoolableConnectionFactory; //导入方法依赖的package包/类
@Before
public void setUp()
    throws Exception {
    // create a GeronimoTransactionManager for testing
    transactionManager = new TransactionManagerImpl();

    // create a driver connection factory
    final Properties properties = new Properties();
    properties.setProperty("user", "username");
    properties.setProperty("password", "password");
    final ConnectionFactory connectionFactory = new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties);

    // wrap it with a LocalXAConnectionFactory
    final XAConnectionFactory xaConnectionFactory = new UncooperativeLocalXAConnectionFactory(transactionManager, connectionFactory);

    // create the pool object factory
    final PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null);
    factory.setValidationQuery("SELECT DUMMY FROM DUAL");
    factory.setDefaultReadOnly(Boolean.TRUE);
    factory.setDefaultAutoCommit(Boolean.TRUE);

    // create the pool
    pool = new GenericObjectPool<>(factory);
    factory.setPool(pool);
    pool.setMaxTotal(10);
    pool.setMaxWaitMillis(100);

    // finally create the datasource
    ds = new ManagedDataSource<>(pool, xaConnectionFactory.getTransactionRegistry());
    ds.setAccessToUnderlyingConnectionAllowed(true);
}
 
开发者ID:apache,项目名称:commons-dbcp,代码行数:32,代码来源:TestManagedConnection.java


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