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

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

Introduction

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

Prototype

public synchronized void setUsername(String username) 

Source Link

Document

Sets the #username .

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

Usage

From source file:test.gov.nih.nci.logging.api.persistence.TestSpringLocationSessionFactoryBean.java

private static BasicDataSource setDataSourceProperties() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost:3306/clm");
    ds.setUsername("root");
    ds.setPassword("admin");
    /*props.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
    props.setProperty("jdbc.batch_size","30");*/
    return ds;//from   ww  w.  j  av a 2s. c om
}

From source file:tp.project.trafficviolationsystem.app.conf.ConnectionConfig.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/tvs");
    ds.setUsername("tvs_user");
    ds.setPassword("tvs_user");
    return ds;//from   w w w  . j a  v  a2 s  .  co  m
}

From source file:ttf.util.AppContext.java

private AppContext(Configuration c) {
    // data source
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(c.getString("db.driverClassName"));
    bds.setUsername(c.getString("db.username"));
    bds.setPassword(c.getString("db.password"));
    bds.setUrl(c.getString("db.uri"));
    dataSource = bds;/* w ww.j  av a 2  s  .c o m*/

    // model handlers
    articleFactory = new BasicArticleFactory();
    topicFactory = new BasicTopicFactory();
    modelStore = new SQLStore(dataSource, articleFactory, topicFactory);

    // processing
    String key = c.getString("alchemy.key");
    AlchemyAPI alchemyAPI = AlchemyAPI.GetInstanceFromString(key);
    EntityDetector entityDetector = new EntityDetector(alchemyAPI);
    TfIdfDetector tfIdfDetector = new TfIdfDetector(new TfIdf());
    SimilarityComputer similarityComputer = new SimilarityComputer();

    contextFactory = new ContextFactory( //
            articleFactory, topicFactory, //
            modelStore, //
            alchemyAPI, entityDetector, tfIdfDetector, similarityComputer);
}

From source file:uk.ac.ebi.sail.server.data.DataManager.java

private static DataSource setupDataSource(BackendConfigurationManager defaultCfg) {
    BasicDataSource ds = new BasicDataSource();

    ds.setDriverClassName(defaultCfg.getDBDriverClass());
    ds.setUsername(defaultCfg.getDBUserName());
    ds.setPassword(defaultCfg.getDBPassword());
    ds.setUrl(defaultCfg.getConnectionURL());

    ds.setTimeBetweenEvictionRunsMillis(10000);

    return ds;//from   w  ww . java 2s.  com
}

From source file:voldemort.performance.MysqlBench.java

public MysqlBench(String table, int numThreads, int numRequests, String connectionString, String username,
        String password, String requestFile, boolean doReads, boolean doWrites) {
    this.table = table;
    this.numThreads = numThreads;
    this.numRequests = numRequests;
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername(username);
    ds.setPassword(password);/* w w  w .j  av a2s  . c o  m*/
    ds.setUrl(connectionString);
    this.requestFile = requestFile;
    this.dataSource = ds;
    this.doReads = doReads;
    this.doWrites = doWrites;
}

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);/*w  w  w. j av a 2s.  c om*/
    }
    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 w  w .  j a v a  2 s .c  o 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  a  va2 s .com*/

    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  w w  .  j a v  a  2 s. c  o  m*/
}