Search in sources :

Example 6 with PooledConnectionFactoryConfiguration

use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.

the class TableManipulation method getConnectionFactory.

private ConnectionFactory getConnectionFactory() {
    PooledConnectionFactoryConfiguration pooledConnectionFactoryConfiguration = persistenceConfiguration.create();
    connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
    connectionFactory.start(pooledConnectionFactoryConfiguration, connectionFactory.getClass().getClassLoader());
    return connectionFactory;
}
Also used : PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) PooledConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)

Example 7 with PooledConnectionFactoryConfiguration

use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.

the class PooledConnectionFactory method start.

@Override
public void start(ConnectionFactoryConfiguration config, ClassLoader classLoader) throws PersistenceException {
    PooledConnectionFactoryConfiguration poolConfig;
    if (config instanceof PooledConnectionFactoryConfiguration) {
        poolConfig = (PooledConnectionFactoryConfiguration) config;
    } else {
        throw new PersistenceException("ConnectionFactoryConfiguration passed in must be an instance of " + "PooledConnectionFactoryConfiguration");
    }
    try {
        String propsFile = poolConfig.propertyFile();
        if (propsFile != null) {
            dataSource = AgroalDataSource.from(new AgroalPropertiesReader(PROPERTIES_PREFIX).readProperties(propsFile));
        } else {
            Class<?> driverClass = Util.loadClass(poolConfig.driverClass(), null);
            // Default Agroal configuration with metrics disabled
            String password = poolConfig.password() != null ? poolConfig.password() : "";
            AgroalDataSourceConfigurationSupplier configuration = new AgroalDataSourceConfigurationSupplier().connectionPoolConfiguration(cp -> cp.maxSize(10).acquisitionTimeout(Duration.ofSeconds(30)).connectionFactoryConfiguration(cf -> cf.jdbcUrl(poolConfig.connectionUrl()).connectionProviderClass(driverClass).jdbcTransactionIsolation(AgroalConnectionFactoryConfiguration.TransactionIsolation.UNDEFINED).principal(new NamePrincipal(poolConfig.username())).credential(new SimplePassword(password))));
            dataSource = AgroalDataSource.from(configuration);
        }
    } catch (Exception e) {
        throw new PersistenceException("Failed to create a AgroalDataSource", e);
    }
}
Also used : JdbcUtil(org.infinispan.persistence.jdbc.common.JdbcUtil) Connection(java.sql.Connection) LogFactory(org.infinispan.util.logging.LogFactory) Util(org.infinispan.commons.util.Util) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) AgroalPropertiesReader(io.agroal.api.configuration.supplier.AgroalPropertiesReader) NamePrincipal(io.agroal.api.security.NamePrincipal) Log(org.infinispan.persistence.jdbc.common.logging.Log) SQLException(java.sql.SQLException) ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory) ConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration) Duration(java.time.Duration) AgroalDataSourceConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier) AgroalConnectionFactoryConfiguration(io.agroal.api.configuration.AgroalConnectionFactoryConfiguration) SimplePassword(io.agroal.api.security.SimplePassword) AgroalDataSource(io.agroal.api.AgroalDataSource) PersistenceException(org.infinispan.persistence.spi.PersistenceException) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration) AgroalDataSourceConfigurationSupplier(io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier) NamePrincipal(io.agroal.api.security.NamePrincipal) PersistenceException(org.infinispan.persistence.spi.PersistenceException) AgroalPropertiesReader(io.agroal.api.configuration.supplier.AgroalPropertiesReader) SimplePassword(io.agroal.api.security.SimplePassword) SQLException(java.sql.SQLException) PersistenceException(org.infinispan.persistence.spi.PersistenceException)

Aggregations

PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Configuration (org.infinispan.configuration.cache.Configuration)2 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)2 ManagedConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ManagedConnectionFactoryConfiguration)2 PooledConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)2 AgroalDataSource (io.agroal.api.AgroalDataSource)1 AgroalConnectionFactoryConfiguration (io.agroal.api.configuration.AgroalConnectionFactoryConfiguration)1 AgroalDataSourceConfigurationSupplier (io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier)1 AgroalPropertiesReader (io.agroal.api.configuration.supplier.AgroalPropertiesReader)1 NamePrincipal (io.agroal.api.security.NamePrincipal)1 SimplePassword (io.agroal.api.security.SimplePassword)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Duration (java.time.Duration)1 Util (org.infinispan.commons.util.Util)1 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)1 TestObjectStreamMarshaller (org.infinispan.marshall.TestObjectStreamMarshaller)1