Search in sources :

Example 1 with BasicManagedDataSource

use of org.apache.commons.dbcp.managed.BasicManagedDataSource in project ignite by apache.

the class HibernateL2CacheTransactionalSelfTest method registryBuilder.

/** {@inheritDoc} */
@Nullable
@Override
protected StandardServiceRegistryBuilder registryBuilder() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
    // JTA-aware data source.
    BasicManagedDataSource dataSrc = new BasicManagedDataSource();
    dataSrc.setTransactionManager(jotm.getTransactionManager());
    dataSrc.setDefaultAutoCommit(false);
    JdbcDataSource h2DataSrc = new JdbcDataSource();
    h2DataSrc.setURL(CONNECTION_URL);
    dataSrc.setXaDataSourceInstance(h2DataSrc);
    connProvider.setDataSource(dataSrc);
    connProvider.configure(Collections.emptyMap());
    builder.addService(ConnectionProvider.class, connProvider);
    builder.addService(JtaPlatform.class, new TestJtaPlatform());
    builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
    return builder;
}
Also used : JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) DatasourceConnectionProviderImpl(org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) BasicManagedDataSource(org.apache.commons.dbcp.managed.BasicManagedDataSource) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BasicManagedDataSource

use of org.apache.commons.dbcp.managed.BasicManagedDataSource 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)2 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 DatasourceConnectionProviderImpl (org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl)1 JtaTransactionCoordinatorBuilderImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl)1 Nullable (org.jetbrains.annotations.Nullable)1 Current (org.objectweb.jotm.Current)1