txIsolationLevel.getCode()); dataSource = new PoolingDataSource(connectionPool);
return new PoolingDataSource(objectPool);
/** * Sets up a pooling data source for connection pooling. * This can be used if the application server does not have a pooling * dataSource already configured. * * <p>This takes a normal jdbc connection string, and requires a jdbc * driver to be loaded, and then uses a * {@link DriverManagerConnectionFactory} to create connections to the * database. * * <p>An alternative method of configuring a pooling driver is to use an * external configuration file. See the the Apache jakarta-commons * commons-pool documentation. * * @param key Identifies which connection factory to use. A typical key is * a JDBC connect string, since each JDBC connect string requires a * different connection factory. * @param connectionFactory Creates connections from an underlying * JDBC connect string or DataSource * @return a pooling DataSource object */ public synchronized DataSource getPoolingDataSource( Object key, ConnectionFactory connectionFactory) { ObjectPool connectionPool = getPool(key, connectionFactory); // create pooling datasource return new PoolingDataSource(connectionPool); }
private static DataSource setupDataSource(String uri, String user, String pass) { if (LOG.isDebugEnabled()) { StringBuilder sb = new StringBuilder("Creating database session pool: ") .append("URL: {} User: {} Password: {}"); LOG.debug(sb.toString(), new Object[]{uri, user, (pass != null && pass.trim().length() != 0) ? "****" : pass}); } ConnectionFactory cf = new DriverManagerConnectionFactory(uri, user, pass); ObjectPool pool = new GenericObjectPool(); new PoolableConnectionFactory(cf, pool, null, null, false, false); return new PoolingDataSource(pool); }
public void setup( Properties prop ) { this.prop=prop; GenericObjectPool.Config conPoolCfg = new GenericObjectPool.Config(); conPoolCfg.maxActive = Integer.parseInt( prop.getProperty( "connectionPoolMaxSize", "15" ) ); conPoolCfg.maxIdle = Integer.parseInt( prop.getProperty( "connectionPoolMaxIdle", "8" ) ); conPoolCfg.maxWait = Integer.parseInt( prop.getProperty( "connectionPoolMaxWait", "60000" ) ); conPoolCfg.minIdle = Integer.parseInt( prop.getProperty( "connectionPoolMinSize", "2" ) ); ObjectPool connectionPool = new GenericObjectPool( null, conPoolCfg ); try { Class.forName( prop.getProperty( "jdbcDriver" ) ); } catch( ClassNotFoundException e ) { e.printStackTrace(); throw new RuntimeException(); } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( prop.getProperty( "jdbcUrl" ), prop.getProperty( "jdbcUser" ), prop.getProperty( "jdbcPassword" ) ); new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); PoolingDataSource dataSource = new PoolingDataSource(connectionPool); ds = dataSource; }
public static DataSource buildDataSource(String user, String pass, String driver, String url) { DataSource ds; try { Class.forName(driver); } catch (ClassNotFoundException ignore) { } GenericObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( url, user, pass); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true); return new PoolingDataSource(connectionPool); }
public static DataSource buildDataSource(String user, String pass, String driver, String url) { DataSource ds; try { Class.forName(driver); } catch (ClassNotFoundException ignore) { } GenericObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( url, user, pass); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true); return new PoolingDataSource(connectionPool); }
/** * <p> * Default Constructor * </p>. */ public DataSourceWorkflowRepositoryFactory() throws WorkflowException { String jdbcUrl, user, pass, driver; jdbcUrl = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.url"); user = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.user"); pass = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.pass"); driver = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.driver"); try { Class.forName(driver); } catch (ClassNotFoundException e) { throw new WorkflowException("Cannot load driver: " + driver); } GenericObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( jdbcUrl, user, pass); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true); dataSource = new PoolingDataSource(connectionPool); }
/** * Creates the actual data source instance. This method only exists so * subclasses can replace the implementation class. * * @throws SQLException if unable to create a datasource instance */ protected void createDataSourceInstance() throws SQLException { PoolingDataSource pds = new PoolingDataSource(connectionPool); pds.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed()); pds.setLogWriter(logWriter); dataSource = pds; }
DataSource createDataSource() { boolean connectionNoWrap = config.getBoolean(CONNECTION_NOWRAP, false); ObjectPool connectionPool = createConnectionPool(); PoolingDataSource dataSource = new PoolingDataSource(connectionPool); dataSource.setAccessToUnderlyingConnectionAllowed(connectionNoWrap); return dataSource; }
/** * Creates the actual data source instance. This method only exists so * subclasses can replace the implementation class. * * @throws SQLException if unable to create a datasource instance */ protected void createDataSourceInstance() throws SQLException { PoolingDataSource pds = new PoolingDataSource(connectionPool); pds.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed()); pds.setLogWriter(logWriter); dataSource = pds; }
/** * <p> * Default Constructor * </p>. */ public DataSourceWorkflowRepositoryFactory() throws WorkflowException { String jdbcUrl, user, pass, driver; jdbcUrl = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.url"); user = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.user"); pass = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.pass"); driver = System .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.driver"); try { Class.forName(driver); } catch (ClassNotFoundException e) { throw new WorkflowException("Cannot load driver: " + driver); } GenericObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( jdbcUrl, user, pass); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true); dataSource = new PoolingDataSource(connectionPool); }
public static DataSource getPoolingDataSourceFromConf(Configuration conf) { final ConnectionFactory cf = new DriverManagerConnectionFactory( conf.get(LensConfConstants.SERVER_DB_JDBC_URL, LensConfConstants.DEFAULT_SERVER_DB_JDBC_URL), conf.get(LensConfConstants.SERVER_DB_JDBC_USER, LensConfConstants.DEFAULT_SERVER_DB_USER), conf.get(LensConfConstants.SERVER_DB_JDBC_PASS, LensConfConstants.DEFAULT_SERVER_DB_PASS)); final GenericObjectPool connectionPool = new GenericObjectPool(); connectionPool.setTestOnBorrow(false); connectionPool.setTestOnReturn(false); connectionPool.setTestWhileIdle(true); new PoolableConnectionFactory(cf, connectionPool, null, conf.get(LensConfConstants.SERVER_DB_VALIDATION_QUERY, LensConfConstants.DEFAULT_SERVER_DB_VALIDATION_QUERY), false, false).setDefaultAutoCommit(true); return new PoolingDataSource(connectionPool); }
private DataSource setupDataSource(String connectURI, IModule module) { // Ensure the JDBC driver class is loaded // TODO - AHK final List<? extends ITypeLoader> typeLoaders = module.getTypeLoaders(IDefaultTypeLoader.class); ((IDefaultTypeLoader)typeLoaders.get(0)).loadClass(getDriverName(connectURI)); // TODO - AHK - Figure out the implications of the connection pooling when the jdbc url changes GenericObjectPool connectionPool = new GenericObjectPool(null); connectionPool.setMinIdle( 1 ); connectionPool.setMaxActive( 10 ); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true); return new PoolingDataSource(connectionPool); } }
connPool = new PoolingDataSource(objectPool); } else { throw new RuntimeException("Unknown JDBC connection pooling " + connectionPooler);
/** * Creates a new {@link ConnectionPool} instance. * * @param id * @param connectURI * @param user * @param password * @param readOnly * @param minIdle * @param maxActive */ public ConnectionPool( String id, String connectURI, String user, String password, boolean readOnly, int minIdle, int maxActive ) { this.id = id; pool = new GenericObjectPool<Connection>( null ); pool.setMinIdle( minIdle ); pool.setMaxActive( maxActive ); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, user, password ); // TODO make this configurable new PoolableConnectionFactory( connectionFactory, pool, null, null, readOnly, true ); ds = new PoolingDataSource( pool ); // needed, so users can retrieve the underlying connection from pooled // connections, e.g. to access the // LargeObjectManager from a PGConnection ds.setAccessToUnderlyingConnectionAllowed( true ); }
/** * This method must be called from the start method. */ protected final void createDataSource() { connectionPool = new GenericObjectPool(null); connectionPool.setMaxActive(CONNECTION_POOL_SIZE); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( getJdbcUrl(), getUsername(), getPassword()); // The following line must be kept in although it does not appear to be // used, the constructor regsiters the // constructed object at the connection pool. PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true); ingoredVariable(poolableConnectionFactory); itsDataSource = new PoolingDataSource(connectionPool); }
return new PoolingDataSource(connectionPool); } catch (ClassNotFoundException e) { throw new InitializationException("An error occurred during creation of new datasource object", e);
return new PoolingDataSource(connectionPool); } catch (ClassNotFoundException e) { throw new InitializationException("An error occurred during creation of new datasource object", e);
new PoolingDataSource(connectionPool);