List of usage examples for org.apache.commons.dbcp PoolableConnectionFactory getPool
public synchronized ObjectPool getPool()
From source file:com.iciql.test.IciqlSuite.java
/** * Main entry point for the test suite. Executing this method will run the * test suite on all registered databases. * //from w ww .jav a 2 s . c om * @param args * @throws Exception */ public static void main(String... args) throws Exception { Params params = new Params(); JCommander jc = new JCommander(params); try { jc.parse(args); } catch (ParameterException t) { usage(jc, t); } // Replace System.out with a file if (!StringUtils.isNullOrEmpty(params.dbPerformanceFile)) { out = new PrintStream(params.dbPerformanceFile); System.setErr(out); } deleteRecursively(new File("testdbs")); // Start the HSQL and H2 servers in-process org.hsqldb.Server hsql = startHSQL(); org.h2.tools.Server h2 = startH2(); // Statement logging final FileWriter statementWriter; if (StringUtils.isNullOrEmpty(params.sqlStatementsFile)) { statementWriter = null; } else { statementWriter = new FileWriter(params.sqlStatementsFile); } IciqlListener statementListener = new IciqlListener() { @Override public void logIciql(StatementType type, String statement) { if (statementWriter == null) { return; } try { statementWriter.append(statement); statementWriter.append('\n'); } catch (IOException e) { e.printStackTrace(); } } }; IciqlLogger.registerListener(statementListener); SuiteClasses suiteClasses = IciqlSuite.class.getAnnotation(SuiteClasses.class); long quickestDatabase = Long.MAX_VALUE; String dividerMajor = buildDivider('*', 79); String dividerMinor = buildDivider('-', 79); // Header out.println(dividerMajor); out.println(MessageFormat.format("{0} {1} ({2}) testing {3} database configurations", Constants.NAME, Constants.VERSION, Constants.VERSION_DATE, TEST_DBS.length)); out.println(dividerMajor); out.println(); showProperty("java.vendor"); showProperty("java.runtime.version"); showProperty("java.vm.name"); showProperty("os.name"); showProperty("os.version"); showProperty("os.arch"); showProperty("available processors", "" + Runtime.getRuntime().availableProcessors()); showProperty("available memory", MessageFormat.format("{0,number,0.0} GB", ((double) Runtime.getRuntime().maxMemory()) / (1024 * 1024))); out.println(); // Test a database long lastCount = 0; for (TestDb testDb : TEST_DBS) { out.println(dividerMinor); out.println("Testing " + testDb.describeDatabase()); out.println(" " + testDb.url); out.println(dividerMinor); // inject a database section delimiter in the statement log if (statementWriter != null) { statementWriter.append("\n\n"); statementWriter.append("# ").append(dividerMinor).append('\n'); statementWriter.append("# ").append("Testing " + testDb.describeDatabase()).append('\n'); statementWriter.append("# ").append(dividerMinor).append('\n'); statementWriter.append("\n\n"); } if (testDb.getVersion().equals("OFFLINE")) { // Database not available out.println("Skipping. Could not find " + testDb.url); out.println(); } else { // Setup system properties System.setProperty("iciql.url", testDb.url); System.setProperty("iciql.user", testDb.username); System.setProperty("iciql.password", testDb.password); // Test database Result result = JUnitCore.runClasses(suiteClasses.value()); // Report results testDb.runtime = result.getRunTime(); if (testDb.runtime < quickestDatabase) { quickestDatabase = testDb.runtime; } testDb.statements = IciqlLogger.getTotalCount() - lastCount; // reset total count for next database lastCount = IciqlLogger.getTotalCount(); out.println(MessageFormat.format( "{0} tests ({1} failures, {2} ignores) {3} statements in {4,number,0.000} secs", result.getRunCount(), result.getFailureCount(), result.getIgnoreCount(), testDb.statements, result.getRunTime() / 1000f)); if (result.getFailureCount() == 0) { out.println(); out.println(" 100% successful test suite run."); out.println(); } else { for (Failure failure : result.getFailures()) { out.println(MessageFormat.format("\n + {0}\n {1}", failure.getTestHeader(), failure.getMessage())); } out.println(); } } } // Display runtime results sorted by performance leader out.println(); out.println(dividerMajor); out.println(MessageFormat.format("{0} {1} ({2}) test suite performance results", Constants.NAME, Constants.VERSION, Constants.VERSION_DATE)); out.println(dividerMajor); List<TestDb> dbs = Arrays.asList(TEST_DBS); Collections.sort(dbs); out.println(MessageFormat.format("{0} {1} {2} {3} {4}", StringUtils.pad("Name", 11, " ", true), StringUtils.pad("Type", 5, " ", true), StringUtils.pad("Version", 23, " ", true), StringUtils.pad("Stats/Sec", 10, " ", true), "Runtime")); out.println(dividerMinor); for (TestDb testDb : dbs) { DecimalFormat df = new DecimalFormat("0.0"); out.println(MessageFormat.format("{0} {1} {2} {3} {4} {5}s ({6,number,0.0}x)", StringUtils.pad(testDb.name, 11, " ", true), testDb.isEmbedded ? "E" : "T", testDb.isMemory ? "M" : "F", StringUtils.pad(testDb.getVersion(), 21, " ", true), StringUtils.pad("" + testDb.getStatementRate(), 10, " ", false), StringUtils.pad(df.format(testDb.getRuntime()), 8, " ", false), ((double) testDb.runtime) / quickestDatabase)); } out.println(dividerMinor); out.println(" E = embedded connection"); out.println(" T = tcp/ip connection"); out.println(" M = memory database"); out.println(" F = file/persistent database"); // cleanup for (PoolableConnectionFactory factory : connectionFactories.values()) { factory.getPool().close(); } IciqlLogger.unregisterListener(statementListener); out.close(); System.setErr(ERR); if (statementWriter != null) { statementWriter.close(); } hsql.stop(); h2.stop(); System.exit(0); }
From source file:com.noelios.restlet.ext.jdbc.JdbcClientHelper.java
/** * Creates a connection pool for a given connection configuration. * /*from www . j a v a2s.c o m*/ * @param uri * The connection URI. * @param properties * The connection properties. * @return The new connection pool. */ protected static ObjectPool createConnectionPool(String uri, Properties properties) { // Create an ObjectPool that will serve as the actual pool of // connections final ObjectPool result = new GenericObjectPool(null); // Create a ConnectionFactory that the pool will use to create // Connections final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, properties); // Create the PoolableConnectionFactory, which wraps the "real" // Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, result, null, null, false, false); // To remove warnings poolableConnectionFactory.getPool(); return result; }
From source file:com.springsource.insight.plugin.jdbc.PoolingConnectionTest.java
@Test public void testOperationCollection() throws SQLException { DataSourceConnectionFactory connFactory = new DataSourceConnectionFactory(dataSource); ObjectPool connPool = new GenericObjectPool(); PoolableConnectionFactory poolFactory = new PoolableConnectionFactory(connFactory, connPool, null, null, false, true);// w ww. j ava 2 s . co m PoolingDataSource poolDs = new PoolingDataSource(poolFactory.getPool()); String sql = "select * from appointment where owner = 'Agim'"; Connection c = poolDs.getConnection(); try { PreparedStatement ps = c.prepareStatement(sql); try { System.out.println("Prepared statement=" + ps.getClass()); ResultSet rs = ps.executeQuery(); rs.close(); } finally { ps.close(); } } finally { c.close(); } ArgumentCaptor<Operation> opCaptor = ArgumentCaptor.forClass(Operation.class); verify(spiedOperationCollector, times(3)).enter(opCaptor.capture()); List<Operation> ops = opCaptor.getAllValues(); assertEquals("Mismatched number of operations", 3, ops.size()); assertSourceCodeLocation("top-op", ops.get(0), "org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper", "prepareStatement"); assertSourceCodeLocation("mid-op", ops.get(1), "org.apache.commons.dbcp.DelegatingConnection", "prepareStatement"); assertSourceCodeLocation("bottom-op", ops.get(2), "org.hsqldb.jdbc.jdbcConnection", "prepareStatement"); }
From source file:com.cloud.utils.db.Transaction.java
private static DataSource getDefaultDataSource(final String database) { final GenericObjectPool connectionPool = new GenericObjectPool(null, 5); final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( "jdbc:mysql://localhost:3306/" + database, "cloud", "cloud"); final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); return new PoolingDataSource(/* connectionPool */poolableConnectionFactory.getPool()); }
From source file:com.cloud.utils.db.TransactionLegacy.java
@SuppressWarnings({ "unchecked", "rawtypes" })
private static DataSource getDefaultDataSource(final String database) {
final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
"jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
connectionPool, null, null, false, true);
return new PoolingDataSource(/* connectionPool */poolableConnectionFactory.getPool());
}
From source file:com.cloud.utils.db.TransactionLegacy.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void initDataSource(Properties dbProps) {
try {/*from www .j ava2s. c om*/
if (dbProps.size() == 0)
return;
s_dbHAEnabled = Boolean.valueOf(dbProps.getProperty("db.ha.enabled"));
s_logger.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled);
String loadBalanceStrategy = dbProps.getProperty("db.ha.loadBalanceStrategy");
// FIXME: If params are missing...default them????
final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive"));
final int cloudMaxIdle = Integer.parseInt(dbProps.getProperty("db.cloud.maxIdle"));
final long cloudMaxWait = Long.parseLong(dbProps.getProperty("db.cloud.maxWait"));
final String cloudUsername = dbProps.getProperty("db.cloud.username");
final String cloudPassword = dbProps.getProperty("db.cloud.password");
final String cloudHost = dbProps.getProperty("db.cloud.host");
final String cloudDriver = dbProps.getProperty("db.cloud.driver");
final int cloudPort = Integer.parseInt(dbProps.getProperty("db.cloud.port"));
final String cloudDbName = dbProps.getProperty("db.cloud.name");
final boolean cloudAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.cloud.autoReconnect"));
final String cloudValidationQuery = dbProps.getProperty("db.cloud.validationQuery");
final String cloudIsolationLevel = dbProps.getProperty("db.cloud.isolation.level");
int isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
if (cloudIsolationLevel == null) {
isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
} else if (cloudIsolationLevel.equalsIgnoreCase("readcommitted")) {
isolationLevel = Connection.TRANSACTION_READ_COMMITTED;
} else if (cloudIsolationLevel.equalsIgnoreCase("repeatableread")) {
isolationLevel = Connection.TRANSACTION_REPEATABLE_READ;
} else if (cloudIsolationLevel.equalsIgnoreCase("serializable")) {
isolationLevel = Connection.TRANSACTION_SERIALIZABLE;
} else if (cloudIsolationLevel.equalsIgnoreCase("readuncommitted")) {
isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED;
} else {
s_logger.warn("Unknown isolation level " + cloudIsolationLevel + ". Using read uncommitted");
}
final boolean cloudTestOnBorrow = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testOnBorrow"));
final boolean cloudTestWhileIdle = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testWhileIdle"));
final long cloudTimeBtwEvictionRunsMillis = Long
.parseLong(dbProps.getProperty("db.cloud.timeBetweenEvictionRunsMillis"));
final long cloudMinEvcitableIdleTimeMillis = Long
.parseLong(dbProps.getProperty("db.cloud.minEvictableIdleTimeMillis"));
final boolean cloudPoolPreparedStatements = Boolean
.parseBoolean(dbProps.getProperty("db.cloud.poolPreparedStatements"));
final String url = dbProps.getProperty("db.cloud.url.params");
String cloudDbHAParams = null;
String cloudSlaves = null;
if (s_dbHAEnabled) {
cloudDbHAParams = getDBHAParams("cloud", dbProps);
cloudSlaves = dbProps.getProperty("db.cloud.slaves");
s_logger.info("The slaves configured for Cloud Data base is/are : " + cloudSlaves);
}
final boolean useSSL = Boolean.parseBoolean(dbProps.getProperty("db.cloud.useSSL"));
if (useSSL) {
System.setProperty("javax.net.ssl.keyStore", dbProps.getProperty("db.cloud.keyStore"));
System.setProperty("javax.net.ssl.keyStorePassword",
dbProps.getProperty("db.cloud.keyStorePassword"));
System.setProperty("javax.net.ssl.trustStore", dbProps.getProperty("db.cloud.trustStore"));
System.setProperty("javax.net.ssl.trustStorePassword",
dbProps.getProperty("db.cloud.trustStorePassword"));
}
final GenericObjectPool cloudConnectionPool = new GenericObjectPool(null, cloudMaxActive,
GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, cloudMaxWait, cloudMaxIdle, cloudTestOnBorrow,
false, cloudTimeBtwEvictionRunsMillis, 1, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle);
final String cloudConnectionUri = cloudDriver + "://" + cloudHost
+ (s_dbHAEnabled ? "," + cloudSlaves : "") + ":" + cloudPort + "/" + cloudDbName
+ "?autoReconnect=" + cloudAutoReconnect + (url != null ? "&" + url : "")
+ (useSSL ? "&useSSL=true" : "") + (s_dbHAEnabled ? "&" + cloudDbHAParams : "")
+ (s_dbHAEnabled ? "&loadBalanceStrategy=" + loadBalanceStrategy : "");
DriverLoader.loadDriver(cloudDriver);
final ConnectionFactory cloudConnectionFactory = new DriverManagerConnectionFactory(cloudConnectionUri,
cloudUsername, cloudPassword);
final KeyedObjectPoolFactory poolableObjFactory = (cloudPoolPreparedStatements
? new StackKeyedObjectPoolFactory()
: null);
final PoolableConnectionFactory cloudPoolableConnectionFactory = new PoolableConnectionFactory(
cloudConnectionFactory, cloudConnectionPool, poolableObjFactory, cloudValidationQuery, false,
false, isolationLevel);
// Default Data Source for CloudStack
s_ds = new PoolingDataSource(cloudPoolableConnectionFactory.getPool());
// Configure the usage db
final int usageMaxActive = Integer.parseInt(dbProps.getProperty("db.usage.maxActive"));
final int usageMaxIdle = Integer.parseInt(dbProps.getProperty("db.usage.maxIdle"));
final long usageMaxWait = Long.parseLong(dbProps.getProperty("db.usage.maxWait"));
final String usageUsername = dbProps.getProperty("db.usage.username");
final String usagePassword = dbProps.getProperty("db.usage.password");
final String usageHost = dbProps.getProperty("db.usage.host");
final String usageDriver = dbProps.getProperty("db.usage.driver");
final int usagePort = Integer.parseInt(dbProps.getProperty("db.usage.port"));
final String usageDbName = dbProps.getProperty("db.usage.name");
final boolean usageAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.usage.autoReconnect"));
final String usageUrl = dbProps.getProperty("db.usage.url.params");
final GenericObjectPool usageConnectionPool = new GenericObjectPool(null, usageMaxActive,
GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, usageMaxWait, usageMaxIdle);
final String usageConnectionUri = usageDriver + "://" + usageHost
+ (s_dbHAEnabled ? "," + dbProps.getProperty("db.cloud.slaves") : "") + ":" + usagePort + "/"
+ usageDbName + "?autoReconnect=" + usageAutoReconnect
+ (usageUrl != null ? "&" + usageUrl : "")
+ (s_dbHAEnabled ? "&" + getDBHAParams("usage", dbProps) : "")
+ (s_dbHAEnabled ? "&loadBalanceStrategy=" + loadBalanceStrategy : "");
DriverLoader.loadDriver(usageDriver);
final ConnectionFactory usageConnectionFactory = new DriverManagerConnectionFactory(usageConnectionUri,
usageUsername, usagePassword);
final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory(
usageConnectionFactory, usageConnectionPool, new StackKeyedObjectPoolFactory(), null, false,
false);
// Data Source for usage server
s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool());
try {
// Configure the simulator db
final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive"));
final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle"));
final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait"));
final String simulatorUsername = dbProps.getProperty("db.simulator.username");
final String simulatorPassword = dbProps.getProperty("db.simulator.password");
final String simulatorHost = dbProps.getProperty("db.simulator.host");
final String simulatorDriver = dbProps.getProperty("db.simulator.driver");
final int simulatorPort = Integer.parseInt(dbProps.getProperty("db.simulator.port"));
final String simulatorDbName = dbProps.getProperty("db.simulator.name");
final boolean simulatorAutoReconnect = Boolean
.parseBoolean(dbProps.getProperty("db.simulator.autoReconnect"));
final GenericObjectPool simulatorConnectionPool = new GenericObjectPool(null, simulatorMaxActive,
GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, simulatorMaxWait, simulatorMaxIdle);
final String simulatorConnectionUri = simulatorDriver + "://" + simulatorHost + ":" + simulatorPort
+ "/" + simulatorDbName + "?autoReconnect=" + simulatorAutoReconnect;
DriverLoader.loadDriver(simulatorDriver);
final ConnectionFactory simulatorConnectionFactory = new DriverManagerConnectionFactory(
simulatorConnectionUri, simulatorUsername, simulatorPassword);
final PoolableConnectionFactory simulatorPoolableConnectionFactory = new PoolableConnectionFactory(
simulatorConnectionFactory, simulatorConnectionPool, new StackKeyedObjectPoolFactory(),
null, false, false);
s_simulatorDS = new PoolingDataSource(simulatorPoolableConnectionFactory.getPool());
} catch (Exception e) {
s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS");
}
} catch (final Exception e) {
s_ds = getDefaultDataSource("cloud");
s_usageDS = getDefaultDataSource("cloud_usage");
s_simulatorDS = getDefaultDataSource("cloud_simulator");
s_logger.warn(
"Unable to load db configuration, using defaults with 5 connections. Falling back on assumed datasource on localhost:3306 using username:password=cloud:cloud. Please check your configuration",
e);
}
}
From source file:com.zotoh.core.db.JDBCPoolManager.java
private synchronized JDBCPool create(String pool, JDBCInfo param, Properties props) throws SQLException { if (existsPool(pool)) { throw new SQLException("Jdbc Pool already exists: " + pool); }// www.j a v a2 s.co m PoolableConnectionFactory pcf; DriverConnectionFactory dcf; GenericObjectPool gop; DBVendor dbv; ObjectPool p; Driver d; tlog().debug("JDBCPoolMgr: Driver : {}", param.getDriver()); tlog().debug("JDBCPoolMgr: URL : {}", param.getUrl()); // Ute.loadDriver(param.getDriver()); d = DriverManager.getDriver(param.getUrl()); dbv = DBUte.getDBVendor(param); dcf = new DriverConnectionFactory(d, param.getUrl(), props); gop = new GenericObjectPool(); gop.setMaxActive(asInt(props.getProperty("max-conns"), 10)); gop.setTestOnBorrow(true); gop.setMaxIdle(gop.getMaxActive()); gop.setMinIdle(asInt(props.getProperty("min-conns"), 2)); gop.setMaxWait(asLong(props.getProperty("max-wait4-conn-millis"), 1500L)); gop.setMinEvictableIdleTimeMillis(asLong(props.getProperty("evict-conn-ifidle-millis"), 300000L)); gop.setTimeBetweenEvictionRunsMillis(asLong(props.getProperty("check-evict-every-millis"), 60000L)); pcf = new PoolableConnectionFactory(dcf, gop, null, null, true, false); pcf.setDefaultReadOnly(false); p = pcf.getPool(); JDBCPool j = new JDBCPool(dbv, param, p); _ps.put(pool, j); tlog().debug("JDBCPoolMgr: Added db pool: {}, info= {}", pool, param); return j; }
From source file:orca.util.db.MySqlPool.java
public static synchronized void registerPool(DriverManagerConnectionFactory factory, String joclFileLocation, String poolName) throws Exception { if (factory == null) { throw new IllegalArgumentException("factory cannot be null"); }//w w w . java 2 s . c om if (poolName == null) { throw new IllegalArgumentException("poolName cannot be null"); } // register the pool only if this is a new pool boolean exists = false; String[] pools = driver.getPoolNames(); for (int i = 0; i < pools.length; i++) { if (pools[i].equals(poolName)) { exists = true; break; } } if (!exists) { GenericObjectPool connectionPool = createConnectionPool(joclFileLocation); PoolableConnectionFactory pcf = new PoolableConnectionFactory(factory, connectionPool, null, null, false, true); driver.registerPool(poolName, pcf.getPool()); } }
From source file:org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl.java
/** * Returns a new ObjectPool for the specified connection descriptor. * Override this method to setup your own pool. * @param jcd the connection descriptor for which to set up the pool * @return a newly created object pool//from w w w . ja v a 2 s .c o m */ protected ObjectPool setupPool(JdbcConnectionDescriptor jcd) { log.info("Create new ObjectPool for DBCP connections:" + jcd); try { ClassHelper.newInstance(jcd.getDriver()); } catch (InstantiationException e) { log.fatal( "Unable to instantiate the driver class: " + jcd.getDriver() + " in ConnectionFactoryDBCImpl!", e); } catch (IllegalAccessException e) { log.fatal("IllegalAccessException while instantiating the driver class: " + jcd.getDriver() + " in ConnectionFactoryDBCImpl!", e); } catch (ClassNotFoundException e) { log.fatal("Could not find the driver class : " + jcd.getDriver() + " in ConnectionFactoryDBCImpl!", e); } // Get the configuration for the connection pool GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig(); // Get the additional abandoned configuration AbandonedConfig ac = jcd.getConnectionPoolDescriptor().getAbandonedConfig(); // Create the ObjectPool that serves as the actual pool of connections. final ObjectPool connectionPool = createConnectionPool(conf, ac); // Create a DriverManager-based ConnectionFactory that // the connectionPool will use to create Connection instances final org.apache.commons.dbcp.ConnectionFactory connectionFactory; connectionFactory = createConnectionFactory(jcd); // Create PreparedStatement object pool (if any) KeyedObjectPoolFactory statementPoolFactory = createStatementPoolFactory(jcd); // Set validation query and auto-commit mode final String validationQuery; final boolean defaultAutoCommit; final boolean defaultReadOnly = false; validationQuery = jcd.getConnectionPoolDescriptor().getValidationQuery(); defaultAutoCommit = (jcd.getUseAutoCommit() != JdbcConnectionDescriptor.AUTO_COMMIT_SET_FALSE); // // Now we'll create the PoolableConnectionFactory, which wraps // the "real" Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. // final PoolableConnectionFactory poolableConnectionFactory; poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, statementPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit, ac); return poolableConnectionFactory.getPool(); }
From source file:org.restlet.ext.jdbc.JdbcClientHelper.java
/** * Creates a connection pool for a given connection configuration. * //from ww w . jav a2 s .c om * @param uri * The connection URI. * @param properties * The connection properties. * @return The new connection pool. */ public static ObjectPool createConnectionPool(String uri, Properties properties) { // Create an ObjectPool that will serve as the actual pool of // connections ObjectPool result = new GenericObjectPool(null); // Create a ConnectionFactory that the pool will use to create // Connections ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(uri, properties); // Create the PoolableConnectionFactory, which wraps the "real" // Connections created by the ConnectionFactory with // the classes that implement the pooling functionality. PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, result, null, null, false, false); // To remove warnings poolableConnectionFactory.getPool(); return result; }