本文整理汇总了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;
}
示例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);
}
示例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);
}