Example usage for org.apache.commons.dbcp BasicDataSource BasicDataSource

List of usage examples for org.apache.commons.dbcp BasicDataSource BasicDataSource

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource BasicDataSource.

Prototype

BasicDataSource

Source Link

Usage

From source file:com.dangdang.ddframe.job.cloud.executor.TaskExecutor.java

@Override
public void registered(final ExecutorDriver executorDriver, final Protos.ExecutorInfo executorInfo,
        final Protos.FrameworkInfo frameworkInfo, final Protos.SlaveInfo slaveInfo) {
    if (!executorInfo.getData().isEmpty()) {
        Map<String, String> data = SerializationUtils.deserialize(executorInfo.getData().toByteArray());
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(data.get("event_trace_rdb_driver"));
        dataSource.setUrl(data.get("event_trace_rdb_url"));
        dataSource.setPassword(data.get("event_trace_rdb_password"));
        dataSource.setUsername(data.get("event_trace_rdb_username"));
        jobEventBus = new JobEventBus(new JobEventRdbConfiguration(dataSource));
    }/*from  ww  w. ja  v  a  2 s  .com*/
}

From source file:com.dangdang.ddframe.rdb.transaction.soft.base.AbstractSoftTransactionIntegrationTest.java

private DataSource createDataSource(final String dataSourceName) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(org.h2.Driver.class.getName());
    result.setUrl("jdbc:h2:mem:" + dataSourceName);
    result.setUsername("sa");
    result.setPassword("");
    return result;
}

From source file:com.dangdang.ddframe.job.example.JavaLiteJobMain.java

private static DataSource setUpEventTraceDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(EVENT_RDB_STORAGE_DRIVER);
    result.setUrl(EVENT_RDB_STORAGE_URL);
    result.setUsername(EVENT_RDB_STORAGE_USERNAME);
    result.setPassword(EVENT_RDB_STORAGE_PASSWORD);
    return result;
}

From source file:com.manpowergroup.cn.icloud.util.Case1.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from   w  ww  .  j a  v a  2 s .c o m*/
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    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.weibo.datasys.common.db.DBManager.java

/**
 * //from   w ww  .  ja  v a  2 s  .  c  o  m
 * ?????
 * 
 * @param configData
 */
private static void initDataSource(CommonData configData) {
    String dsname = configData.getBaseField("dsname");

    BasicDataSource dataSource = new BasicDataSource();
    // ??
    dataSource.setDriverClassName(configData.getBaseField("driverClassName"));
    // ??
    dataSource.setUrl(configData.getBaseField("connectURL"));
    // ???
    dataSource.setUsername(configData.getBaseField("username"));
    dataSource.setPassword(configData.getBaseField("password"));
    // ?
    dataSource.setInitialSize(StringUtils.parseInt(configData.getBaseField("initialSize"), 1));
    // ?
    dataSource.setMinIdle(StringUtils.parseInt(configData.getBaseField("minIdle"), 1));
    // 
    dataSource.setMaxIdle(StringUtils.parseInt(configData.getBaseField("maxIdle"), 1));
    // 
    dataSource.setMaxActive(StringUtils.parseInt(configData.getBaseField("maxActive"), 1));
    // ?,?(ms)
    dataSource.setMaxWait(StringUtils.parseInt(configData.getBaseField("maxWait"), 1000));

    // ??
    dataSource.setTestWhileIdle(true);
    // ?sql?
    dataSource.setValidationQuery("select 'test'");
    // ?
    dataSource.setValidationQueryTimeout(5000);
    // 
    dataSource.setTimeBetweenEvictionRunsMillis(3600000);
    // ??
    dataSource.setMinEvictableIdleTimeMillis(3600000);

    dsMap.put(dsname, dataSource);

    logger.info("[InitDataSourceOK] - dsname={}", dsname);
}

From source file:edu.tamu.tcat.db.core.AbstractDataSourceFactory.java

/**
 * Create a new {@link BasicDataSource} from the specified {@link DSProperties}
 *///from   www . j ava 2  s.c  om
