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

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

Introduction

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

Prototype

public synchronized void setDefaultAutoCommit(boolean defaultAutoCommit) 

Source Link

Document

Sets default auto-commit state of connections returned by this datasource.

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

Usage

From source file:de.iteratec.iteraplan.businesslogic.service.DataSourceServiceImpl.java

/** {@inheritDoc} */
public void initializeDBwithKey(String key) {
    DataSource dataSource = validateKey(key);
    if (dataSource == null) {
        // The key points to the MASTER data source. Nothing todo.
        return;/*w ww. jav a 2s  .  c om*/
    }

    // Validation succeeded.
    // Add the data source only if it is not contained already.
    if (!routingDataSource.isKeyContained(key)) {

        // Create a basic data source.
        BasicDataSource ds = new CachableBasicDataSource();
        ds.setDriverClassName(dataSource.getDriver());
        ds.setUrl(dataSource.getUrl());
        ds.setUsername(dataSource.getUser());
        ds.setPassword(dataSource.getPassword());
        ds.setDefaultAutoCommit(false);

        String validationQuery = IteraplanProperties.getProperties()
                .getProperty(IteraplanProperties.DATABASE_VALIDATIONQUERY);
        ds.setValidationQuery(validationQuery);
        ds.setTestOnBorrow(true);
        // basicDataSource.setMaxActive(5);
        // basicDataSource.setMinIdle(1);

        routingDataSource.addCachableBasicDataSource(key, ds);
    }
}

From source file:hoot.services.testsupport.HootServicesSpringTestConfig.java

@Bean(name = "dataSource")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.postgresql.Driver");
    dataSource.setUrl("jdbc:postgresql://localhost:5432/hoot");
    dataSource.setUsername("hoot");
    dataSource.setPassword("hoottest");
    dataSource.setInitialSize(5);//  w w w  . ja va  2 s.co m
    dataSource.setMaxActive(10);
    dataSource.setMaxIdle(2);
    dataSource.setDefaultAutoCommit(false);
    dataSource.setRemoveAbandoned(true);
    dataSource.setLogAbandoned(true);
    return dataSource;
}

From source file:gxu.software_engineering.shen10.market.core.SpringBeans.java

@Bean(destroyMethod = "close")
public DataSource dataSource() {
    Properties props = new Properties();
    InputStream in = null;// ww  w . j  a v a  2  s . c  om
    try {
        in = this.getClass().getResourceAsStream("/db/dataSource.properties");
        props.load(in);
    } catch (IOException e) {
        L.error("????", e);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            L.error("wtf!", e);
        }
    }
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(props.getProperty("db.driver"));
    dataSource.setUrl(props.getProperty("db.url"));
    dataSource.setUsername(props.getProperty("db.username"));
    dataSource.setPassword(props.getProperty("db.password"));
    dataSource.setDefaultAutoCommit(false);
    return dataSource;
}

From source file:cn.newgxu.lab.core.config.SpringBeans.java

@Bean(destroyMethod = "close")
public DataSource dataSource() {
    Properties props = new Properties();
    InputStream in = null;/*w  ww.  java2s  .c  o  m*/
    try {
        in = this.getClass().getResourceAsStream("/config/dataSource.properties");
        props.load(in);
    } catch (IOException e) {
        L.error("????", e);
    } finally {
        try {
            in.close();
        } catch (IOException e) {
            L.error("wtf!", e);
        }
    }
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(props.getProperty("db.driver"));
    dataSource.setUrl(props.getProperty("db.url"));
    dataSource.setUsername(props.getProperty("db.username"));
    dataSource.setPassword(props.getProperty("db.password"));
    dataSource.setDefaultAutoCommit(false);
    return dataSource;
}

From source file:hoot.services.HootServicesSpringConfig.java

@Bean(name = "dataSource")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.postgresql.Driver");
    dataSource.setUrl("jdbc:postgresql://" + env.getProperty("DB_HOST") + ":" + env.getProperty("DB_PORT") + "/"
            + env.getProperty("DB_NAME"));
    dataSource.setUsername(env.getProperty("DB_USER"));
    dataSource.setPassword(env.getProperty("DB_PASSWORD"));
    dataSource.setInitialSize(25);/*from ww w.j  a va  2 s  . com*/
    dataSource.setMaxActive(90);
    dataSource.setMaxIdle(30);
    dataSource.setDefaultAutoCommit(false);
    dataSource.setRemoveAbandoned(true);
    dataSource.setLogAbandoned(true);
    return dataSource;
}

From source file:com.norconex.collector.http.db.impl.derby.DerbyCrawlURLDatabase.java

private DataSource createDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    ds.setUrl("jdbc:derby:" + dbDir + ";create=true");
    ds.setDefaultAutoCommit(true);
    return ds;/*w  ww  . ja  v a  2s. co  m*/
}

From source file:com.bstek.dorado.core.store.SqlBaseStoreSupport.java

