ds.setTestOnBorrow( Boolean.valueOf( value ) );
/** * creates a new {@link BasicDataSource} * @param config the properties used for datasource instantiation * @return */ public static BasicDataSource newDataSource(Config config) { BasicDataSource basicDataSource = new BasicDataSource(); PasswordManager passwordManager = PasswordManager.getInstance(ConfigUtils.configToProperties(config)); basicDataSource.setDriverClassName(ConfigUtils.getString(config, ConfigurationKeys.STATE_STORE_DB_JDBC_DRIVER_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER)); // MySQL server can timeout a connection so need to validate connections before use basicDataSource.setValidationQuery("select 1"); basicDataSource.setTestOnBorrow(true); basicDataSource.setDefaultAutoCommit(false); basicDataSource.setTimeBetweenEvictionRunsMillis(60000); basicDataSource.setUrl(config.getString(ConfigurationKeys.STATE_STORE_DB_URL_KEY)); basicDataSource.setUsername(passwordManager.readPassword( config.getString(ConfigurationKeys.STATE_STORE_DB_USER_KEY))); basicDataSource.setPassword(passwordManager.readPassword( config.getString(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY))); basicDataSource.setMinEvictableIdleTimeMillis( ConfigUtils.getLong(config, ConfigurationKeys.STATE_STORE_DB_CONN_MIN_EVICTABLE_IDLE_TIME_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_DB_CONN_MIN_EVICTABLE_IDLE_TIME)); return basicDataSource; }
private JdbcPushDownConnectionManager(KylinConfig config) throws ClassNotFoundException { dataSource = new BasicDataSource(); Class.forName(config.getJdbcDriverClass()); dataSource.setDriverClassName(config.getJdbcDriverClass()); dataSource.setUrl(config.getJdbcUrl()); dataSource.setUsername(config.getJdbcUsername()); dataSource.setPassword(config.getJdbcPassword()); dataSource.setMaxActive(config.getPoolMaxTotal()); dataSource.setMaxIdle(config.getPoolMaxIdle()); dataSource.setMinIdle(config.getPoolMinIdle()); // Default settings dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("select 1"); dataSource.setRemoveAbandoned(true); dataSource.setRemoveAbandonedTimeout(300); }
/** * Default constructor method. * @param config Basic configuration of JDBC source, such as driver name, URL, username, password. * @throws Exception If datasource cannot be connected. */ protected AbstractJdbcAdaptor(AdaptorConfig config) throws ClassNotFoundException { this.config = config; this.dataSourceDef = DataSourceDefProvider.getInstance().getById(config.datasourceId); dataSource = new BasicDataSource(); Class.forName(config.driver); dataSource.setDriverClassName(config.driver); dataSource.setUrl(config.url); dataSource.setUsername(config.username); dataSource.setPassword(config.password); dataSource.setMaxActive(config.poolMaxTotal); dataSource.setMaxIdle(config.poolMaxIdle); dataSource.setMinIdle(config.poolMinIdle); // Default settings dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(getSourceValidationSql()); dataSource.setRemoveAbandoned(true); dataSource.setRemoveAbandonedTimeout(300); DataSourceDefProvider provider = DataSourceDefProvider.getInstance(); DataSourceDef jdbcDs = provider.getById(getDataSourceId()); configurer = new DefaultConfiguer(this, jdbcDs); }
dataSource.setTestOnBorrow(true);
dataSource.setTestOnBorrow(true);
/** * Configures an Apache Commons data source with the specified properties. */ private void configureDataSource(@Nonnull final org.apache.commons.dbcp.BasicDataSource dataSource, @Nonnull final com.thinkbiganalytics.db.DataSourceProperties props) { dataSource.setDriverClassLoader(props.getDriverClassLoader()); dataSource.setValidationQuery(props.getValidationQuery()); dataSource.setTestOnBorrow(true); if (props.getProperties() != null) { for (final Map.Entry<Object, Object> entry : props.getProperties().entrySet()) { dataSource.addConnectionProperty((String) entry.getKey(), (String) entry.getValue()); } } }
@Override public synchronized void setTestOnBorrow(boolean testOnBorrow) { delegate.setTestOnBorrow(testOnBorrow); }
dbcpDataSource.setTestOnBorrow(false); dbcpDataSource.setTestOnReturn(false); dbcpDataSource.setRemoveAbandoned(true);
dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(validationQuery);
@ManagedAttribute @Description("Set the indication of whether objects will be validated before being borrowed from the pool.") public void setTestOnBorrow(final boolean test) { ds.setTestOnBorrow(test); }
/** * Configures an Apache Commons data source with the specified properties. */ private void configureDataSource(@Nonnull final org.apache.commons.dbcp.BasicDataSource dataSource, @Nonnull final com.thinkbiganalytics.db.DataSourceProperties props) { dataSource.setDriverClassLoader(props.getDriverClassLoader()); dataSource.setValidationQuery(props.getValidationQuery()); dataSource.setTestOnBorrow(true); if (props.getProperties() != null) { for (final Map.Entry<Object, Object> entry : props.getProperties().entrySet()) { dataSource.addConnectionProperty((String) entry.getKey(), (String) entry.getValue()); } } }
dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(getValidationQuery());
private DataSource getDatasource() { DbConnectorConfig connectorConfig = config.get(); BasicDataSource dataSource = new BasicDataSource(); dataSource.setUsername(connectorConfig.getUser()); dataSource.setPassword(connectorConfig.getPassword()); String uri = connectorConfig.getConnectURI(); isPostgreSQL = uri.startsWith("jdbc:postgresql"); dataSource.setUrl(uri); if (connectorConfig.isUseValidationQuery()) { dataSource.setValidationQuery(connectorConfig.getValidationQuery()); dataSource.setTestOnBorrow(true); } return dataSource; }
BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(JDBCDriver); ds.setUrl(JDBCUrl); ds.setUsername(JDBCUser); ds.setPassword(JDBCPassword); ds.setInitialSize(initSize); ds.setTestOnBorrow(false); ds.setTestWhileIdle(true);
BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(JDBCDriver); ds.setUrl(JDBCUrl); ds.setUsername(JDBCUser); ds.setPassword(JDBCPassword); ds.setInitialSize(initSize); ds.setMaxTotal(maxTotal);//negative for no limit ds.setTestOnBorrow(false); ds.setTestWhileIdle(true); Connection con = ds.getConnection();
@Override protected void initializeImpl(String propertyPrefix) { log.info("Initializing pooled connection manager"); dataSource = new BasicDataSource(); dataSource.setDriverClassName(getDriverClassName()); dataSource.setUrl(getUrl(propertyPrefix)); dataSource.setUsername(Common.envProps.getString(propertyPrefix + "db.username")); dataSource.setPassword(getDatabasePassword(propertyPrefix)); dataSource.setMaxActive(Common.envProps.getInt(propertyPrefix + "db.pool.maxActive", 10)); dataSource.setMaxIdle(Common.envProps.getInt(propertyPrefix + "db.pool.maxIdle", 10)); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(true); }
protected void setupDbcp() { org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource(); ds.setUrl(jdbcUrl); ds.setUsername("brettw"); ds.setPassword(""); ds.setInitialSize(MIN_POOL_SIZE); ds.setMinIdle(MIN_POOL_SIZE); ds.setMaxIdle(maxPoolSize); ds.setMaxActive(maxPoolSize); ds.setDefaultAutoCommit(false); ds.setTestOnBorrow(true); ds.setValidationQuery("SELECT 1"); DS = ds; }
private static DataSource setupDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(getDriver()); ds.setUsername(getUser()); ds.setPassword(getPassword()); ds.setUrl(getConnectionString()); ds.setDefaultAutoCommit(false); ds.setInitialSize(4); ds.setMaxActive(60); ds.setMaxIdle(10); ds.setValidationQuery("/* ping */ SELECT 1");//config to validate against mysql ds.setValidationQueryTimeout(3); ds.setTestOnBorrow(true); ds.setTestOnReturn(true); return ds; }
private JdbcPushDownConnectionManager(KylinConfig config) throws ClassNotFoundException { dataSource = new BasicDataSource(); Class.forName(config.getJdbcDriverClass()); dataSource.setDriverClassName(config.getJdbcDriverClass()); dataSource.setUrl(config.getJdbcUrl()); dataSource.setUsername(config.getJdbcUsername()); dataSource.setPassword(config.getJdbcPassword()); dataSource.setMaxActive(config.getPoolMaxTotal()); dataSource.setMaxIdle(config.getPoolMaxIdle()); dataSource.setMinIdle(config.getPoolMinIdle()); // Default settings dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("select 1"); dataSource.setRemoveAbandoned(true); dataSource.setRemoveAbandonedTimeout(300); }