Search in sources :

Example 1 with ConnectionFactory

use of org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory in project infinispan by infinispan.

the class TxStoreTest method assertRowCount.

private void assertRowCount(int rowCount) {
    JdbcStringBasedStore jdbcStore = (JdbcStringBasedStore) store.delegate();
    ConnectionFactory connectionFactory = jdbcStore.getConnectionFactory();
    TableName tableName = jdbcStore.getTableManager().getDataTableName();
    int value = UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
    assert value == rowCount : "Expected " + rowCount + " rows, actual value is " + value;
}
Also used : TableName(org.infinispan.persistence.jdbc.impl.table.TableName) ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory) JdbcStringBasedStore(org.infinispan.persistence.jdbc.stringbased.JdbcStringBasedStore)

Example 2 with ConnectionFactory

use of org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory in project infinispan by infinispan.

the class JdbcStringBasedClusterTest method testPurgeExpired.

public void testPurgeExpired() throws SQLException {
    Cache<String, String> cacheToUse = cache(0, cacheName);
    cacheToUse.put("key1", "expired", 10, TimeUnit.MINUTES);
    cacheToUse.put("key2", "value");
    cacheToUse.put("key3", "expired", 10, TimeUnit.MINUTES);
    cacheToUse.put("key4", "value");
    assertEquals(4, cache(0, cacheName).size());
    // Remove all entries from memory
    for (int i = 0; i < cacheManagers.size(); ++i) {
        TestingUtil.extractComponent(cache(i, cacheName), InternalDataContainer.class).clear();
    }
    assertEquals(4, cacheToUse.size());
    // Advance to expire one of the entries
    controlledTimeService.advance(TimeUnit.MINUTES.toMillis(11));
    PersistenceManager persistenceManager = TestingUtil.extractComponent(cache(0, cacheName), PersistenceManager.class);
    CompletionStages.join(persistenceManager.purgeExpired());
    assertEquals(2, cacheToUse.size());
    // Make sure the purge actually removed the data from the database
    JdbcStringBasedStore jdbcStringBasedStore = persistenceManager.getStores(JdbcStringBasedStore.class).iterator().next();
    ConnectionFactory connectionFactory = jdbcStringBasedStore.getConnectionFactory();
    Connection connection = connectionFactory.getConnection();
    try (Statement stat = connection.createStatement()) {
        try (ResultSet rs = stat.executeQuery("SELECT COUNT(1) FROM " + jdbcStringBasedStore.getTableManager().getDataTableName())) {
            assertTrue(rs.next());
            assertEquals(2, rs.getInt(1));
            assertFalse(rs.next());
        }
    } finally {
        connectionFactory.releaseConnection(connection);
    }
}
Also used : ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory) PersistenceManager(org.infinispan.persistence.manager.PersistenceManager) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer)

Example 3 with ConnectionFactory

use of org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory in project infinispan by infinispan.

the class JdbcStringBasedStoreAltMapperTest method rowCount.

protected int rowCount() {
    ConnectionFactory connectionFactory = getConnection();
    TableName tableName = tableManager.getDataTableName();
    return UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
}
Also used : TableName(org.infinispan.persistence.jdbc.impl.table.TableName) ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory)

Example 4 with ConnectionFactory

use of org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory in project infinispan by infinispan.

the class StringStoreWithPooledConnectionFunctionalTest method getConnectionFactory.

@Override
public ConnectionFactory getConnectionFactory(JdbcStringBasedStoreConfigurationBuilder storeBuilder) {
    ConnectionFactoryConfiguration connectionFactoryConfiguration;
    if (customFactoryConfiguration != null) {
        connectionFactoryConfiguration = storeBuilder.connectionPool().read(customFactoryConfiguration).create();
    } else {
        connectionFactoryConfiguration = configureUniqueConnectionFactory(storeBuilder).create();
    }
    final ConnectionFactory connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
    connectionFactory.start(connectionFactoryConfiguration, connectionFactory.getClass().getClassLoader());
    return connectionFactory;
}
Also used : ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory) UnitTestDatabaseManager.configureUniqueConnectionFactory(org.infinispan.persistence.jdbc.UnitTestDatabaseManager.configureUniqueConnectionFactory) PooledConnectionFactory(org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory) ConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration) PooledConnectionFactoryConfiguration(org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)

Example 5 with ConnectionFactory

use of org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory in project infinispan by infinispan.

the class BaseJdbcStore method start.

@Override
public CompletionStage<Void> start(InitializationContext ctx) {
    this.config = ctx.getConfiguration();
    blockingManager = ctx.getBlockingManager();
    return blockingManager.runBlocking(() -> {
        try {
            ConnectionFactory factory = ConnectionFactory.getConnectionFactory(config.connectionFactory().connectionFactoryClass());
            factory.start(config.connectionFactory(), factory.getClass().getClassLoader());
            this.connectionFactory = factory;
            tableOperations = createTableOperations(ctx, config);
        } catch (SQLException e) {
            throw new PersistenceException(e);
        }
    }, "jdbcstore-start");
}
Also used : ConnectionFactory(org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory) SQLException(java.sql.SQLException) PersistenceException(org.infinispan.persistence.spi.PersistenceException)

Aggregations

ConnectionFactory (org.infinispan.persistence.jdbc.common.connectionfactory.ConnectionFactory)6 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 ConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration)2 TableName (org.infinispan.persistence.jdbc.impl.table.TableName)2 InternalDataContainer (org.infinispan.container.impl.InternalDataContainer)1 UnitTestDatabaseManager.configureUniqueConnectionFactory (org.infinispan.persistence.jdbc.UnitTestDatabaseManager.configureUniqueConnectionFactory)1 PooledConnectionFactoryConfiguration (org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration)1 PooledConnectionFactory (org.infinispan.persistence.jdbc.common.impl.connectionfactory.PooledConnectionFactory)1 JdbcStringBasedStore (org.infinispan.persistence.jdbc.stringbased.JdbcStringBasedStore)1 PersistenceManager (org.infinispan.persistence.manager.PersistenceManager)1 PersistenceException (org.infinispan.persistence.spi.PersistenceException)1 JdbcConnection (util.JdbcConnection)1