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

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

Introduction

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

Prototype

public synchronized void setUrl(String url) 

Source Link

Document

Sets the #url .

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsSQLDataSourceFactory.java

/**
 * Setup a dataSource for "users". Usage is for all users for consultation functions.
 * /*from  w  ww . j av a 2  s .c  om*/
 * @param dataSource
 *          the DataSource to update
 * @return SitoolsDataSource the new DataSource
 */
public SitoolsSQLDataSource setupDataSourceForUsers(JDBCDataSource dataSource) {
    String key = dataSource.getId();
    SitoolsSQLDataSource foundDatasource = dataSources.get(key);
    if (foundDatasource == null) {

        BasicDataSource ds = new BasicDataSource();
        // OSGi
        ds.setDriverClassLoader(getClass().getClassLoader());
        ds.setDriverClassName(dataSource.getDriverClass());
        ds.setUsername(dataSource.getUserLogin());
        ds.setPassword(dataSource.getUserPassword());
        ds.setUrl(dataSource.getUrl());
        ds.setMaxActive(dataSource.getMaxActive());
        ds.setInitialSize(dataSource.getInitialSize());
        ds.setDefaultReadOnly(true);
        // test that the connection is alive on each request. If not It will be dropped from the pool and another
        // connection will be created
        ds.setTestOnBorrow(true);
        ds.setValidationQuery("SELECT 1");
        if ((dataSource.getSchemaOnConnection() != null) && !dataSource.getSchemaOnConnection().equals("")) {
            ds.setDefaultCatalog(dataSource.getSchemaOnConnection());
        }
        foundDatasource = new SitoolsSQLDataSource(dataSource, ds, dataSource.getSchemaOnConnection());
        dataSources.put(key, foundDatasource);
    }
    return foundDatasource;
}

From source file:io.druid.db.DbConnector.java

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);
    }/*from   w w w. ja  va2  s. c  o  m*/

    return dataSource;
}

From source file:com.atypon.wayf.guice.WayfGuiceModule.java

@Provides
@Singleton/*from www  .  j  a v a2  s  . com*/
public NamedParameterJdbcTemplate getJdbcTemplate(@Named("jdbc.driver") String driver,
        @Named("jdbc.username") String username, @Named("jdbc.password") String password,
        @Named("jdbc.url") String url, @Named("jdbc.maxActive") Integer maxActive,
        @Named("jdbc.maxIdle") Integer maxIdle, @Named("jdbc.initialSize") Integer initialSize,
        @Named("jdbc.validationQuery") String validationQuery) {
    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(driver);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setUrl(url);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setInitialSize(initialSize);
    dataSource.setValidationQuery(validationQuery);

    return new NamedParameterJdbcTemplate(dataSource);
}

From source file:com.norconex.collector.http.db.impl.derby.DerbyCrawlURLDatabase.java

private DataSource createDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    ds.setUrl("jdbc:derby:" + dbDir + ";create=true");
    ds.setDefaultAutoCommit(true);/* ww w . ja  v a  2 s. c om*/
    return ds;
}

From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.dao.mysqlImpl.AbstractJDBCBaseDao.java

private synchronized BasicDataSource createConnectionPool() {
    BasicDataSource source;
    logger.debug("creating connectionpool");
    String driver = bundle.getString("dbDriver");
    String user = bundle.getString("dbUser");
    String pass = bundle.getString("dbPass");
    String url = bundle.getString("dbUrl");
    url = url + "?user=" + user + "&password=" + pass;
    source = new BasicDataSource();
    source.setDriverClassName(driver);//from  w  w w .j  a v  a2  s  .  co m
    source.setUsername(user);
    source.setPassword(pass);
    source.setUrl(url);
    source.setTestOnReturn(true);
    source.setValidationQuery("SELECT 1");
    logger.debug("connectionpool created");
    return source;
}

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  w  w .  j  a  v a  2s  . c o  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:com.thinkbiganalytics.nifi.v2.thrift.RefreshableDataSource.java

private DataSource create() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setDriverClassLoader(driverClassLoader);
    dataSource.setUrl(url);
    dataSource.setUsername(username);// w w  w.  j av  a 2 s.  c om
    dataSource.setPassword(password);
    return dataSource;
}

From source file:com.openteach.diamond.repository.client.impl.database.DataSourceFactory.java

/**
 * //from   www. ja  va2 s.co  m
 * @return
 */
public DataSource newInstance() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDefaultAutoCommit(true);
    dataSource.setDriverClassName(certificate.getDriverClassName());
    dataSource.setMaxActive(certificate.getMaxActive());
    dataSource.setMaxIdle(certificate.getMaxIdle());
    dataSource.setMaxWait(certificate.getMaxWait());
    dataSource.setMinIdle(certificate.getMinIdle());
    dataSource.setUsername(certificate.getUsername());
    dataSource.setPassword(certificate.getPassword());
    dataSource.setUrl(certificate.getUrl());
    return dataSource;
}

From source file:com.alibaba.druid.benckmark.pool.CaseKylin_Oracle.java

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from  ww w  . j  a  v  a2  s  .c  o  m*/
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(oracleDriverClass);
    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);
    dataSource.setValidationQuery(validateQuery);

    for (int i = 0; i < TEST_COUNT; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}

From source file:com.ritchey.naming.InitialContextFactory.java

/**
 * Create a databaseSource for a database by using properties that are
 * formed with the jndi name (e.g. database.myCoolDatabaseNumber1.url). url,
 * user, password and driver should all be defined.
 *
 * @param database is the jndi name of the database
 * @param properties represents the values of build.properties
 * @param jdbc is the context we're going to load
 * @throws NamingException//from w w  w.j av  a2 s . co  m
 */
public void createDs(String database, Properties properties, Context jdbc) throws NamingException {
    org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
    try {
        jdbc.bind(database, ds);
    } catch (Exception e) {
        // Quietly suppress NameAlreadyBound Exception
    }

    Boolean isDatabase = true;
    ds.setDriverClassName(getValue(isDatabase, "driver", database, properties));
    ds.setUrl(getValue(isDatabase, "url", database, properties));
    ds.setUsername(getValue(isDatabase, "user", database, properties));
    ds.setPassword(getValue(isDatabase, "password", database, properties));
}