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;
}
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);
}
}
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);
}
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;
}
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");
}
Aggregations