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:org.owasp.dependencytrack.config.DatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(driverClassName);
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    basicDataSource.setUrl(url);//from  ww w  .j a va  2 s .  co m
    basicDataSource.setMaxActive(maxActive);
    return basicDataSource;
}

From source file:org.owasp.dependencytrack.config.JunitDatabaseConfiguration.java

@Bean
public DataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName("org.h2.Driver");
    basicDataSource.setUsername("sa");
    basicDataSource.setPassword("");
    basicDataSource.setUrl("jdbc:h2:mem:dtrack");
    basicDataSource.setMaxActive(100);/* w  w  w .  j a va 2s .c  o  m*/
    return basicDataSource;
}

From source file:org.paxml.tag.sql.SqlDataSourceTag.java

private DataSource getCacheOrCreate() {
    String key = getCacheKey();/*from   ww  w .  java2s .c  o  m*/
    DataSource ds = CACHE.get(key);
    if (ds == null) {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(getDriver());
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setDefaultAutoCommit(true);
        DataSource existing = CACHE.putIfAbsent(key, dataSource);
        if (existing != null) {
            ds = existing;
        } else {
            ds = dataSource;
        }
    }
    return ds;
}

From source file:org.paxml.util.DBUtils.java

public static DataSource getPooledDataSource(String driverClass, String username, String password, String url) {
    String key = driverClass + "::" + url;
    BasicDataSource ds = pooledDataSources.get(key);
    if (ds == null) {
        ds = new BasicDataSource();
        ds.setDriverClassName(driverClass);
        ds.setUsername(username);
        ds.setPassword(password);/*from   w w  w  .  j  a  v a2  s.  co  m*/
        ds.setUrl(url);
        BasicDataSource existingDs = pooledDataSources.putIfAbsent(key, ds);
        if (existingDs != null) {
            try {
                ds.close();
            } catch (SQLException e) {
                // do nothing
            }
            ds = existingDs;
        }

    }

    return ds;
}

From source file:org.pentaho.platform.engine.services.connection.datasource.dbcp.NonPooledDatasourceService.java

private DataSource convert(IDatasource datasource) {
    BasicDataSource basicDatasource = new BasicDataSource();
    basicDatasource.setDriverClassName(datasource.getDriverClass());
    basicDatasource.setMaxActive(datasource.getMaxActConn());
    basicDatasource.setMaxIdle(datasource.getIdleConn());
    basicDatasource.setMaxWait(datasource.getWait());
    basicDatasource.setUrl(datasource.getUrl());
    basicDatasource.setUsername(datasource.getUserName());
    basicDatasource.setPassword(datasource.getPassword());
    basicDatasource.setValidationQuery(datasource.getQuery());
    return basicDatasource;
}

From source file:org.pinus4j.cluster.impl.AppDBClusterImpl.java

@Override
public void buildDataSource(DBInfo dbConnInfo) throws LoadConfigException {
    AppDBInfo appDbConnInfo = (AppDBInfo) dbConnInfo;

    LOG.info(dbConnInfo.toString());//from ww  w  .  j  a v  a  2  s.c  o  m

    try {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(enumDb.getDriverClass());
        ds.setUsername(appDbConnInfo.getUsername());
        ds.setPassword(appDbConnInfo.getPassword());
        ds.setUrl(appDbConnInfo.getUrl());

        // ?
        Map<String, Object> dbConnPoolInfo = appDbConnInfo.getConnPoolInfo();
        ds.setValidationQuery("SELECT 1");
        ds.setMaxActive((Integer) dbConnPoolInfo.get(Const.PROP_MAXACTIVE));
        ds.setMinIdle((Integer) dbConnPoolInfo.get(Const.PROP_MINIDLE));
        ds.setMaxIdle((Integer) dbConnPoolInfo.get(Const.PROP_MAXIDLE));
        ds.setInitialSize((Integer) dbConnPoolInfo.get(Const.PROP_INITIALSIZE));
        ds.setRemoveAbandoned((Boolean) dbConnPoolInfo.get(Const.PROP_REMOVEABANDONED));
        ds.setRemoveAbandonedTimeout((Integer) dbConnPoolInfo.get(Const.PROP_REMOVEABANDONEDTIMEOUT));
        ds.setMaxWait((Integer) dbConnPoolInfo.get(Const.PROP_MAXWAIT));
        ds.setTimeBetweenEvictionRunsMillis(
                (Integer) dbConnPoolInfo.get(Const.PROP_TIMEBETWEENEVICTIONRUNSMILLIS));
        ds.setNumTestsPerEvictionRun((Integer) dbConnPoolInfo.get(Const.PROP_NUMTESTSPEREVICTIONRUN));
        ds.setMinEvictableIdleTimeMillis((Integer) dbConnPoolInfo.get(Const.PROP_MINEVICTABLEIDLETIMEMILLIS));

        dbConnInfo.setDatasource(ds);
    } catch (Exception e) {
        throw new LoadConfigException(e);
    }
}

