Search in sources :

Example 1 with Current

use of org.objectweb.jotm.Current in project OpenAttestation by OpenAttestation.

the class PersistenceManager method createDataSource.

/**
            p.jdbcDriver = jpaProperties.getProperty("javax.persistence.jdbc.driver");
            p.jdbcUrl = jpaProperties.getProperty("javax.persistence.jdbc.url");
            p.jdbcUsername = jpaProperties.getProperty("javax.persistence.jdbc.user");
            p.jdbcPassword = jpaProperties.getProperty("javax.persistence.jdbc.password");
    * 
    * @param jpaProperties
    * @return 
    */
public 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
    // max 50 active connections to database
    ds.setMaxActive(50);
    // max 10 idle connections in the pool
    ds.setMaxIdle(10);
    // no limit
    ds.setMaxOpenPreparedStatements(-1);
    // wait indefinitely for a new connection from the pool
    ds.setMaxWait(-1);
    // (milliseconds) connection may be idle up to 30 minutes before being evicted
    ds.setMinEvictableIdleTimeMillis(1000 * 60 * 30);
    // min 5 idle connections in the pool
    ds.setMinIdle(5);
    // how many connections to test each time
    ds.setNumTestsPerEvictionRun(10);
    ds.setPassword(jpaProperties.getProperty("javax.persistence.jdbc.password"));
    ds.setPoolPreparedStatements(true);
    ds.setRemoveAbandoned(true);
    // (seconds) connection may be abandoned for up to an hour before being removed
    ds.setRemoveAbandonedTimeout(60 * 60);
    ds.setTestOnBorrow(true);
    ds.setTestOnReturn(false);
    ds.setTestWhileIdle(true);
    // (milliseconds) check which idle connections should be evicted once every minute
    ds.setTimeBetweenEvictionRunsMillis(1000 * 60);
    ds.setUrl(jpaProperties.getProperty("javax.persistence.jdbc.url"));
    ds.setUsername(jpaProperties.getProperty("javax.persistence.jdbc.user"));
    ds.setValidationQuery("SELECT 1");
    // (seconds) how long to wait on a result for the validation query before giving up
    ds.setValidationQueryTimeout(2);
    //        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;
}
Also used : BasicManagedDataSource(org.apache.commons.dbcp.managed.BasicManagedDataSource) Current(org.objectweb.jotm.Current)

Aggregations

BasicManagedDataSource (org.apache.commons.dbcp.managed.BasicManagedDataSource)1 Current (org.objectweb.jotm.Current)1