protected synchronized BasicDataSource createDataSource(final Properties parameters)
        throws DataSourceException {
    BasicDataSource dataSource;
    final Driver driver = getDriver();
    final String connectionUrl = getConnectionUrl(parameters);
    final Properties connectionProps = getConnectionProperties(parameters);

    dataSource = new BasicDataSource() {
        @Override
        protected ConnectionFactory createConnectionFactory() throws SQLException {
            //The loading of the driver via class-loader does not work properly in OSGI.

            if (driver.acceptsURL(getUrl())) {
                if (getValidationQuery() == null) {
                    setTestOnBorrow(false);
                    setTestOnReturn(false);
                    setTestWhileIdle(false);
                }

                ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, connectionUrl,
                        connectionProps);
                return driverConnectionFactory;
            }
            return super.createConnectionFactory();
        }
    };
    //         dataSource.setDriverClassLoader(Driver.class.getClassLoader());
    // should be included in the connection properties and not needed
    //        dataSource.setUsername(key.getUsername());
    //        dataSource.setPassword(key.getPassword());
    dataSource.setDriverClassName(driver.getClass().getName());
    dataSource.setUrl(connectionUrl);
    dataSource.setMaxActive(getMaxActiveConnections(parameters));
    dataSource.setMaxIdle(getMaxIdleConnections(parameters));
    dataSource.setMinIdle(0);
    dataSource.setMinEvictableIdleTimeMillis(10000);
    dataSource.setTimeBetweenEvictionRunsMillis(1000);
    dataSource.setLogAbandoned(true);
    dataSource.setRemoveAbandoned(true);//seconds
    dataSource.setRemoveAbandonedTimeout(60);
    return dataSource;
}

From source file:gobblin.runtime.MysqlDatasetStateStoreTest.java

@BeforeClass
public void setUp() throws Exception {
    testMetastoreDatabase = TestMetastoreDatabaseFactory.get();
    String jdbcUrl = testMetastoreDatabase.getJdbcUrl();
    ConfigBuilder configBuilder = ConfigBuilder.create();
    BasicDataSource mySqlDs = new BasicDataSource();

    mySqlDs.setDriverClassName(ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER);
    mySqlDs.setDefaultAutoCommit(false);
    mySqlDs.setUrl(jdbcUrl);/*w  w  w .  j  av  a 2  s. co m*/
    mySqlDs.setUsername(TEST_USER);
    mySqlDs.setPassword(TEST_PASSWORD);

    dbJobStateStore = new MysqlStateStore<>(mySqlDs, TEST_STATE_STORE, false, JobState.class);

    configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_URL_KEY, jdbcUrl);
    configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_USER_KEY, TEST_USER);
    configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, TEST_PASSWORD);

    ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(
            DatasetStateStore.Factory.class);

    DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass("mysql").newInstance();
    dbDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build());

    // clear data that may have been left behind by a prior test run
    dbJobStateStore.delete(TEST_JOB_NAME);
    dbDatasetStateStore.delete(TEST_JOB_NAME);
}

From source file:br.com.shopcarpet.config.JpaConfig.java

/**
 * A metodo dataSource retorna a conexao do banco de dados.
 *//*from  w  w w. j  a v a  2s  .  co m*/
@Bean
public DataSource getDataSource() {
    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost/carpet");
    ds.setUsername("carpet");
    ds.setPassword("carpet123");
    return ds;
}

From source file:io.apiman.gateway.engine.impl.DefaultJdbcComponentTest.java

@Test
public void testDataSource() throws Throwable {
    DefaultJdbcComponent component = new DefaultJdbcComponent();

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(Driver.class.getName());
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setUrl("jdbc:h2:mem:testDataSource;DB_CLOSE_DELAY=-1");

    try {//from   w w w. j  av a 2  s. c o m
        IJdbcClient client = component.create(ds);
        doAllTests(client);
    } finally {
        try {
            ds.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:calculus.backend.JpaConfig.java

@Bean
public DataSource dataSource() {

    loadProperties();/*from  w w  w. j  a v a  2s  .com*/

    BasicDataSource driver = new BasicDataSource();
    driver.setDriverClassName(this.driver);
    driver.setUrl(this.url);
    driver.setUsername(this.user);
    driver.setPassword(this.pass);
    driver.setMaxIdle(poolSize);
    driver.setMaxActive(poolSize);
    return driver;
}