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.gvsig.fmap.dal.store.jdbc.JDBCResource.java

protected DataSource createDataSource() {
    JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*/*from   w w  w  .  j  av a  2  s . c o  m*/
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
       .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
     */
    return dataSource;
}

From source file:org.gvsig.fmap.dal.store.jdbc.JDBCResource.java

protected void connectToDB() throws DataException {
    if (this.dataSource != null) {
        return;// w  w  w.  j  a  va 2 s.co  m
    }
    JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
    .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
    */

    this.dataSource = dataSource;
}

From source file:org.gvsig.fmap.dal.store.mysql.MySQLResource.java

protected DataSource createDataSource() {
    MySQLResourceParameters jdbcParams = (MySQLResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*/*w w  w  . j  a  v  a 2s.  c o m*/
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
       .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
     */
    return dataSource;
}

From source file:org.gvsig.fmap.dal.store.postgresql.PostgreSQLResource.java

protected DataSource createDataSource() {
    PostgreSQLResourceParameters jdbcParams = (PostgreSQLResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*//from  w  w w .j a  va2s .  c o m
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
       .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
     */
    return dataSource;
}

From source file:org.hibernate.spatial.testing.DataSourceUtils.java

private void createBasicDataSource() {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(jdbcDriver);/*from w w w. j  a  va 2  s  .  c  o m*/
    bds.setUrl(jdbcUrl);
    bds.setUsername(jdbcUser);
    bds.setPassword(jdbcPass);
    dataSource = bds;
}

From source file:org.jfaster.mango.support.DataSourceConfig.java

public static DataSource getDataSource(int i) {
    String driverClassName = getDriverClassName(i);
    String url = getUrl(i);//ww w. j  av  a  2s .  com
    String username = getUsername(i);
    String password = getPassword(i);

    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(url);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setInitialSize(1);
    ds.setMaxActive(1);
    ds.setDriverClassName(driverClassName);
    return ds;
}

From source file:org.jooq.example.spark.SparkCRUD.java

public static void main(String[] args) throws Exception {
    final BasicDataSource ds = new BasicDataSource();
    final Properties properties = new Properties();
    properties.load(SparkCRUD.class.getResourceAsStream("/config.properties"));

    ds.setDriverClassName(properties.getProperty("db.driver"));
    ds.setUrl(properties.getProperty("db.url"));
    ds.setUsername(properties.getProperty("db.username"));
    ds.setPassword(properties.getProperty("db.password"));

    final DSLContext ctx = DSL.using(ds, SQLDialect.H2);

    // Creates a new book resource, will return the ID to the created resource
    // author and title are sent as query parameters e.g. /books?author=Foo&title=Bar
    post("/books", (request, response) -> {
        AuthorRecord author = upsertAuthor(ctx, request);

        BookRecord book = ctx.newRecord(BOOK);
        book.setAuthorId(author.getId());
        book.setTitle(request.queryParams("title"));
        book.store();/*w w w  .  j ava 2 s  . co  m*/

        response.status(201); // 201 Created
        return book.getId();
    });

    // Gets the book resource for the provided id
    get("/books/:id", (request, response) -> {
        Record2<String, String> book = ctx.select(BOOK.TITLE, AUTHOR.NAME).from(BOOK).join(AUTHOR)
                .on(BOOK.AUTHOR_ID.eq(AUTHOR.ID))
                .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne();

        if (book != null) {
            return "Title: " + book.value1() + ", Author: " + book.value2();
        } else {
            response.status(404); // 404 Not found
            return "Book not found";
        }
    });

    // Updates the book resource for the provided id with new information
    // author and title are sent as query parameters e.g. /books/<id>?author=Foo&title=Bar
    put("/books/:id", (request, response) -> {
        BookRecord book = ctx.selectFrom(BOOK)
                .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne();

        if (book != null) {
            AuthorRecord author = upsertAuthor(ctx, request);

            String newAuthor = request.queryParams("author");
            String newTitle = request.queryParams("title");

            if (newAuthor != null) {
                book.setAuthorId(author.getId());
            }
            if (newTitle != null) {
                book.setTitle(newTitle);
            }

            book.update();
            return "Book with id '" + book.getId() + "' updated";
        } else {
            response.status(404); // 404 Not found
            return "Book not found";
        }
    });

    // Deletes the book resource for the provided id
    delete("/books/:id", (request, response) -> {
        BookRecord book = ctx.deleteFrom(BOOK)
                .where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).returning().fetchOne();

        if (book != null) {
            return "Book with id '" + book.getId() + "' deleted";
        } else {
            response.status(404); // 404 Not found
            return "Book not found";
        }
    });

    // Gets all available book resources (id's)
    get("/books", (request, response) -> {
        return ctx.select(BOOK.ID).from(BOOK).fetch(BOOK.ID).stream().map(Object::toString)
                .collect(Collectors.joining(" "));
    });
}

From source file:org.jxstar.dao.pool.PooledConnection.java

/**
 * ???//from   w w w.  j a  v  a  2 s. com
 * @param dsName
 * @return
 */
private DataSource createSelfDataSource(DataSourceConfig dsConfig) {
    String dsName = dsConfig.getDataSourceName();
    BasicDataSource ds = (BasicDataSource) _myDataSourceMap.get(dsName);
    if (ds != null)
        return ds;

    ds = new BasicDataSource();
    //???
    int iTranLevel = getTranLevelConstant(dsConfig.getTranLevel());
    int maxnum = Integer.parseInt(dsConfig.getMaxConNum());

    ds.setDriverClassName(dsConfig.getDriverClass());
    ds.setUrl(dsConfig.getJdbcUrl());
    ds.setUsername(dsConfig.getUserName());
    ds.setPassword(dsConfig.getPassWord());

    ds.setMaxIdle(maxnum);
    ds.setMaxActive(maxnum);
    ds.setMaxWait(Long.parseLong(dsConfig.getMaxWaitTime()));
    ds.setDefaultAutoCommit(false);
    ds.setDefaultTransactionIsolation(iTranLevel);

    //????SystemVarserver.xml?
    String validTest = dsConfig.getValidTest();
    String validQuery = dsConfig.getValidQuery();
    if (validTest.equalsIgnoreCase("true") && validQuery.length() > 0) {
        _log.showDebug("pool test use query...");
        ds.setTestOnBorrow(true);
        ds.setValidationQuery(validQuery);
        ds.setValidationQueryTimeout(3);
    }

    //?mysql???
    //?????
    if (dsConfig.getValidIdle().equalsIgnoreCase("true")) {
        _log.showDebug("pool idle valid thread started...");
        ds.setMinIdle(5);
        ds.setTestWhileIdle(true);

        //1030?5
        ds.setMinEvictableIdleTimeMillis(30 * 60 * 1000);//30 minus
        ds.setTimeBetweenEvictionRunsMillis(10 * 60 * 1000);//10 minus
    }

    //???
    _myDataSourceMap.put(dsName, ds);

    return ds;
}

From source file:org.kaaproject.kaa.server.datamigration.utils.DataSources.java

/**
 * Create data source based on passed options.
 *
 * @param opt options that used to build data source
 * @return the data source//from  w w  w. ja v a  2 s  .  c o  m
 */
public static DataSource getDataSource(Options opt) {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(opt.getDriverClassName());
    bds.setUrl(opt.getJdbcUrl());
    bds.setUsername(opt.getUsername());
    bds.setPassword(opt.getPassword());
    bds.setDefaultAutoCommit(false);
    return bds;
}

From source file:org.karsha.lucene.jdbc.JDBCDatabaseUtil.java

/**
 * Gets the data source./*from   w  w w.j a  v  a  2s .c om*/
 * 
 * @return the data source
 */
public synchronized static DataSource getDataSource() {

    // String url = "jdbc:mysql://rss1.stratoslive.wso2.com/karsha_annotate_karsha_opensource_lk";
    //            String username = "adm_ann_lQrhzZUK";
    //           String password = "admin@lsf";
    //MysqlDataSource dataSource = new MysqlDataSource();
    BasicDataSource dataSource = new BasicDataSource();
    //                dataSource.setUser("adm_ann_lQrhzZUK");             
    //      dataSource.setPassword("admin@lsf");
    //      dataSource.setUrl("jdbc:mysql://rss1.stratoslive.wso2.com/karsha_annotate_karsha_opensource_lk");

    dataSource.setUsername("admin_i+APQovg");
    dataSource.setPassword("admin");

    //emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
    dataSource.setUrl(
            "jdbc:mysql://rss1.stratoslive.wso2.com/karshaindex_kasunperera_com?emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false");

    //                dataSource.setUsername("root");                
    //      dataSource.setPassword("nbuser");
    //                dataSource.setUrl("jdbc:mysql://localhost:3306/karshaindex?emulateLocators=true&useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false");
    // dataSource.setEmulateLocators(true);
    return dataSource;
}