Package org.apache.commons.dbcp.managed

Examples of org.apache.commons.dbcp.managed.BasicManagedDataSource


    *
    * @param jpaProperties
    * @return
    */   
    private static DataSource createDataSource(Properties jpaProperties) {
        BasicManagedDataSource ds = new BasicManagedDataSource();
        Current tm = new Current();
        ds.setAccessToUnderlyingConnectionAllowed(true);
        ds.setConnectionInitSqls(Collections.EMPTY_LIST);
        ds.setDefaultAutoCommit(true);
//        ds.setDefaultCatalog("mw_as"); // not needed when using the url...
        ds.setDefaultReadOnly(false);
//        ds.setDefaultTransactionIsolation(0);
        ds.setDriverClassLoader(ClassLoader.getSystemClassLoader());
        ds.setDriverClassName(jpaProperties.getProperty("javax.persistence.jdbc.driver"));
        ds.setInitialSize(10);
        ds.setLogAbandoned(true);
//        ds.setLogWriter(null); // null disables logging; TODO: see if we can get a PrintWriter from slf4j... and for some reason calls createDataSource() whic hdoesn't make sense
//        ds.setLoginTimeout(30); // in seconds ;   not supported by basicdatasource... and for some reason calls createDataSource() whic hdoesn't make sense
        ds.setMaxActive(50); // max 50 active connections to database
        ds.setMaxIdle(10); // max 10 idle connections in the pool
        ds.setMaxOpenPreparedStatements(-1); // no limit
        ds.setMaxWait(-1); // wait indefinitely for a new connection from the pool
        ds.setMinEvictableIdleTimeMillis(1000*60*30); // (milliseconds) connection may be idle up to 30 minutes before being evicted
        ds.setMinIdle(5); // min 5 idle connections in the pool
        ds.setNumTestsPerEvictionRun(10); // how many connections to test each time
        ds.setPassword(jpaProperties.getProperty("javax.persistence.jdbc.password"));
        ds.setPoolPreparedStatements(true);
        ds.setRemoveAbandoned(true);
        ds.setRemoveAbandonedTimeout(60*60); // (seconds) connection may be abandoned for up to an hour before being removed
        ds.setTestOnBorrow(true);
        ds.setTestOnReturn(false);
        ds.setTestWhileIdle(true);
        ds.setTimeBetweenEvictionRunsMillis(1000*60); // (milliseconds) check which idle connections should be evicted once every minute
        ds.setUrl(jpaProperties.getProperty("javax.persistence.jdbc.url"));
        ds.setUsername(jpaProperties.getProperty("javax.persistence.jdbc.user"));
        ds.setValidationQuery("SELECT 1");
        ds.setValidationQueryTimeout(2); // (seconds) how long to wait on a result for the validation query before giving up
//        DataSourceConnectionFactory connectionFactory = new DataSourceConnectionFactory(dataSource, dbUsername, dbPassowrd);
//        PoolableConnectionFactory dbcpFactory = new PoolableConnectionFactory(connectionFactory, pool, validationQuery, validationQueryTimeoutSeconds, false, false);
//        poolingDataSource = new PoolingDataSource(pool);
        ds.setTransactionManager(tm);
        return ds;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.dbcp.managed.BasicManagedDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.