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: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   www . j a v a2s .  com
    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.alibaba.druid.benckmark.pool.Case3.java

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*  w  w w .j  a  va 2s .c o  m*/
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setMinIdle(minIdle);
    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.setConnectionProperties(connectionProperties);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

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

From source file:edu.si.services.sidora.rest.batch.BatchServiceTest.java

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry reg = super.createRegistry();

    if (USE_MYSQL_DB) {
        BasicDataSource testMySQLdb = new BasicDataSource();
        testMySQLdb.setDriverClassName("com.mysql.jdbc.Driver");
        testMySQLdb.setUrl(//from w  ww  . j  ava 2  s . c o  m
                "jdbc:mysql://" + props.getProperty("mysql.host") + ":" + props.getProperty("mysql.port") + "/"
                        + props.getProperty("mysql.database") + "?zeroDateTimeBehavior=convertToNull");
        testMySQLdb.setUsername(props.getProperty("mysql.username").toString());
        testMySQLdb.setPassword(props.getProperty("mysql.password").toString());
        reg.bind("dataSource", testMySQLdb);
    } else {
        reg.bind("dataSource", db);
    }

    reg.bind("dataSource", db);

    reg.bind("jsonProvider", org.apache.cxf.jaxrs.provider.json.JSONProvider.class);
    reg.bind("jaxbProvider", org.apache.cxf.jaxrs.provider.JAXBElementProvider.class);

    return reg;
}

From source file:capture.PostgreSQLDatabase.java

public PostgreSQLDatabase() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(DRIVER);/*w w  w  .j a va  2s  .com*/
    ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username"));
    ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password"));
    ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url"));
    dataSource = ds;
}

From source file:capture.MySQLDatabase.java

public MySQLDatabase() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(DRIVER);/*from  w w w.j av  a 2s  .  com*/
    ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username"));
    ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password"));
    ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url"));
    dataSource = ds;
}

From source file:com.amazon.carbonado.repo.jdbc.TestH2.java

private RepositoryBuilder jdbcBuilder(boolean isMaster) throws RepositoryException {
    JDBCRepositoryBuilder builder = new JDBCRepositoryBuilder();
    builder.setName("jdbc");
    builder.setAutoVersioningEnabled(true, null);
    builder.setMaster(isMaster);//w w w.  j a  v  a  2s  .c o  m
    BasicDataSource ds = new BasicDataSource();
    builder.setDataSource(ds);

    builder.setSchemaResolver(new H2SchemaResolver());

    File dir = new File(TestUtilities.makeTestDirectory("jdbc"), "/h2");
    String url = "jdbc:h2:" + dir.getPath();
    ds.setDriverClassName("org.h2.Driver");
    ds.setUrl(url);
    ds.setUsername("sa");
    ds.setPassword("");

    return builder;
}

From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java

public void contextInitialized(final ServletContextEvent arg0) {
    Properties poolProp = new Properties();
    try {/*from   w w  w.  j a v  a 2 s . c o m*/
        Context initContext = new InitialContext();

        // load pool properties file (from class path)
        poolProp.load(ConnectionListener.class.getResourceAsStream("/jdbc_pools.properties"));
        StringTokenizer stk = new StringTokenizer(poolProp.getProperty("PROP_LIST"));

        // process all properties files list in pool properties (from class
        // path)
        while (stk.hasMoreTokens()) {
            try {
                String propName = stk.nextToken();
                LOGGER.info(this, "loading jdbc properties - " + propName);

                Properties prop = new Properties();
                prop.load(ConnectionListener.class.getResourceAsStream(propName));

                DataSource dsr;
                if (prop.containsKey("JNDI_NAME")) {
                    // lookup DataSource from JNDI
                    // FIXME JNDI support is not tested yet. SPI or Factory
                    // is needed here.
                    LOGGER.warn(this, "JNDI DataSource support needs more hands on!");
                    dsr = (DataSource) initContext.lookup(prop.getProperty("JNDI_NAME"));
                } else {
                    // create new BasicDataSource
                    BasicDataSource bds = new BasicDataSource();
                    bds.setMaxActive(Integer.parseInt(prop.getProperty("MAX_ACTIVE")));
                    bds.setMaxIdle(Integer.parseInt(prop.getProperty("MAX_IDLE")));
                    bds.setMaxWait(Integer.parseInt(prop.getProperty("MAX_WAIT")));
                    bds.setInitialSize(Integer.parseInt(prop.getProperty("INITIAL")));
                    bds.setDriverClassName(prop.getProperty("CLASS_NAME"));
                    bds.setUrl(prop.getProperty("URL"));
                    bds.setUsername(prop.getProperty("USER"));
                    bds.setPassword(prop.getProperty("PASSWORD"));
                    bds.setValidationQuery(prop.getProperty("VALIDATION"));
                    dsr = bds;
                }
                boundDsrs.put(prop.getProperty("POOL_NAME"), dsr);
                initContext.bind(prop.getProperty("POOL_NAME"), dsr);
            } catch (RuntimeException e) {
                LOGGER.trace(e);
            }
        }
    } catch (IOException | NamingException e) {
        LOGGER.trace(e);
    }
}

From source file:com.uber.hoodie.hive.HoodieHiveClient.java

private void createHiveConnection() {
    if (connection == null) {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driverName);
        ds.setUrl(getHiveJdbcUrlWithDefaultDBName());
        ds.setUsername(syncConfig.hiveUser);
        ds.setPassword(syncConfig.hivePass);
        LOG.info("Getting Hive Connection from Datasource " + ds);
        try {//from w w w.ja v  a 2s  .  c om
            this.connection = ds.getConnection();
        } catch (SQLException e) {
            throw new HoodieHiveSyncException(
                    "Cannot create hive connection " + getHiveJdbcUrlWithDefaultDBName(), e);
        }
    }
}

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from ww  w  .  j  a  v a  2s . co m*/
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(false);

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

From source file:com.emc.ecs.sync.source.AtmosSource.java

@Override
public void parseCustomOptions(CommandLine line) {
    AtmosUtil.AtmosUri atmosUri = AtmosUtil.parseUri(sourceUri);
    endpoints = atmosUri.endpoints;/*  w w w  .jav a 2s .  c o m*/
    uid = atmosUri.uid;
    secret = atmosUri.secret;
    namespaceRoot = atmosUri.rootPath;

    if (line.hasOption(SOURCE_OIDLIST_OPTION))
        oidFile = line.getOptionValue(SOURCE_OIDLIST_OPTION);

    if (line.hasOption(SOURCE_NAMELIST_OPTION))
        nameFile = line.getOptionValue(SOURCE_NAMELIST_OPTION);

    if (line.hasOption(SOURCE_SQLQUERY_OPTION)) {
        query = line.getOptionValue(SOURCE_SQLQUERY_OPTION);

        // Initialize a connection pool
        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(line.getOptionValue(JDBC_URL_OPT));
        if (line.hasOption(JDBC_DRIVER_OPT))
            ds.setDriverClassName(line.getOptionValue(JDBC_DRIVER_OPT));
        ds.setUsername(line.getOptionValue(JDBC_USER_OPT));
        ds.setPassword(line.getOptionValue(JDBC_PASSWORD_OPT));
        ds.setMaxActive(200);
        ds.setMaxOpenPreparedStatements(180);
        setDataSource(ds);
    }

    deleteTags = line.hasOption(DELETE_TAGS_OPT);
}