List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxWait
public synchronized void setMaxWait(long maxWait)
From source file:org.lucane.server.database.DatabaseAbstractionLayer.java
/** * DatabaseLayer Factory/*from w ww.j ava2 s .c o m*/ * Get the layer corresponding to the driver */ public static DatabaseAbstractionLayer createLayer(ServerConfig config) throws Exception { Class.forName(config.getDbDriver()); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(config.getDbDriver()); ds.setUsername(config.getDbLogin()); ds.setPassword(config.getDbPassword()); ds.setUrl(config.getDbUrl()); ds.setPoolPreparedStatements(true); ds.setInitialSize(config.getDbPoolInitialSize()); ds.setMaxActive(config.getDbPoolMaxActive()); ds.setMaxIdle(config.getDbPoolMaxIdle()); ds.setMinIdle(config.getDbPoolMinIdle()); ds.setMaxWait(config.getDbPoolMaxWait()); Logging.getLogger() .info("Pool initialized (" + "initial size=" + config.getDbPoolInitialSize() + ", max active=" + config.getDbPoolMaxActive() + ", max idle=" + config.getDbPoolMaxIdle() + ", min idle=" + config.getDbPoolMinIdle() + ", max wait=" + config.getDbPoolMaxWait() + ")"); //-- dynamic layer loading Class klass = Class.forName(config.getDbLayer()); Class[] types = { DataSource.class }; Object[] values = { ds }; Constructor constr = klass.getConstructor(types); return (DatabaseAbstractionLayer) constr.newInstance(values); }
From source file:org.ngrinder.infra.config.Database.java
/** * Setup the database common features.//ww w . j a va 2s . com * * @param dataSource datasource */ protected void setupCommon(BasicDataSource dataSource) { dataSource.setDriverClassName(getJdbcDriverName()); dataSource.setInitialSize(DB_INITIAL_SIZE); dataSource.setMaxActive(DB_MAX_ACTIVE); dataSource.setMinIdle(DB_MIN_IDLE); dataSource.setMaxWait(DB_MAX_WAIT); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(DB_MAX_OPEN_PREPARED_STATEMENTS); dataSource.setTestWhileIdle(true); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(true); dataSource.setValidationQuery("SELECT 1"); }
From source file:org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledDatasourceService.java
private DataSource convert(IDatasource datasource) { BasicDataSource basicDatasource = new BasicDataSource(); basicDatasource.setDriverClassName(datasource.getDriverClass()); basicDatasource.setMaxActive(datasource.getMaxActConn()); basicDatasource.setMaxIdle(datasource.getIdleConn()); basicDatasource.setMaxWait(datasource.getWait()); basicDatasource.setUrl(datasource.getUrl()); basicDatasource.setUsername(datasource.getUserName()); basicDatasource.setPassword(datasource.getPassword()); basicDatasource.setValidationQuery(datasource.getQuery()); return basicDatasource; }
From source file:org.pinus4j.cluster.impl.AppDBClusterImpl.java
@Override public void buildDataSource(DBInfo dbConnInfo) throws LoadConfigException { AppDBInfo appDbConnInfo = (AppDBInfo) dbConnInfo; LOG.info(dbConnInfo.toString());//from w w w .ja v a 2 s.c o m try { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(enumDb.getDriverClass()); ds.setUsername(appDbConnInfo.getUsername()); ds.setPassword(appDbConnInfo.getPassword()); ds.setUrl(appDbConnInfo.getUrl()); // ? Map<String, Object> dbConnPoolInfo = appDbConnInfo.getConnPoolInfo(); ds.setValidationQuery("SELECT 1"); ds.setMaxActive((Integer) dbConnPoolInfo.get(Const.PROP_MAXACTIVE)); ds.setMinIdle((Integer) dbConnPoolInfo.get(Const.PROP_MINIDLE)); ds.setMaxIdle((Integer) dbConnPoolInfo.get(Const.PROP_MAXIDLE)); ds.setInitialSize((Integer) dbConnPoolInfo.get(Const.PROP_INITIALSIZE)); ds.setRemoveAbandoned((Boolean) dbConnPoolInfo.get(Const.PROP_REMOVEABANDONED)); ds.setRemoveAbandonedTimeout((Integer) dbConnPoolInfo.get(Const.PROP_REMOVEABANDONEDTIMEOUT)); ds.setMaxWait((Integer) dbConnPoolInfo.get(Const.PROP_MAXWAIT)); ds.setTimeBetweenEvictionRunsMillis( (Integer) dbConnPoolInfo.get(Const.PROP_TIMEBETWEENEVICTIONRUNSMILLIS)); ds.setNumTestsPerEvictionRun((Integer) dbConnPoolInfo.get(Const.PROP_NUMTESTSPEREVICTIONRUN)); ds.setMinEvictableIdleTimeMillis((Integer) dbConnPoolInfo.get(Const.PROP_MINEVICTABLEIDLETIMEMILLIS)); dbConnInfo.setDatasource(ds); } catch (Exception e) { throw new LoadConfigException(e); } }
From source file:org.sbq.batch.configurations.DatabaseConfiguration.java
@Bean(destroyMethod = "close") public DataSource dbcpDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/batch_db"); dataSource.setUsername("root"); dataSource.setPassword(""); dataSource.setMaxActive(20);/*from w ww. j av a 2 s. co m*/ dataSource.setMaxIdle(20); dataSource.setMaxWait(10000); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1"); dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); return dataSource; }
From source file:org.wsm.database.tools.util.MysqlBaseLoadTestConnectionManager.java
public BasicDataSource getBasicDataSourceSetup() { BasicDataSource bds = super.setupBasicDataSourcePooling(); bds.setMaxActive(150);/*from ww w . j a v a 2 s . c om*/ bds.setMaxIdle(8); bds.setMaxWait(3000); return bds; }
From source file:org.wso2.carbon.registry.core.jdbc.utils.RegistryDataSource.java
public RegistryDataSource(DataBaseConfiguration config) { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setUrl(config.getDbUrl()); basicDataSource.setDriverClassName(config.getDriverName()); basicDataSource.setUsername(config.getUserName()); basicDataSource.setPassword(config.getResolvedPassword()); if (config.getMaxActive() != null) { basicDataSource.setMaxActive(Integer.parseInt(config.getMaxActive())); } else {//from w ww . j av a 2 s. c o m basicDataSource.setMaxActive(DEFAULT_MAX_ACTIVE); } if (config.getMaxWait() != null) { basicDataSource.setMaxWait(Integer.parseInt(config.getMaxWait())); } else { basicDataSource.setMaxWait(DEFAULT_MAX_WAIT); } if (config.getMaxIdle() != null) { basicDataSource.setMaxIdle(Integer.parseInt(config.getMaxIdle())); } if (config.getMinIdle() != null) { basicDataSource.setMinIdle(Integer.parseInt(config.getMinIdle())); } else { basicDataSource.setMinIdle(DEFAULT_MIN_IDLE); } this.dataSource = basicDataSource; }
From source file:se.unlogic.hierarchy.core.utils.DBCPUtils.java
public static BasicDataSource createConnectionPool(DataSourceDescriptor dataSourceDescriptor) { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(dataSourceDescriptor.getDriver()); basicDataSource.setUsername(dataSourceDescriptor.getUsername()); basicDataSource.setPassword(dataSourceDescriptor.getPassword()); basicDataSource.setUrl(dataSourceDescriptor.getUrl()); basicDataSource.setDefaultCatalog(dataSourceDescriptor.getDefaultCatalog()); basicDataSource.setLogAbandoned(dataSourceDescriptor.logAbandoned()); basicDataSource.setRemoveAbandoned(dataSourceDescriptor.removeAbandoned()); if (dataSourceDescriptor.getRemoveTimeout() != null) { basicDataSource.setRemoveAbandonedTimeout(dataSourceDescriptor.getRemoveTimeout()); }/* w w w . j av a 2s . c om*/ basicDataSource.setTestOnBorrow(dataSourceDescriptor.testOnBorrow()); basicDataSource.setValidationQuery(dataSourceDescriptor.getValidationQuery()); basicDataSource.setMaxWait(dataSourceDescriptor.getMaxWait()); basicDataSource.setMaxActive(dataSourceDescriptor.getMaxActive()); basicDataSource.setMaxIdle(dataSourceDescriptor.getMaxIdle()); basicDataSource.setMinIdle(dataSourceDescriptor.getMinIdle()); return basicDataSource; }
From source file:xbird.util.jdbc.datasource.DbcpDataSourceProvider.java
public DataSource setupDataSource(String connectURI) { // creates DataSource BasicDataSource ds = new BasicDataSource(); // for debugging. if (Settings.isLoggingEnabled) { ds.setAccessToUnderlyingConnectionAllowed(true); }//from ww w. java2 s . com ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind"))); // sets up DataSource ds.setUrl(connectURI); final String dbuser = Settings.get("xbird.db.user"); final String dbpasswd = Settings.get("xbird.db.passwd"); if (dbuser != null && dbuser.length() != 0) { ds.setUsername(dbuser); ds.setPassword(dbpasswd); } // addtinal settings. final String maxactive = Settings.get("xbird.db.pool.maxactive"); if (maxactive != null) ds.setMaxActive(Integer.parseInt(maxactive)); final String maxidle = Settings.get("xbird.db.pool.maxidle"); if (maxidle != null) ds.setMaxIdle(Integer.parseInt(maxidle)); final String maxwait = Settings.get("xbird.db.pool.maxwait"); ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait)); ds.setDefaultAutoCommit(true); //ds.setDefaultReadOnly(false); final String initialsize = Settings.get("xbird.db.pool.initialsize"); ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE : Integer.parseInt(initialsize)); // sets up for PreparedStatements. ds.setPoolPreparedStatements(true); final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size"); ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS : Integer.parseInt(maxOpenPreparedStatements)); return ds; }