List of usage examples for org.apache.commons.dbcp2 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.ofbiz.core.entity.transaction.DBCPConnectionFactory.java
private static void initConnectionPoolSettings(final BasicDataSource dataSource, final ConnectionPoolInfo poolInfo) { if (poolInfo == null) { return;/*from w ww . j ava 2 s .c o m*/ } dataSource.setMaxTotal(poolInfo.getMaxSize()); dataSource.setMinIdle(poolInfo.getMinSize()); dataSource.setMaxIdle(poolInfo.getMaxIdle()); dataSource.setMaxWaitMillis(poolInfo.getMaxWait()); dataSource.setDefaultCatalog(poolInfo.getDefaultCatalog()); if (poolInfo.getInitialSize() != null) { dataSource.setInitialSize(poolInfo.getInitialSize()); } if (isNotEmpty(poolInfo.getValidationQuery())) { // testOnBorrow defaults to true when this is set, but can still be forced to false dataSource.setTestOnBorrow(poolInfo.getTestOnBorrow() == null || poolInfo.getTestOnBorrow()); if (poolInfo.getTestOnReturn() != null) { dataSource.setTestOnReturn(poolInfo.getTestOnReturn()); } if (poolInfo.getTestWhileIdle() != null) { dataSource.setTestWhileIdle(poolInfo.getTestWhileIdle()); } dataSource.setValidationQuery(poolInfo.getValidationQuery()); if (poolInfo.getValidationQueryTimeout() != null) { dataSource.setValidationQueryTimeout(poolInfo.getValidationQueryTimeout()); } } if (poolInfo.getPoolPreparedStatements() != null) { dataSource.setPoolPreparedStatements(poolInfo.getPoolPreparedStatements()); if (dataSource.isPoolPreparedStatements() && poolInfo.getMaxOpenPreparedStatements() != null) { dataSource.setMaxOpenPreparedStatements(poolInfo.getMaxOpenPreparedStatements()); } } if (poolInfo.getRemoveAbandonedOnBorrow() != null) { dataSource.setRemoveAbandonedOnBorrow(poolInfo.getRemoveAbandonedOnBorrow()); } if (poolInfo.getRemoveAbandonedOnMaintanance() != null) { dataSource.setRemoveAbandonedOnMaintenance(poolInfo.getRemoveAbandonedOnMaintanance()); } if (poolInfo.getRemoveAbandonedTimeout() != null) { dataSource.setRemoveAbandonedTimeout(poolInfo.getRemoveAbandonedTimeout()); } if (poolInfo.getMinEvictableTimeMillis() != null) { dataSource.setMinEvictableIdleTimeMillis(poolInfo.getMinEvictableTimeMillis()); } if (poolInfo.getNumTestsPerEvictionRun() != null) { dataSource.setNumTestsPerEvictionRun(poolInfo.getNumTestsPerEvictionRun()); } if (poolInfo.getTimeBetweenEvictionRunsMillis() != null) { dataSource.setTimeBetweenEvictionRunsMillis(poolInfo.getTimeBetweenEvictionRunsMillis()); } }
From source file:pgsql.connection.PooledConnectionFactory.java
private void initializeConnectionPool(BasicDataSource connectionPool, URI databaseUri) { final String dbUrl = "jdbc:postgresql://" + databaseUri.getHost() + databaseUri.getPath(); if (databaseUri.getUserInfo() != null) { connectionPool.setUsername(databaseUri.getUserInfo().split(":")[0]); connectionPool.setPassword(databaseUri.getUserInfo().split(":")[1]); }//from w w w . j av a2 s . co m connectionPool.setDriverClassName("org.postgresql.Driver"); connectionPool.setUrl(dbUrl); connectionPool.setInitialSize(1); }
From source file:rzd.vivc.documentexamination.configuration.SpringDateConfigMySQL.java
@Bean //? ? //ww w .ja v a2 s. c o m public DataSource dataSource() { //MySQL BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); //? ds.setUrl("jdbc:mysql://localhost:3306/dateexamination"); ds.setUsername("root"); /* ds.setUsername("exam"); ds.setPassword("exam68");*/ // ds.setInitialSize(5); ds.setMaxIdle(5); ds.setMaxTotal(15); return ds; }
From source file:tilda.db.ConnectionPool.java
public static void init(String Id, String Driver, String DB, String User, String Pswd, int InitialSize, int MaxSize) { if (_DataSourcesById.get(Id) == null) synchronized (_DataSourcesById) { if (_DataSourcesById.get(Id) == null) // Definitely no connection pool by that name {/*ww w .j av a 2 s. co m*/ String Sig = DB + "``" + User; BasicDataSource BDS = _DataSourcesBySig.get(Sig); // Let's see if that DB definition is already there if (BDS == null) { LOG.info("Initializing a fresh pool for Id=" + Id + ", DB=" + DB + ", User=" + User + ", and Pswd=Shhhhhhh!"); BDS = new BasicDataSource(); BDS.setDriverClassName(Driver); BDS.setUrl(DB); if (TextUtil.isNullOrEmpty(Pswd) == false && TextUtil.isNullOrEmpty(User) == false) { BDS.setUsername(User); BDS.setPassword(Pswd); } BDS.setInitialSize(InitialSize); BDS.setMaxTotal(MaxSize); BDS.setDefaultAutoCommit(false); BDS.setDefaultTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); BDS.setDefaultQueryTimeout(20000); _DataSourcesBySig.put(Sig, BDS); } else { LOG.info("Merging pool with ID " + Id + " into prexisting pool " + Sig); if (BDS.getInitialSize() < InitialSize) BDS.setInitialSize(InitialSize); if (BDS.getMaxTotal() < MaxSize) BDS.setMaxTotal(MaxSize); } _DataSourcesById.put(Id, BDS); } } }
From source file:ws.rocket.sqlstore.test.SqlStoreTest.java
@BeforeClass public void setUp() throws SQLException, IOException { ResourceBundle bundle = ResourceBundle.getBundle("ws.rocket.sqlstore.test.test"); File dbPath = new File(bundle.getString("jdbc.dbPath")); if (!dbPath.exists()) { dbPath.mkdirs();/*from w ww . j av a2 s.c om*/ } System.setProperty("derby.system.home", dbPath.getCanonicalPath()); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(bundle.getString("jdbc.driver")); ds.setUrl(bundle.getString("jdbc.url")); ds.setDefaultReadOnly(true); ds.setDefaultAutoCommit(false); ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); ds.setInitialSize(Integer.parseInt(bundle.getString("jdbc.initialConnections"))); this.dataSource = ds; boolean tableExists; try (Connection c = this.dataSource.getConnection()) { DatabaseMetaData meta = c.getMetaData(); try (ResultSet rs = meta.getTables(null, "SQLSTORE", "PERSON", new String[] { "TABLE" })) { tableExists = rs.next(); } } if (tableExists) { dropTables(); } }