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

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

Introduction

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

Prototype

public synchronized void setPassword(String password) 

Source Link

Document

Sets the #password .

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

Usage

From source file:voldemort.performance.MysqlGrowth.java

public static void main(String[] args) throws Exception {
    if (args.length != 3) {
        System.err.println("USAGE: java MySQLGrowth total_size increment threads");
        System.exit(1);/*from   ww w  .  j ava 2s. co m*/
    }
    final int totalSize = Integer.parseInt(args[0]);
    final int increment = Integer.parseInt(args[1]);
    final int threads = Integer.parseInt(args[2]);

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername("root");
    ds.setPassword("");
    ds.setUrl("jdbc:mysql://127.0.0.1:3306/test");
    final Connection conn = ds.getConnection();
    conn.createStatement().execute("truncate table test_table");

    final Random rand = new Random();
    int iterations = totalSize / increment;
    long[] readTimes = new long[iterations];
    long[] writeTimes = new long[iterations];
    ExecutorService service = Executors.newFixedThreadPool(threads);
    for (int i = 0; i < iterations; i++) {
        System.out.println("Starting iteration " + i);
        List<Future<Object>> results = new ArrayList<Future<Object>>(increment);
        long startTime = System.currentTimeMillis();
        final int fi = i;
        for (int j = 0; j < increment; j++) {
            final int fj = j;
            results.add(service.submit(new Callable<Object>() {

                public Object call() throws Exception {
                    upsert(conn, Integer.toString(fi * increment + fj), Integer.toString(fi * increment + fj));
                    return null;
                }
            }));
        }
        for (int j = 0; j < increment; j++)
            results.get(j).get();
        writeTimes[i] = System.currentTimeMillis() - startTime;
        System.out.println("write: " + (writeTimes[i] / (double) increment));
        results.clear();

        startTime = System.currentTimeMillis();
        for (int j = 0; j < increment; j++) {
            results.add(service.submit(new Callable<Object>() {

                public Object call() throws Exception {
                    return select(conn, Integer.toString(rand.nextInt((fi + 1) * increment)));
                }
            }));
        }
        for (int j = 0; j < increment; j++)
            results.get(j).get();
        readTimes[i] = (System.currentTimeMillis() - startTime);
        System.out.println("read: " + (readTimes[i] / (double) increment));
    }
    conn.close();

    System.out.println();
    System.out.println("iteration read write:");
    for (int i = 0; i < iterations; i++) {
        System.out.print(i);
        System.out.print(" " + readTimes[i] / (double) increment);
        System.out.println(" " + writeTimes[i] / (double) increment);
    }

    System.exit(0);
}

From source file:voldemort.store.mysql.MysqlStorageConfiguration.java

public MysqlStorageConfiguration(VoldemortConfig config) {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:mysql://" + config.getMysqlHost() + ":" + config.getMysqlPort() + "/"
            + config.getMysqlDatabaseName());
    ds.setUsername(config.getMysqlUsername());
    ds.setPassword(config.getMysqlPassword());
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    this.dataSource = ds;
}

From source file:voldemort.store.mysql.MysqlStorageEngineTest.java

private DataSource getDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:mysql://localhost:3306/test");
    ds.setUsername("root");
    ds.setPassword("");
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    return ds;//from  w  ww. ja v a2  s  . co  m
}

From source file:xbird.util.jdbc.datasource.DbcpDataSourceProvider.java

public DataSource setupDataSource(String connectURI) {
    // creates DataSource
    BasicDataSource ds = new BasicDataSource();

    // for debugging.
    if (Settings.isLoggingEnabled) {
        ds.setAccessToUnderlyingConnectionAllowed(true);
    }/*from   w  w w  .j ava 2  s . c  om*/

    ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind")));

    // sets up DataSource
    ds.setUrl(connectURI);
    final String dbuser = Settings.get("xbird.db.user");
    final String dbpasswd = Settings.get("xbird.db.passwd");
    if (dbuser != null && dbuser.length() != 0) {
        ds.setUsername(dbuser);
        ds.setPassword(dbpasswd);
    }

    // addtinal settings.
    final String maxactive = Settings.get("xbird.db.pool.maxactive");
    if (maxactive != null)
        ds.setMaxActive(Integer.parseInt(maxactive));

    final String maxidle = Settings.get("xbird.db.pool.maxidle");
    if (maxidle != null)
        ds.setMaxIdle(Integer.parseInt(maxidle));

    final String maxwait = Settings.get("xbird.db.pool.maxwait");
    ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait));

    ds.setDefaultAutoCommit(true);
    //ds.setDefaultReadOnly(false);

    final String initialsize = Settings.get("xbird.db.pool.initialsize");
    ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE : Integer.parseInt(initialsize));

    // sets up for PreparedStatements.
    ds.setPoolPreparedStatements(true);

    final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size");
    ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS
            : Integer.parseInt(maxOpenPreparedStatements));

    return ds;
}

From source file:za.co.dwarfsun.jcmanager.app.conf.ConnectionConfig.java

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUrl("jdbc:derby://localhost:1527/JobCardDB");
    ds.setUsername("jobcard");
    ds.setPassword("jobcard");
    return ds;//from w ww . jav a 2  s. c o  m
}

From source file:za.co.dwarfsun.jobcardmanager.test.ConnectionConfigTest.java

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUrl("jdbc:derby://localhost:1527/JobCardDB");
    ds.setUsername("jobcard");
    ds.setPassword("jobcard");
    return ds;//  w  w w.j ava 2  s  .  com
}