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: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);/*from  w w  w.ja v a 2s. co  m*/
    if (DatabaseType.Oracle == dbEnv.getDatabaseType()) {
        result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName));
    }
    return result;
}

From source file:BasicDataSourceExample.java

public static DataSource setupDataSource(String connectURI) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    ds.setUsername("scott");
    ds.setPassword("tiger");
    ds.setUrl(connectURI);
    return ds;/*from  ww  w  .  j  a  va2s  . c om*/
}

From source file:com.pinterest.pinlater.backends.mysql.MySQLDataSources.java

private static DataSource createDataSource(String host, int port, String user, String passwd, int poolSize,
        int maxWaitMillis, int socketTimeoutMillis) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource
            .setUrl(String.format(
                    "jdbc:mysql://%s:%d?" + "connectTimeout=5000&" + "socketTimeout=%d&"
                            + "enableQueryTimeouts=false&" + "cachePrepStmts=true&" + "characterEncoding=UTF-8",
                    host, port, socketTimeoutMillis));
    dataSource.setUsername(user);//from  ww w  . j  av a  2  s  . c  o  m
    dataSource.setPassword(passwd);
    dataSource.setDefaultAutoCommit(true);
    dataSource.setInitialSize(poolSize);
    dataSource.setMaxActive(poolSize);
    dataSource.setMaxIdle(poolSize);
    // deal with idle connection eviction
    dataSource.setValidationQuery("SELECT 1 FROM DUAL");
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setTestWhileIdle(true);
    dataSource.setMinEvictableIdleTimeMillis(5 * 60 * 1000);
    dataSource.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000);
    dataSource.setNumTestsPerEvictionRun(poolSize);
    // max wait in milliseconds for a connection.
    dataSource.setMaxWait(maxWaitMillis);
    // force connection pool initialization.
    Connection conn = null;
    try {
        // Here not getting the connection from ThreadLocal no need to worry about that.
        conn = dataSource.getConnection();
    } catch (SQLException e) {
        LOG.error(String.format(
                "Failed to get a mysql connection when creating DataSource, " + "host: %s, port: %d", host,
                port), e);
    } finally {
        JdbcUtils.closeConnection(conn);
    }
    return dataSource;
}

From source file:ejp.examples.MultiThreadedWithConnectionPooling.java

static DataSource getDbcpDataSource() {
    BasicDataSource ds = new BasicDataSource();

    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setMaxActive(100);/*  w  w w .j  a v a 2  s .  co m*/
    ds.setUrl("jdbc:hsqldb:mem:ejp_example");

    return ds;
}

From source file:com.jt.dbcp.example.BasicDataSourceExample.java

public static DataSource setupDataSource(String connectURI) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("root");
    ds.setPassword("root");
    ds.setUrl(connectURI);
    return ds;//from  w  w w . j  av  a  2  s . c o  m
}

From source file:cz.muni.fi.pv168.airshipmanager.ContractManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:derby:memory:AirshipManagerImplTest;create=true");
    return ds;/*from ww w.j a v a2  s  .c o m*/
}

From source file:BorrowingManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:derby:memory:libraryProject;create=true");
    return ds;/*from w  w w  .j a va 2 s .  c  o m*/
}

From source file:com.katsu.dwm.jndi.datasource.DataSourceFactory.java

public static DataSource getDataSource(Resource resource) {
    BasicDataSource result = new BasicDataSource();
    result.setMaxActive(resource.getMaxActive());
    result.setMaxIdle(resource.getMaxIdle());
    result.setPassword(resource.getPassword());
    result.setUsername(resource.getUsername());
    result.setUrl(resource.getUrl());
    result.setDriverClassName(resource.getDriverClassName());
    return result;
}

From source file:cz.muni.fi.pv168.dressroommanager.DressroomManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    //we will use in memory database
    ds.setUrl("jdbc:derby:memory:dressroom-test;create=true");
    //ds.setUrl("jdbc:derby://localhost:1527/test");
    return ds;/*  w  w  w  .j a  v a  2 s  .c  o m*/
}

From source file:edu.ncsa.uiuc.rdfrepo.testing.USeekMSailFac.java

public static IndexingSail getIndexingSail(String dburl, String dbuser, String password,
        String capturepredicate, Sail sail) throws SailException {
    //set tup the postgis datasource for indexer
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.postgresql.Driver");
    dataSource.setUrl(dburl);
    dataSource.setUsername(dbuser);//from   w  w  w  .j ava  2s.  com
    dataSource.setPassword(password);
    PostgisIndexerSettings indexerSettings = new PostgisIndexerSettings();

    //        String patternString =
    //            "?observation <http://purl.oclc.org/NET/ssnx/ssn#observationResultTime> ?time." +
    //                "?time  <http://www.w3.org/2006/time#inXSDDateTime> ?timevalue. " +
    //                "?loc <http://www.opengis.net/rdf#hasWKT> ?coord. " +
    //                "?sensor <http://www.loa-cnr.it/ontologies/DUL.owl#hasLocation> ?loc." +
    //                "?observation <http://purl.oclc.org/NET/ssnx/ssn#observedBy> ?sensor. ";

    String patternString = "?geometry <http://www.opengis.net/rdf#hasWKT> ?wkt.";

    sail.initialize();
    indexerSettings.setMatchSatatments(createPatternFromString(patternString, sail));
    indexerSettings.setDataSource(dataSource);

    //a matcher decides which object should be indexed by its associated predicate, we can use "http://www.opengis.net/rdf#hasWKT"
    PostgisIndexMatcher matcher = new PostgisIndexMatcher();
    matcher.setPredicate(capturepredicate);

    //create a IndexingSail from the basic sail and the indexer
    indexerSettings.setMatchers(Arrays.asList(new PostgisIndexMatcher[] { matcher }));

    //        PartitionDef p = new P
    //        IndexingSail indexingSail = new IndexingSail(sail, indexerSettings);
    //        indexingSail.getConnection().

    //        indexingSail.initialize();
    return null;
}