List of usage examples for org.apache.commons.dbcp BasicDataSource BasicDataSource
BasicDataSource
From source file:com.redrisegames.reigninwildWeb.ui.SampleWebUiApplication.java
@Bean public DataSource getDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driver); dataSource.setUrl(url);/* w ww . ja v a 2 s . c om*/ dataSource.setUsername(username); dataSource.setPassword(password); return dataSource; }
From source file:com.dangdang.ddframe.rdb.common.sql.base.AbstractSQLTest.java
private static BasicDataSource buildDataSource(final String dbName, final DatabaseType type) { DataBaseEnvironment dbEnv = new DataBaseEnvironment(type); BasicDataSource result = new BasicDataSource(); result.setDriverClassName(dbEnv.getDriverClassName()); result.setUrl(dbEnv.getURL(dbName)); result.setUsername(dbEnv.getUsername()); result.setPassword(dbEnv.getPassword()); result.setMaxActive(1000);/* w w w .j ava 2s .co m*/ if (DatabaseType.Oracle == dbEnv.getDatabaseType()) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName)); } return result; }
From source file:com.alibaba.druid.benckmark.pool.CaseKylin_mysql.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w ww .j a va2 s.co m dataSource.setMaxIdle(maxIdle); dataSource.setMinIdle(minIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnBorrow(testWhileIdle); dataSource.setTestOnBorrow(testOnReturn); dataSource.setRemoveAbandoned(removeAbandoned); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:net.comze.framework.orm.datasource.DbcpDataSourceFactory.java
private BasicDataSource initialize(Properties properties) { ObjectUtils.notNull(properties, "properties"); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(properties.getProperty(JDBC_DRIVER)); basicDataSource.setUrl(properties.getProperty(JDBC_URL)); basicDataSource.setUsername(properties.getProperty(JDBC_USERNAME)); basicDataSource.setPassword(properties.getProperty(JDBC_PASSWORD)); if (properties.containsKey(DBCP_INITIALSIZE)) { basicDataSource.setInitialSize(Integer.parseInt(properties.getProperty(DBCP_INITIALSIZE))); }//from w w w . j a v a 2 s. co m if (properties.containsKey(DBCP_MAXACTIVE)) { basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(DBCP_MAXACTIVE))); } if (properties.containsKey(DBCP_MAXIDLE)) { basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(DBCP_MAXIDLE))); } if (properties.containsKey(DBCP_MAXWAIT)) { basicDataSource.setMaxWait(Long.parseLong(properties.getProperty(DBCP_MAXWAIT))); } if (properties.containsKey(DBCP_MINEVICTABLEIDLETIMEMILLIS)) { basicDataSource.setMinEvictableIdleTimeMillis( Long.parseLong(properties.getProperty(DBCP_MINEVICTABLEIDLETIMEMILLIS))); } if (properties.containsKey(DBCP_MINIDLE)) { basicDataSource.setMinIdle(Integer.parseInt(properties.getProperty(DBCP_MINIDLE))); } if (properties.containsKey(DBCP_NUMTESTSPEREVICTIONRUN)) { basicDataSource.setNumTestsPerEvictionRun( Integer.parseInt(properties.getProperty(DBCP_NUMTESTSPEREVICTIONRUN))); } if (properties.containsKey(DBCP_REMOVEABANDONED)) { basicDataSource.setRemoveAbandoned(Boolean.parseBoolean(properties.getProperty(DBCP_REMOVEABANDONED))); } if (properties.containsKey(DBCP_REMOVEABANDONEDTIMEOUT)) { basicDataSource.setRemoveAbandonedTimeout( Integer.parseInt(properties.getProperty(DBCP_REMOVEABANDONEDTIMEOUT))); } if (properties.containsKey(DBCP_TESTONBORROW)) { basicDataSource.setTestOnBorrow(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONBORROW))); } if (properties.containsKey(DBCP_TESTONCREATE)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONCREATE))); } if (properties.containsKey(DBCP_TESTONRETURN)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONRETURN))); } if (properties.containsKey(DBCP_TESTWHILEIDLE)) { basicDataSource.setTestWhileIdle(Boolean.parseBoolean(properties.getProperty(DBCP_TESTWHILEIDLE))); } if (properties.containsKey(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS)) { basicDataSource.setTimeBetweenEvictionRunsMillis( Long.parseLong(properties.getProperty(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS))); } if (properties.containsKey(DBCP_VALIDATIONQUERY)) { basicDataSource.setValidationQuery(properties.getProperty(DBCP_VALIDATIONQUERY)); } if (properties.containsKey(DBCP_VALIDATIONQUERYTIMEOUT)) { basicDataSource.setValidationQueryTimeout( Integer.parseInt(properties.getProperty(DBCP_VALIDATIONQUERYTIMEOUT))); } return basicDataSource; }
From source file:com.dangdang.ddframe.job.lite.console.restful.EventTraceHistoryRestfulApi.java
private DataSource setUpEventTraceDataSource() { BasicDataSource result = new BasicDataSource(); result.setDriverClassName(eventTraceDataSourceConfiguration.getDriver()); result.setUrl(eventTraceDataSourceConfiguration.getUrl()); result.setUsername(eventTraceDataSourceConfiguration.getUsername()); result.setPassword(eventTraceDataSourceConfiguration.getPassword()); return result; }
From source file:com.icbc.Scheduler.DA.PoolingConnectionProvider.java
private void initialize(String dbDriver, String dbURL, String dbUser, String dbPassword, int maxConnections, String dbValidationQuery) throws SQLException { if (dbDriver == null) { throw new SQLException("DB driver class name cannot be null!"); }/*from www . ja va2 s.c om*/ if (dbURL == null) { throw new SQLException("DB URL cannot be null!"); } if (maxConnections < 0) { throw new SQLException("Max connections must be greater than zero!"); } datasource = new BasicDataSource(); datasource.setDriverClassName(dbDriver); datasource.setUrl(dbURL); datasource.setUsername(dbUser); datasource.setPassword(dbPassword); datasource.setMaxActive(maxConnections); datasource.setTestOnBorrow(true); //datasource.setLoginTimeout(5); // datasource.setLoginTimeout(-1); // datasource.setMaxWait(-1); if (dbValidationQuery != null) { datasource.setValidationQuery(dbValidationQuery); } else { datasource.setValidationQuery("select SYSDATE FROM DUAL"); } }
From source file:contactsdirectory.backend.PersonManagerImplTest.java
private static DataSource prepareDataSource() throws SQLException { BasicDataSource ds = new BasicDataSource(); //we will use in memory database ds.setUrl("jdbc:derby:memory:personmgr-test;create=true"); return ds;// ww w .j a v a 2 s.c om }
From source file:com.alibaba.druid.benckmark.pool.Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w ww . jav a 2s . c o m dataSource.setMinIdle(minPoolSize); dataSource.setMaxIdle(maxPoolSize); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(false); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.dangdang.ddframe.job.cloud.scheduler.boot.env.BootstrapEnvironment.java
/** * ???.//from w w w. j a va 2s. c om * * @return ?? */ public Optional<JobEventRdbConfiguration> getJobEventRdbConfiguration() { String driver = getValue(EnvironmentArgument.EVENT_TRACE_RDB_DRIVER); String url = getValue(EnvironmentArgument.EVENT_TRACE_RDB_URL); String username = getValue(EnvironmentArgument.EVENT_TRACE_RDB_USERNAME); String password = getValue(EnvironmentArgument.EVENT_TRACE_RDB_PASSWORD); if (!Strings.isNullOrEmpty(driver) && !Strings.isNullOrEmpty(url) && !Strings.isNullOrEmpty(username)) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driver); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); return Optional.of(new JobEventRdbConfiguration(dataSource)); } return Optional.absent(); }
From source file:net.hydromatic.optiq.impl.jdbc.JdbcSchema.java
/** Creates a JDBC data source with the given specification. */ public static DataSource dataSource(String url, String driverClassName, String username, String password) { if (url.startsWith("jdbc:hsqldb:")) { // Prevent hsqldb from screwing up java.util.logging. System.setProperty("hsqldb.reconfig_logging", "false"); }/*from w w w . ja v a 2 s. c o m*/ BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setDriverClassName(driverClassName); return dataSource; }