List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxActive
public synchronized void setMaxActive(int maxActive)
From source file:org.geotoolkit.coverage.postgresql.PGCoverageStoreFactory.java
/** * Creates the datasource for the coverage store. *///w ww .j a v a 2 s. c o m private DataSource createDataSource(final ParameterValueGroup params) throws IOException { //create a datasource final BasicDataSource dataSource = new BasicDataSource(); // driver dataSource.setDriverClassName(getDriverClassName()); // url dataSource.setUrl(getJDBCUrl(params)); // username final String user = (String) params.parameter(USER.getName().toString()).getValue(); dataSource.setUsername(user); // password final String passwd = (String) params.parameter(PASSWORD.getName().toString()).getValue(); if (passwd != null) { dataSource.setPassword(passwd); } // max wait final Integer maxWait = (Integer) params.parameter(MAXWAIT.getName().toString()).getValue(); if (maxWait != null && maxWait != -1) { dataSource.setMaxWait(maxWait * 1000); } // connection pooling options final Integer minConn = (Integer) params.parameter(MINCONN.getName().toString()).getValue(); if (minConn != null) { dataSource.setMinIdle(minConn); } final Integer maxConn = (Integer) params.parameter(MAXCONN.getName().toString()).getValue(); if (maxConn != null) { dataSource.setMaxActive(maxConn); } final Boolean validate = (Boolean) params.parameter(VALIDATECONN.getName().toString()).getValue(); if (validate != null && validate && getValidationQuery() != null) { dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(getValidationQuery()); } // might need this dataSource.setAccessToUnderlyingConnectionAllowed(true); return new DBCPDataSource(dataSource); }
From source file:org.geotoolkit.db.AbstractJDBCFeatureStoreFactory.java
/** * Create a datasource using given parameters. *//*from w ww. j a v a 2 s .c o m*/ protected DataSource createDataSource(final ParameterValueGroup params) throws IOException { //create a datasource final BasicDataSource dataSource = new BasicDataSource(); // some default data source behaviour dataSource.setPoolPreparedStatements(false); // driver dataSource.setDriverClassName(getDriverClassName()); // url dataSource.setUrl(getJDBCUrl(params)); // username final String user = (String) params.parameter(USER.getName().toString()).getValue(); dataSource.setUsername(user); // password final String passwd = (String) params.parameter(PASSWORD.getName().toString()).getValue(); if (passwd != null) { dataSource.setPassword(passwd); } // max wait final Integer maxWait = (Integer) params.parameter(MAXWAIT.getName().toString()).getValue(); if (maxWait != null && maxWait != -1) { dataSource.setMaxWait(maxWait * 1000); } // connection pooling options final Integer minConn = (Integer) params.parameter(MINCONN.getName().toString()).getValue(); if (minConn != null) { dataSource.setMinIdle(minConn); } final Integer maxConn = (Integer) params.parameter(MAXCONN.getName().toString()).getValue(); if (maxConn != null) { dataSource.setMaxActive(maxConn); } final Boolean validate = (Boolean) params.parameter(VALIDATECONN.getName().toString()).getValue(); if (validate != null && validate && getValidationQuery() != null) { dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(getValidationQuery()); } // allow manipulating connections for possible tuning. dataSource.setAccessToUnderlyingConnectionAllowed(true); return new DBCPDataSource(dataSource); }
From source file:org.geotools.jdbc.JDBCDataStoreFactory.java
/** * DataSource access allowing SQL use: intended to allow client code to query available schemas. * <p>/*from w w w . ja v a2s.c o m*/ * This DataSource is the clients responsibility to close() when they are finished using it. * </p> * @param params Map of connection parameter. * @return DataSource for SQL use * @throws IOException */ public BasicDataSource createDataSource(Map params) throws IOException { //create a datasource BasicDataSource dataSource = new BasicDataSource(); // driver dataSource.setDriverClassName(getDriverClassName()); // url dataSource.setUrl(getJDBCUrl(params)); // username String user = (String) USER.lookUp(params); dataSource.setUsername(user); // password String passwd = (String) PASSWD.lookUp(params); if (passwd != null) { dataSource.setPassword(passwd); } // max wait Integer maxWait = (Integer) MAXWAIT.lookUp(params); if (maxWait != null && maxWait != -1) { dataSource.setMaxWait(maxWait * 1000); } // connection pooling options Integer minConn = (Integer) MINCONN.lookUp(params); if (minConn != null) { dataSource.setMinIdle(minConn); } Integer maxConn = (Integer) MAXCONN.lookUp(params); if (maxConn != null) { dataSource.setMaxActive(maxConn); } Boolean validate = (Boolean) VALIDATECONN.lookUp(params); if (validate != null && validate && getValidationQuery() != null) { dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(getValidationQuery()); } // some datastores might need this dataSource.setAccessToUnderlyingConnectionAllowed(true); return dataSource; }
From source file:org.geotools.jdbc.JDBCTestSetup.java
/** * Creates a data source by reading properties from a file called 'db.properties', * located paralell to the test setup instance. *//* ww w . j a v a 2s . com*/ protected DataSource createDataSource() throws IOException { Properties db = fixture; BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(db.getProperty("driver")); dataSource.setUrl(db.getProperty("url")); if (db.containsKey("user")) { dataSource.setUsername(db.getProperty("user")); } else if (db.containsKey("username")) { dataSource.setUsername(db.getProperty("username")); } if (db.containsKey("password")) { dataSource.setPassword(db.getProperty("password")); } dataSource.setPoolPreparedStatements(true); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMinIdle(1); dataSource.setMaxActive(4); // if we cannot get a connection within 5 seconds give up dataSource.setMaxWait(5000); initializeDataSource(dataSource, db); // return a closeable data source (DisposableDataSource interface) // so that the connection pool will be tore down on datastore dispose return new DBCPDataSource(dataSource); }
From source file:org.geotools.referencing.factory.epsg.OracleDialectEpsgMediatorStarvationOnlineStressTest.java
protected DataSource connect(String user, String password, String url, Properties params) throws SQLException { //DataSource origional = super.connect( user, password, url, params ); BasicDataSource origional = new BasicDataSource(); origional.setDriverClassName("oracle.jdbc.driver.OracleDriver"); origional.setUsername(user);//from w w w . j a v a2 s . co m origional.setPassword(password); origional.setUrl(url); origional.setMaxActive(10); origional.setMaxIdle(1); return origional; }
From source file:org.geowebcache.diskquota.jdbc.JDBCQuotaStoreFactory.java
private DataSource getDataSource(JDBCConfiguration config) throws ConfigurationException { try {/* w w w . j a v a 2 s .co m*/ DataSource ds = null; if (config.getJNDISource() != null) { InitialContext context = new InitialContext(); ds = (DataSource) context.lookup(config.getJNDISource()); } else if (config.getConnectionPool() != null) { ConnectionPoolConfiguration cp = config.getConnectionPool(); BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(cp.getDriver()); bds.setUrl(cp.getUrl()); bds.setUsername(cp.getUsername()); bds.setPassword(cp.getPassword()); bds.setPoolPreparedStatements(true); bds.setMaxOpenPreparedStatements(cp.getMaxOpenPreparedStatements()); bds.setMinIdle(cp.getMinConnections()); bds.setMaxActive(cp.getMaxConnections()); bds.setMaxWait(cp.getConnectionTimeout() * 1000); bds.setValidationQuery(cp.getValidationQuery()); ds = bds; } // verify the datasource works Connection c = null; try { c = ds.getConnection(); } catch (SQLException e) { throw new ConfigurationException("Failed to get a database connection: " + e.getMessage(), e); } finally { if (c != null) { try { c.close(); } catch (SQLException e) { // nothing we can do about it, but at least let the admin know log.debug("An error occurred while closing the test JDBC connection: " + e.getMessage(), e); } } } return ds; } catch (NamingException e) { throw new ConfigurationException("Failed to locate the data source in JNDI", e); } }
From source file:org.geowebcache.diskquota.jdbc.JDBCQuotaStoreFactory.java
/** * Prepares a simple data source for the embedded H2 * // w w w .j a v a 2 s . c o m * @param cacheDirFinder * @return * @throws ConfigurationException */ private DataSource getH2DataSource(DefaultStorageFinder cacheDirFinder) throws ConfigurationException { File storeDirectory = new File(cacheDirFinder.getDefaultPath(), "diskquota_page_store_h2"); storeDirectory.mkdirs(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); String database = new File(storeDirectory, "diskquota").getAbsolutePath(); dataSource.setUrl("jdbc:h2:" + database); dataSource.setUsername("sa"); dataSource.setPoolPreparedStatements(true); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMinIdle(1); dataSource.setMaxActive(-1); // boundless dataSource.setMaxWait(5000); return dataSource; }
From source file:org.jfaster.mango.support.DataSourceConfig.java
public static DataSource getDataSource(int i) { String driverClassName = getDriverClassName(i); String url = getUrl(i);//w w w.j a va 2 s . c o m String username = getUsername(i); String password = getPassword(i); BasicDataSource ds = new BasicDataSource(); ds.setUrl(url); ds.setUsername(username); ds.setPassword(password); ds.setInitialSize(1); ds.setMaxActive(1); ds.setDriverClassName(driverClassName); return ds; }
From source file:org.jxstar.dao.pool.PooledConnection.java
/** * ???/* ww w . j a v a 2 s . c om*/ * @param dsName * @return */ private DataSource createSelfDataSource(DataSourceConfig dsConfig) { String dsName = dsConfig.getDataSourceName(); BasicDataSource ds = (BasicDataSource) _myDataSourceMap.get(dsName); if (ds != null) return ds; ds = new BasicDataSource(); //??? int iTranLevel = getTranLevelConstant(dsConfig.getTranLevel()); int maxnum = Integer.parseInt(dsConfig.getMaxConNum()); ds.setDriverClassName(dsConfig.getDriverClass()); ds.setUrl(dsConfig.getJdbcUrl()); ds.setUsername(dsConfig.getUserName()); ds.setPassword(dsConfig.getPassWord()); ds.setMaxIdle(maxnum); ds.setMaxActive(maxnum); ds.setMaxWait(Long.parseLong(dsConfig.getMaxWaitTime())); ds.setDefaultAutoCommit(false); ds.setDefaultTransactionIsolation(iTranLevel); //????SystemVarserver.xml? String validTest = dsConfig.getValidTest(); String validQuery = dsConfig.getValidQuery(); if (validTest.equalsIgnoreCase("true") && validQuery.length() > 0) { _log.showDebug("pool test use query..."); ds.setTestOnBorrow(true); ds.setValidationQuery(validQuery); ds.setValidationQueryTimeout(3); } //?mysql??? //????? if (dsConfig.getValidIdle().equalsIgnoreCase("true")) { _log.showDebug("pool idle valid thread started..."); ds.setMinIdle(5); ds.setTestWhileIdle(true); //1030?5 ds.setMinEvictableIdleTimeMillis(30 * 60 * 1000);//30 minus ds.setTimeBetweenEvictionRunsMillis(10 * 60 * 1000);//10 minus } //??? _myDataSourceMap.put(dsName, ds); return ds; }
From source file:org.lucane.server.database.DatabaseAbstractionLayer.java
/** * DatabaseLayer Factory//from w w w .j a v a2s. 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); }