protected synchronized DataSource getDataSource() throws Exception {
    if (dataSource != null) {
        return dataSource;
    }/*ww w.  j ava2  s . co  m*/

    if (StringUtils.isBlank(namespace)) {
        throw new IllegalArgumentException("The namespace of store cannot be empty. ");
    }

    prepareNamespace();

    BasicDataSource pds = new BasicDataSource();
    dataSource = pds;

    pds.setDriverClassName(driverClassName);
    pds.setUrl(getConnectionUrl());
    pds.setUsername(username);
    pds.setPassword(password);
    pds.setDefaultCatalog(defaultCatalog);

    if (defaultAutoCommit != null) {
        pds.setDefaultAutoCommit(defaultAutoCommit.booleanValue());
    }
    if (defaultReadOnly != null) {
        pds.setDefaultReadOnly(defaultReadOnly.booleanValue());
    }
    if (defaultTransactionIsolation != null) {
        pds.setDefaultTransactionIsolation(defaultTransactionIsolation.intValue());
    }
    if (maxActive != null) {
        pds.setMaxActive(maxActive.intValue());
    }
    if (maxIdle != null) {
        pds.setMaxIdle(maxIdle.intValue());
    }
    if (minIdle != null) {
        pds.setMinIdle(minIdle.intValue());
    }
    if (initialSize != null) {
        pds.setInitialSize(initialSize.intValue());
    }
    if (maxWait != null) {
        pds.setMaxWait(maxWait.longValue());
    }
    if (timeBetweenEvictionRunsMillis != null) {
        pds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis.longValue());
    }
    if (minEvictableIdleTimeMillis != null) {
        pds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis.longValue());
    }
    return dataSource;
}

From source file:cn.cuizuoli.gotour.config.DataSourceConfig.java

@Bean
public DataSource userDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(env.getRequiredProperty("user.jdbc.driverClassName"));
    dataSource.setUrl(env.getRequiredProperty("user.jdbc.url"));
    dataSource.setUsername(env.getRequiredProperty("user.jdbc.username"));
    dataSource.setPassword(env.getRequiredProperty("user.jdbc.password"));
    dataSource.setInitialSize(env.getRequiredProperty("jdbc.initialSize", Integer.class));
    dataSource.setMaxActive(env.getRequiredProperty("jdbc.maxActive", Integer.class));
    dataSource.setMaxIdle(env.getRequiredProperty("jdbc.maxIdle", Integer.class));
    dataSource.setMinIdle(env.getRequiredProperty("jdbc.minIdle", Integer.class));
    dataSource.setDefaultAutoCommit(env.getRequiredProperty("jdbc.defaultAutoCommit", Boolean.class));
    dataSource.setPoolPreparedStatements(env.getRequiredProperty("jdbc.poolPreparedStatements", Boolean.class));
    dataSource.setValidationQuery(env.getRequiredProperty("jdbc.validationQuery"));
    dataSource.setTestOnBorrow(env.getRequiredProperty("jdbc.testOnBorrow", Boolean.class));
    dataSource.setTestOnReturn(env.getRequiredProperty("jdbc.testOnReturn", Boolean.class));
    dataSource.setTestWhileIdle(env.getRequiredProperty("jdbc.testWhileIdle", Boolean.class));
    dataSource.setTimeBetweenEvictionRunsMillis(
            env.getRequiredProperty("jdbc.timeBetweenEvictionRunsMillis", Long.class));
    dataSource.setNumTestsPerEvictionRun(env.getRequiredProperty("jdbc.numTestsPerEvictionRun", Integer.class));
    dataSource.setMinEvictableIdleTimeMillis(
            env.getRequiredProperty("jdbc.minEvictableIdleTimeMillis", Long.class));
    return dataSource;
}

From source file:jetsennet.orm.datasource.DbcpDataSourceCreator.java

