@Inject public DataSourceProvider(@Named("dataSourceProperties") Properties properties) { this.basicDataSource = new BasicDataSource(); this.basicDataSource.setDriverClassName(properties.getProperty(CONN_DRIVER, DEFAULT_CONN_DRIVER)); this.basicDataSource.setUrl(properties.getProperty(CONN_URL)); if (properties.containsKey(USERNAME) && properties.containsKey(PASSWORD)) { this.basicDataSource.setUsername(properties.getProperty(USERNAME)); this.basicDataSource .setPassword(PasswordManager.getInstance(properties).readPassword(properties.getProperty(PASSWORD))); } if (properties.containsKey(MAX_IDLE_CONNS)) { this.basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(MAX_IDLE_CONNS))); } if (properties.containsKey(MAX_ACTIVE_CONNS)) { this.basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(MAX_ACTIVE_CONNS))); } }
ds.setMaxActive(Integer.parseInt(defaultIfNull(val, "20")));
@SuppressWarnings( "deprecation" ) private static void setPoolProperties( BasicDataSource ds, Properties properties, int initialSize, int maxSize ) { ds.setInitialSize( initialSize ); ds.setMaxActive( maxSize ); ds.setMaxActive( Integer.valueOf( value ) );
BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("username"); dataSource.setPassword("password"); dataSource.setUrl("jdbc:mysql://<host>:<port>/<database>"); dataSource.setMaxActive(10); dataSource.setMaxIdle(5); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1");
@PostConstruct public void init() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(JDBC_DRIVER_NAME); ds.setUrl("jdbc:derby:" + NACOS_HOME + File.separator + DERBY_BASE_DIR + ";create=true"); ds.setUsername(USER_NAME); ds.setPassword(PASSWORD); ds.setInitialSize(20); ds.setMaxActive(30); ds.setMaxIdle(50); ds.setMaxWait(10000L); ds.setPoolPreparedStatements(true); ds.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES .toMillis(10L)); ds.setTestWhileIdle(true); jt = new JdbcTemplate(); jt.setMaxRows(50000); jt.setQueryTimeout(5000); jt.setDataSource(ds); DataSourceTransactionManager tm = new DataSourceTransactionManager(); tjt = new TransactionTemplate(tm); tm.setDataSource(ds); tjt.setTimeout(5000); if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) { reload(); } }
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.setMaxActive(maxTotal);
dataSource.setMaxActive(maxTotal);
public DataSource createNewDataSource(Map params) throws IOException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName((String) DRIVERCLASS.lookUp(params)); dataSource.setUrl((String) JDBC_URL.lookUp(params)); dataSource.setUsername((String) USERNAME.lookUp(params)); dataSource.setPassword((String) PASSWORD.lookUp(params)); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMaxActive(((Integer) MAXACTIVE.lookUp(params)).intValue()); dataSource.setMaxIdle(((Integer) MAXIDLE.lookUp(params)).intValue()); // check the data source is properly setup by trying to gather a connection out of it Connection conn = null; try { conn = dataSource.getConnection(); } catch (SQLException e) { throw new DataSourceException( "Connection pool improperly set up: " + e.getMessage(), e); } finally { // close the connection at once if (conn != null) try { conn.close(); } catch (SQLException e) { } } return dataSource; }
bds.setPoolPreparedStatements(false); bds.setMaxIdle(maxPerUserConnectionCount); bds.setMaxActive(maxPerUserConnectionCount); bds.setMinEvictableIdleTimeMillis( idleConnectionsCleanupTimeoutMs);
/** * Creates a data source by reading properties from a file called 'db.properties', located * paralell to the test setup instance. */ 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); }
dbcpDataSource.setMaxActive(getIntProperty(config, "maxPoolSize", 30)); dbcpDataSource.setMinIdle(getIntProperty(config, "minPoolSize", 5)); dbcpDataSource.setMaxIdle(getIntProperty(config, "maxPoolSize", 20));
dataSource.setMaxActive(maxActive); dataSource.setMinIdle(minIdle);
@ManagedAttribute @Description("Set the maximum number of active connections that can be allocated from this pool at the same time," + " or negative for no limit.") public void setMaxActive(final int max) { ds.setMaxActive(max); }
dataSource.setMaxActive(maxConn);
public static DataSource createSampleDatabaseDataSource() { final BasicDataSource _dataSource = new BasicDataSource(); _dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); _dataSource.setUrl("jdbc:hsqldb:res:orderdb;readonly=true"); _dataSource.setMaxActive(-1); _dataSource.setDefaultAutoCommit(false); return _dataSource; }
BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DATABASE_DRIVER_CLASS); ds.setUsername(DATABASE_USERNAME); ds.setPassword(DATABASE_PASSWORD); ds.setUrl(DATABASE_URL); ds.setInitialSize(1); ds.setMaxActive(50); ds.setDefaultAutoCommit(false);
BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DATABASE_DRIVER_CLASS); ds.setUsername(DATABASE_USERNAME); ds.setPassword(DATABASE_PASSWORD); ds.setUrl(DATABASE_URL); ds.setInitialSize(1); ds.setMaxActive(50); ds.setDefaultAutoCommit(false);
BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("username"); dataSource.setPassword("password"); dataSource.setUrl("jdbc:mysql://<host>:<port>/<database>"); dataSource.setMaxActive(50); dataSource.setMaxIdle(5); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1");