From source file:org.plista.kornakapi.core.storage.MySqlStorage.java

public MySqlStorage(StorageConfiguration storageConf, String label, BasicDataSource dataSource) {

    dataSource.setDriverClassName(storageConf.getJdbcDriverClass());
    dataSource.setUrl(storageConf.getJdbcUrl());
    dataSource.setUsername(storageConf.getUsername());
    dataSource.setPassword(storageConf.getPassword());

    //TODO should be made configurable
    dataSource.setMaxActive(10);//from w ww  .j av a2  s  . c  o m
    dataSource.setMinIdle(5);
    dataSource.setInitialSize(5);
    dataSource.setValidationQuery("SELECT 1;");
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setTestWhileIdle(true);
    dataSource.setTimeBetweenEvictionRunsMillis(5000);

    dataModel = new LabeledMySQLJDBCDataModel(dataSource, "taste_preferences", "user_id", "item_id",
            "preference", "timestamp", "taste_candidates", "label", label);
    this.dataSource = dataSource;
    this.timeWindow = storageConf.getTimeWindow();
    if (timeWindow % 6 != 0 || timeWindow == 0) {
        timeWindow = 24;
    }

}

From source file:org.polyjdbc.core.infrastructure.DataSourceFactory.java

public static DataSource create(Dialect dialect, String databaseUrl, String user, String password) {
    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(DIALECT_DRIVER_CLASS.get(dialect.getCode()));
    dataSource.setUrl(databaseUrl);//from  w w w  .  j a  v a2 s .c  o  m
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setDefaultAutoCommit(false);

    return dataSource;
}

From source file:org.polymap.catalog.h2.data.H2DataStoreFactory.java

protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException {
    String database = (String) DATABASE.lookUp(params);
    String host = (String) HOST.lookUp(params);
    BasicDataSource dataSource = new BasicDataSource();

    if (host != null && !host.equals("")) {
        Integer port = (Integer) PORT.lookUp(params);
        if (port != null && !port.equals("")) {
            dataSource.setUrl("jdbc:h2:tcp://" + host + ":" + port + "/" + database);
        } else {/*  w ww  .j  av a2s . c o m*/
            dataSource.setUrl("jdbc:h2:tcp://" + host + "/" + database);
        }
    } else if (baseDirectory == null) {
        //use current working directory
        dataSource.setUrl("jdbc:h2:" + database);
    } else {
        //use directory specified if the patch is relative
        String location;
        if (!new File(database).isAbsolute()) {
            location = new File(baseDirectory, database).getAbsolutePath();
        } else {
            location = database;
        }

        // falko: add support for NIO
        String osName = System.getProperty("os.name");
        Boolean nio = (Boolean) NIO.lookUp(params);
        Boolean nioMapped = (Boolean) NIO_MAPPED.lookUp(params);

        String url = null;
        if ((nio != null && nio.booleanValue())
        /*|| osName.toLowerCase().contains( "linux" )*/) {
            url = "jdbc:h2:nio:" + location;
        } else if ((nioMapped != null && nioMapped.booleanValue())) {
            url = "jdbc:h2:nioMapped:" + location;
        } else {
            url = "jdbc:h2:file:" + location;
        }

        // falko: multi threaded on 
        //url += ";MULTI_THREADED=1";
        dataSource.setUrl(url);
    }

    String username = (String) USER.lookUp(params);
    if (username != null) {
        dataSource.setUsername(username);
    }
    String password = (String) PASSWD.lookUp(params);
    if (password != null) {
        dataSource.setPassword(password);
    }

    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setPoolPreparedStatements(false);

    return dataSource;
}

From source file:org.projectforge.continuousdb.demo.DemoMain.java

private DemoMain() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUsername("sa");
    // dataSource.setPassword("password");
    dataSource.setUrl("jdbc:hsqldb:testdatabase");

    configuration = new UpdaterConfiguration().setDialect(DatabaseDialect.HSQL).setDataSource(dataSource);
    databaseUpdateDao = configuration.getDatabaseUpdateDao();
    // TableAttribute.register(new TableAttributeHookImpl());

    // final SortedSet<UpdateEntry> updateEntries = new TreeSet<UpdateEntry>();
    // updateEntries.addAll(DatabaseCoreUpdates.getUpdateEntries(this));
    // getSystemUpdater().setUpdateEntries(updateEntries);
}