@Override
public DataSource createDatasource(ConnectionInfo conn, DbPoolInfo props) throws SQLException {
    org.apache.commons.dbcp.BasicDataSource dataSource = new org.apache.commons.dbcp.BasicDataSource();
    dataSource.setDriverClassName(conn.driver);
    dataSource.setUrl(conn.url);/* www  .j a  v  a  2s .  c  om*/
    dataSource.setUsername(conn.user);
    dataSource.setPassword(conn.pwd);

    String connectionProperties = props.get("connectionProperties");
    if (connectionProperties != null && connectionProperties.trim().length() > 0) {
        dataSource.setConnectionProperties(connectionProperties);
    }
    Boolean defaultAutoCommit = Utils.str2Boolean(props.get("defaultAutoCommit"));
    if (defaultAutoCommit != null) {
        dataSource.setDefaultAutoCommit(defaultAutoCommit);
    }
    Boolean defaultReadOnly = Utils.str2Boolean(props.get("defaultReadOnly"));
    if (defaultReadOnly != null) {
        dataSource.setDefaultReadOnly(defaultReadOnly);
    }
    Integer defaultTransactionIsolation = Utils.strToInteger(props.get("defaultTransactionIsolation"));
    if (defaultTransactionIsolation != null) {
        dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    }
    String defaultCatalog = props.get("defaultCatalog");
    if (defaultCatalog != null && defaultCatalog.trim().length() > 0) {
        dataSource.setDefaultCatalog(defaultCatalog);
    }

    int initialSize = Utils.strToInt(props.get("initialSize"));
    if (initialSize > 0) {
        dataSource.setInitialSize(initialSize);
    }
    int maxActive = Utils.strToInt(props.get("maxActive"));
    if (maxActive > 0) {
        dataSource.setMaxActive(maxActive);
    }
    int maxIdle = Utils.strToInt(props.get("maxIdle"));
    if (maxIdle > 0) {
        dataSource.setMaxIdle(maxIdle);
    }
    int minIdle = Utils.strToInt(props.get("minIdle"));
    if (minIdle > 0) {
        dataSource.setMinIdle(minIdle);
    }
    int maxWait = Utils.strToInt(props.get("maxWait"));
    if (maxWait > 0) {
        dataSource.setMaxWait(maxWait);
    }

    String validationQuery = props.get("validationQuery");
    if (validationQuery != null && validationQuery.trim().length() > 0) {
        dataSource.setValidationQuery(validationQuery);
    }
    Integer validationQueryTimeout = Utils.strToInteger(props.get("validationQueryTimeout"));
    if (validationQueryTimeout != null) {
        dataSource.setValidationQueryTimeout(validationQueryTimeout);
    }
    Boolean testOnBorrow = Utils.str2Boolean(props.get("testOnBorrow"));
    if (testOnBorrow != null) {
        dataSource.setTestOnBorrow(testOnBorrow);
    }
    Boolean testOnReturn = Utils.str2Boolean(props.get("testOnReturn"));
    if (testOnReturn != null) {
        dataSource.setTestOnReturn(testOnReturn);
    }
    Boolean testWhileIdle = Utils.str2Boolean(props.get("testWhileIdle"));
    if (testWhileIdle != null) {
        dataSource.setTestWhileIdle(testWhileIdle);
    }
    Integer timeBetweenEvictionRunsMillis = Utils.strToInteger(props.get("timeBetweenEvictionRunsMillis"));
    if (timeBetweenEvictionRunsMillis != null) {
        dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    }
    Integer numTestsPerEvictionRun = Utils.strToInteger(props.get("numTestsPerEvictionRun"));
    if (numTestsPerEvictionRun != null) {
        dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    }
    int minEvictableIdleTimeMillis = Utils.strToInt(props.get("minEvictableIdleTimeMillis"));
    if (minEvictableIdleTimeMillis > 0) {
        dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    }

    Boolean removeAbandoned = Utils.str2Boolean(props.get("removeAbandoned"));
    if (removeAbandoned != null) {
        dataSource.setRemoveAbandoned(removeAbandoned);
    }
    int removeAbandonedTimeout = Utils.strToInt(props.get("removeAbandonedTimeout"));
    if (removeAbandonedTimeout > 0) {
        dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    }
    Boolean logAbandoned = Utils.str2Boolean(props.get("logAbandoned"));
    if (logAbandoned != null) {
        dataSource.setLogAbandoned(logAbandoned);
    }
    return dataSource;
}

From source file:cn.cuizuoli.gotour.config.DataSourceConfig.java

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(env.getRequiredProperty("gotour.jdbc.driverClassName"));
    dataSource.setUrl(env.getRequiredProperty("gotour.jdbc.url"));
    dataSource.setUsername(env.getRequiredProperty("gotour.jdbc.username"));
    dataSource.setPassword(env.getRequiredProperty("gotour.jdbc.password"));
    dataSource.setInitialSize(env.getRequiredProperty("jdbc.initialSize", Integer.class));
    dataSource.setMaxActive(env.getRequiredProperty("jdbc.maxActive", Integer.class));
    dataSource.setMaxIdle(env.getRequiredProperty("jdbc.maxIdle", Integer.class));
    dataSource.setMinIdle(env.getRequiredProperty("jdbc.minIdle", Integer.class));
    dataSource.setDefaultAutoCommit(env.getRequiredProperty("jdbc.defaultAutoCommit", Boolean.class));
    dataSource.setPoolPreparedStatements(env.getRequiredProperty("jdbc.poolPreparedStatements", Boolean.class));
    dataSource.setValidationQuery(env.getRequiredProperty("jdbc.validationQuery"));
    dataSource.setTestOnBorrow(env.getRequiredProperty("jdbc.testOnBorrow", Boolean.class));
    dataSource.setTestOnReturn(env.getRequiredProperty("jdbc.testOnReturn", Boolean.class));
    dataSource.setTestWhileIdle(env.getRequiredProperty("jdbc.testWhileIdle", Boolean.class));
    dataSource.setTimeBetweenEvictionRunsMillis(
            env.getRequiredProperty("jdbc.timeBetweenEvictionRunsMillis", Long.class));
    dataSource.setNumTestsPerEvictionRun(env.getRequiredProperty("jdbc.numTestsPerEvictionRun", Integer.class));
    dataSource.setMinEvictableIdleTimeMillis(
            env.getRequiredProperty("jdbc.minEvictableIdleTimeMillis", Long.class));
    return dataSource;
}