List of usage examples for org.apache.commons.dbcp BasicDataSource setInitialSize
public synchronized void setInitialSize(int initialSize)
Sets the initial size of the connection pool.
Note: this method currently has no effect once the pool has been initialized.
From source file:org.ngrinder.infra.config.Database.java
/** * Setup the database common features./*from w w w .ja va 2s .c o m*/ * * @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.pinus4j.cluster.impl.AppDBClusterImpl.java
@Override public void buildDataSource(DBInfo dbConnInfo) throws LoadConfigException { AppDBInfo appDbConnInfo = (AppDBInfo) dbConnInfo; LOG.info(dbConnInfo.toString());//www .j av a 2 s .c om 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.plista.kornakapi.core.storage.MySqlStorage.java
public MySqlStorage(StorageConfiguration storageConf, String label, BasicDataSource dataSource) { dataSource.setDriverClassName(storageConf.getJdbcDriverClass()); dataSource.setUrl(storageConf.getJdbcUrl()); dataSource.setUsername(storageConf.getUsername()); dataSource.setPassword(storageConf.getPassword()); //TODO should be made configurable dataSource.setMaxActive(10);//from w w w.j a v a2s . c o m dataSource.setMinIdle(5); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1;"); dataSource.setTestOnBorrow(false); dataSource.setTestOnReturn(false); dataSource.setTestWhileIdle(true); dataSource.setTimeBetweenEvictionRunsMillis(5000); dataModel = new LabeledMySQLJDBCDataModel(dataSource, "taste_preferences", "user_id", "item_id", "preference", "timestamp", "taste_candidates", "label", label); this.dataSource = dataSource; this.timeWindow = storageConf.getTimeWindow(); if (timeWindow % 6 != 0 || timeWindow == 0) { timeWindow = 24; } }
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 a v a 2s .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.tdmx.lib.control.datasource.DynamicDataSource.java
private synchronized void createDataSource(DatabaseConnectionInfo dci) throws SQLException { // race condition avoidance if (connectionDataSourceMap.get(dci) != null) { return;/* w w w .j a v a 2 s . c o m*/ } BasicDataSource bds = new BasicDataSource(); bds.setUrl(dci.getUrl()); bds.setDriverClassName(dci.getDriverClassname()); bds.setUsername(dci.getUsername()); bds.setPassword(dci.getPassword()); bds.setMaxActive(100); bds.setMinIdle(0); bds.setInitialSize(1); bds.setMinEvictableIdleTimeMillis(60000); bds.setLogWriter(logWriter); connectionDataSourceMap.put(dci, bds); }
From source file:org.xbib.io.jdbc.SQLConnectionFactory.java
/** * Get connection/* ww w .j a v a 2 s .c o m*/ * * @param uri * * @return an SQL connection * * @throws java.io.IOException */ @Override public Connection<SQLSession> getConnection(final URI uri) throws IOException { this.properties = URIUtil.getPropertiesFromURI(uri); Context context = null; DataSource ds = null; for (String name : new String[] { "jdbc/" + properties.getProperty("host"), "java:comp/env/" + properties.getProperty("scheme") + ":" + properties.getProperty("host") + ":" + properties.getProperty("port") }) { this.jndiName = name; try { context = new InitialContext(); Object o = context.lookup(jndiName); if (o instanceof DataSource) { logger.info("DataSource ''{}'' found in naming context", jndiName); ds = (DataSource) o; break; } else { logger.warn("JNDI object {} not a DataSource class: {} - ignored", jndiName, o.getClass()); } } catch (NameNotFoundException e) { logger.warn("DataSource ''{}'' not found in context", jndiName); } catch (NamingException e) { logger.warn(e.getMessage(), e); } } try { if (ds == null) { BasicDataSource bsource = new BasicDataSource(); bsource.setDriverClassName(properties.getProperty("driverClassName")); String url = properties.getProperty("jdbcScheme") + properties.getProperty("host") + ":" + properties.getProperty("port") + ("jdbc:oracle:thin:@".equals(properties.getProperty("jdbcScheme")) ? ":" : "/") + properties.getProperty("cluster"); bsource.setUrl(url); if (properties.containsKey("username")) { bsource.setUsername(properties.getProperty("username")); } if (properties.containsKey("password")) { bsource.setPassword(properties.getProperty("password")); } if (properties.containsKey("n")) { bsource.setInitialSize(Integer.parseInt(properties.getProperty("n"))); bsource.setMaxActive(Integer.parseInt(properties.getProperty("n"))); } // Other BasicDataSource settings, not used yet: // setAccessToUnderlyingConnectionAllowed(boolean allow) // setDefaultAutoCommit(boolean defaultAutoCommit) // setDefaultCatalog(String defaultCatalog) // setDefaultReadOnly(boolean defaultReadOnly) // setDefaultTransactionIsolation(int defaultTransactionIsolation) // setLogAbandoned(boolean logAbandoned) // setLoginTimeout(int loginTimeout) // setLogWriter(PrintWriter logWriter) // setMaxIdle(int maxIdle) // setMaxOpenPreparedStatements(int maxOpenStatements) // setMaxWait(long maxWait) // setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) // setMinIdle(int minIdle) // setNumTestsPerEvictionRun(int numTestsPerEvictionRun) // setPoolPreparedStatements(boolean poolingStatements) // setTestOnBorrow(boolean testOnBorrow) // setTestOnReturn(boolean testOnReturn) // setTestWhileIdle(boolean testWhileIdle) // setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) // setValidationQuery(String validationQuery) context.bind(jndiName, bsource); ds = (DataSource) bsource; } } catch (NamingException e) { throw new IOException(e.getMessage()); } try { ds.getConnection().setAutoCommit("false".equals(properties.getProperty("autoCommit")) ? false : true); } catch (SQLException e) { throw new IOException(e.getMessage()); } return new SQLConnection(ds); }
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 w w w . ja va 2 s . c o m*/ 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; }