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: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 a 2 s  .c o  m
}

From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java

public static CobarAdapter getCobarAdapter(String cobarNodeName) throws IOException {
    CobarAdapter cAdapter = new CobarAdapter();
    Properties prop = new Properties();
    prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties"));
    BasicDataSource ds = new BasicDataSource();
    String user = prop.getProperty(cobarNodeName + ".user").trim();
    String password = prop.getProperty(cobarNodeName + ".password").trim();
    String ip = prop.getProperty(cobarNodeName + ".ip").trim();
    int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim());
    int maxActive = -1;
    int minIdle = 0;
    long timeBetweenEvictionRunsMillis = 10 * 60 * 1000;
    int numTestsPerEvictionRun = Integer.MAX_VALUE;
    long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
    ds.setUsername(user);/*w ww  .  jav  a2  s  . c  o  m*/
    ds.setPassword(password);
    ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(managerPort).append("/")
            .toString());
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setMaxActive(maxActive);
    ds.setMinIdle(minIdle);
    ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    cAdapter.setDataSource(ds);
    return cAdapter;
}

From source file:com.googlecode.wmbutil.cache.LookupDataSourceFactory.java

public static synchronized LookupDataSource getDataSource() throws CacheRefreshException {
    if (dataSource == null) {
        try {/*from  ww w  .  j a  va  2 s.co  m*/
            Properties config = new Properties();
            config.load(new FileInputStream("lookup-connection.properties"));

            BasicDataSource ds = new BasicDataSource();
            ds.setDriverClassName(config.getProperty("lookup.class"));
            ds.setUrl(config.getProperty("lookup.url"));
            ds.setUsername(config.getProperty("lookup.username"));
            ds.setPassword(config.getProperty("lookup.password"));
            ds.setDefaultReadOnly(false);

            dataSource = new JdbcLookupDataSource(ds);
        } catch (FileNotFoundException e) {
            throw new CacheRefreshException("Could not find lookup-connection.properties file", e);
        } catch (IOException e) {
            throw new CacheRefreshException("Found, but could not read from lookup-connection.properties file",
                    e);
        } catch (RuntimeException e) {
            throw new CacheRefreshException("Could not create data source", e);
        }
    }

    return dataSource;
}

From source file:cn.com.sims.crawler.util.JDBCHelper.java

public static JdbcTemplate createMysqlTemplate(String templateName, String url, String username,
        String password, int initialSize, int maxActive) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(url);//from   w ww .j  a  v  a 2s  . c om
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    JdbcTemplate template = new JdbcTemplate(dataSource);
    templateMap.put(templateName, template);
    return template;
}

From source file:com.taobao.tddl.jdbc.group.testutil.DataSourceFactory.java

public static DataSource getLocalMySQLDataSource(int num) {
    if (num > 3)
        num = 1;/*  ww  w .j a v  a2  s  .c  om*/
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("root");
    ds.setPassword("zhh");
    ds.setUrl("jdbc:mysql://localhost/group_test_" + num);
    return ds;

}

From source file:cz.muni.fi.pv168.dressroommanager.ClosetManagerImplTest.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");
    return ds;/* www  .  j  av a2  s . c  o  m*/
}

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

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    //we will use in memory database
    ds.setUrl("jdbc:derby:memory:closetmgr-test;create=true");
    return ds;//from www  .ja  v a 2 s  .  co  m
}

From source file:com.cgdecker.guice.jdbc.Hsqldb.java

public static DataSource getDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(jdbcDriver.class.getName());
    result.setUrl("jdbc:hsqldb:mem:.");
    result.setUsername("sa");
    result.setPassword("");
    setUpDatabase(result);/*  www.ja v a  2 s .c  o m*/
    return result;
}

From source file:com.dangdang.ddframe.rdb.sharding.config.yaml.AbstractYamlShardingDataSourceTest.java

protected static DataSource createDataSource(final String dsName) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(org.h2.Driver.class.getName());
    result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL", dsName));
    result.setUsername("sa");
    result.setPassword("");
    result.setMaxActive(100);/* ww w.  j a v a2 s.c om*/
    return result;
}

From source file:gsn.storage.DataSources.java

public static BasicDataSource getDataSource(DBConnectionInfo dci) {
    BasicDataSource ds = null;//ww w . j  av  a  2  s.  c  o  m
    try {
        ds = (BasicDataSource) GSNContext.getMainContext().lookup(Integer.toString(dci.hashCode()));
        if (ds == null) {
            ds = new BasicDataSource();
            ds.setDriverClassName(dci.getDriverClass());
            ds.setUsername(dci.getUserName());
            ds.setPassword(dci.getPassword());
            ds.setUrl(dci.getUrl());
            //ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
            //ds.setAccessToUnderlyingConnectionAllowed(true); 
            GSNContext.getMainContext().bind(Integer.toString(dci.hashCode()), ds);
            logger.warn("Created a DataSource to: " + ds.getUrl());
        }
    } catch (NamingException e) {
        logger.error(e.getMessage(), e);
    }
    return ds;
}