List of usage examples for org.apache.commons.pool.impl GenericKeyedObjectPoolFactory GenericKeyedObjectPoolFactory
public GenericKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory, int maxActive, byte whenExhaustedAction, long maxWait, int maxIdle, int maxTotal, boolean testOnBorrow, boolean testOnReturn, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, boolean testWhileIdle)
From source file:org.apache.cayenne.conf.CustomDBCPDataSourceBuilder.java
private KeyedObjectPoolFactory createPreparedStatementPool() { if (!config.getBoolean("poolPreparedStatements", false)) { return null; }/*from w w w. j a va 2s .c o m*/ // the GenericKeyedObjectPool.Config object isn't used because // although it has provision for the maxTotal parameter when // passed to the GenericKeyedObjectPoolFactory constructor // this parameter is not being properly set as a default for // creating prepared statement pools int maxActive = config.getInt(PS_MAX_ACTIVE, GenericObjectPool.DEFAULT_MAX_ACTIVE); byte whenExhaustedAction = config.getWhenExhaustedAction(PS_EXHAUSTED_ACTION, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION); long maxWait = config.getLong(PS_MAX_WAIT, GenericObjectPool.DEFAULT_MAX_WAIT); int maxIdle = config.getInt(PS_MAX_IDLE, GenericObjectPool.DEFAULT_MAX_IDLE); int maxTotal = config.getInt(PS_MAX_TOTAL, 1); boolean testOnBorrow = config.getBoolean(PS_TEST_ON_BORROW, GenericObjectPool.DEFAULT_TEST_ON_BORROW); boolean testOnReturn = config.getBoolean(PS_TEST_ON_RETURN, GenericObjectPool.DEFAULT_TEST_ON_RETURN); long timeBetweenEvictionRunsMillis = config.getLong(PS_TIME_BETWEEN_EVICTIONS, GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS); int numTestsPerEvictionRun = config.getInt(PS_NUM_TEST_PER_EVICTION, GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN); long minEvictableIdleTimeMillis = config.getLong(PS_MIN_EVICTABLE_TIME, GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); boolean testWhileIdle = config.getBoolean(PS_TEST_IDLE, GenericObjectPool.DEFAULT_TEST_WHILE_IDLE); return new GenericKeyedObjectPoolFactory(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle); }
From source file:org.openanzo.datasource.nodecentric.internal.NodeCentricDatasource.java
/** * Initialize a jdbc connection pool/*from w w w . ja v a2 s . c o m*/ * * @param type * either rw or query pool * @param maxActive * maximum number of connections in pool * @param configuration * configuration properties used for creating database connections * @return connection pool * @throws AnzoException * {@link ExceptionConstants#RDB.DRIVER_NAME} if there was a problem loading class for database driver */ private GenericObjectPool initializeConnectionFactory(boolean write, int maxActive) throws AnzoException { // Will use in jndi // DataSource ds = (DataSource) ctx.lookup(RepositoryProperties.getDatabaseJndiName(properties)); try { Class.forName(configuration.getDriverClassName()); } catch (ClassNotFoundException e1) { throw new AnzoException(ExceptionConstants.RDB.DRIVER_NAME, e1, configuration.getDriverClassName()); } Properties props = new Properties(); props.put("user", configuration.getUser()); props.put("password", configuration.getPassword()); props.put("SetBigStringTryClob", "true"); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(configuration.getJdbcUrl(), props); GenericObjectPool connectionPool = new GenericObjectPool(); connectionPool.setMaxActive(maxActive); connectionPool.setMaxIdle(Math.max(1, maxActive / 2)); connectionPool.setMinIdle(0); connectionPool.setMinEvictableIdleTimeMillis(1000 * 60 * 10); connectionPool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 10); connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK); connectionPool.setMaxWait(GenericKeyedObjectPool.DEFAULT_MAX_WAIT); connectionPool.setTestOnBorrow(true); GenericKeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory(null, PS_CACHE_SIZE, GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK, GenericKeyedObjectPool.DEFAULT_MAX_WAIT, PS_CACHE_SIZE, PS_CACHE_SIZE, GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE); PoolableConnectionFactory pcf = new PoolableConnectionFactory(connectionFactory, connectionPool, statementPool, configuration.getValidationQuery(), false, true) { @Override public synchronized Object makeObject() throws Exception { Connection connection = (Connection) super.makeObject(); initializeConnection(connection); return connection; } }; if (configuration.getSupportsIsolation() && write) pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); else if (configuration.getSupportsIsolation() && !write) pcf.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); return connectionPool; }