List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxWait
public synchronized void setMaxWait(long maxWait)
From source file:org.geotoolkit.db.AbstractJDBCFeatureStoreFactory.java
/** * Create a datasource using given parameters. *///ww w . j av a 2 s.co 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 www . j a v a 2s .co 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. *///from ww w .j a v a 2 s .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.geowebcache.diskquota.jdbc.JDBCQuotaStoreFactory.java
private DataSource getDataSource(JDBCConfiguration config) throws ConfigurationException { try {//from w ww .j a v a 2 s. c o 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 ww . j av a 2s . 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.gvsig.fmap.dal.store.jdbc.JDBCResource.java
protected DataSource createDataSource() { JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this.getParameters(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); dataSource.setUsername(jdbcParams.getUser()); dataSource.setPassword(jdbcParams.getPassword()); dataSource.setUrl(jdbcParams.getUrl()); dataSource.setMaxWait(60L * 1000); // FIXME // FIXME Set Pool parameters: /*//from w w w.jav a2 s. co m dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxActive); dataSource.setMaxOpenPreparedStatements(maxActive); dataSource.setMaxWait(maxActive); dataSource.setInitialSize(initialSize); dataSource.setDefaultReadOnly(defaultReadOnly); dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setMinIdle(minIdle); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnReturn(testOnReturn); dataSource.setTestWhileIdle(testOnReturn); dataSource .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setAccessToUnderlyingConnectionAllowed(allow); dataSource.setLoginTimeout(seconds); dataSource.setLogWriter(out); */ return dataSource; }
From source file:org.gvsig.fmap.dal.store.jdbc.JDBCResource.java
protected void connectToDB() throws DataException { if (this.dataSource != null) { return;/* ww w. jav a 2 s. co m*/ } JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this.getParameters(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); dataSource.setUsername(jdbcParams.getUser()); dataSource.setPassword(jdbcParams.getPassword()); dataSource.setUrl(jdbcParams.getUrl()); dataSource.setMaxWait(60L * 1000); // FIXME // FIXME Set Pool parameters: /* dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxActive); dataSource.setMaxOpenPreparedStatements(maxActive); dataSource.setMaxWait(maxActive); dataSource.setInitialSize(initialSize); dataSource.setDefaultReadOnly(defaultReadOnly); dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setMinIdle(minIdle); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnReturn(testOnReturn); dataSource.setTestWhileIdle(testOnReturn); dataSource .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setAccessToUnderlyingConnectionAllowed(allow); dataSource.setLoginTimeout(seconds); dataSource.setLogWriter(out); */ this.dataSource = dataSource; }
From source file:org.gvsig.fmap.dal.store.mysql.MySQLResource.java
protected DataSource createDataSource() { MySQLResourceParameters jdbcParams = (MySQLResourceParameters) this.getParameters(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); dataSource.setUsername(jdbcParams.getUser()); dataSource.setPassword(jdbcParams.getPassword()); dataSource.setUrl(jdbcParams.getUrl()); dataSource.setMaxWait(60L * 1000); // FIXME // FIXME Set Pool parameters: /*//from w w w .j a v a2 s . c om dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxActive); dataSource.setMaxOpenPreparedStatements(maxActive); dataSource.setMaxWait(maxActive); dataSource.setInitialSize(initialSize); dataSource.setDefaultReadOnly(defaultReadOnly); dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setMinIdle(minIdle); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnReturn(testOnReturn); dataSource.setTestWhileIdle(testOnReturn); dataSource .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setAccessToUnderlyingConnectionAllowed(allow); dataSource.setLoginTimeout(seconds); dataSource.setLogWriter(out); */ return dataSource; }
From source file:org.gvsig.fmap.dal.store.postgresql.PostgreSQLResource.java
protected DataSource createDataSource() { PostgreSQLResourceParameters jdbcParams = (PostgreSQLResourceParameters) this.getParameters(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName()); dataSource.setUsername(jdbcParams.getUser()); dataSource.setPassword(jdbcParams.getPassword()); dataSource.setUrl(jdbcParams.getUrl()); dataSource.setMaxWait(60L * 1000); // FIXME // FIXME Set Pool parameters: /*//from ww w .ja va 2s . c o m dataSource.setMaxActive(maxActive); dataSource.setMaxIdle(maxActive); dataSource.setMaxOpenPreparedStatements(maxActive); dataSource.setMaxWait(maxActive); dataSource.setInitialSize(initialSize); dataSource.setDefaultReadOnly(defaultReadOnly); dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setMinIdle(minIdle); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnReturn(testOnReturn); dataSource.setTestWhileIdle(testOnReturn); dataSource .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setAccessToUnderlyingConnectionAllowed(allow); dataSource.setLoginTimeout(seconds); dataSource.setLogWriter(out); */ return dataSource; }
From source file:org.jxstar.dao.pool.PooledConnection.java
/** * ???//ww w . j av a2 s.c o m * @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; }