use of org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration in project infinispan by infinispan.
the class QueriesJdbcJoinTest method createTables.
private void createTables(ConnectionFactoryConfigurationBuilder<ConnectionFactoryConfiguration> builder, boolean idJoin) {
ConnectionFactoryConfiguration config = builder.create();
FACTORY = ConnectionFactory.getConnectionFactory(config.connectionFactoryClass());
FACTORY.start(config, getClass().getClassLoader());
Connection connection = null;
try {
connection = FACTORY.getConnection();
try (Statement stmt = connection.createStatement()) {
String tableCreation = "CREATE TABLE " + TABLE1_NAME + " (" + "name VARCHAR(255) NOT NULL, " + (idJoin ? "address INT, " : "") + "picture VARBINARY(255), " + "sex VARCHAR(255), " + "birthdate TIMESTAMP, " + "accepted_tos boolean, " + "notused VARCHAR(255), " + "PRIMARY KEY (NAME))";
stmt.execute(tableCreation);
tableCreation = "create TABLE " + TABLE2_NAME + " (" + (idJoin ? "id INT NOT NULL, " : "name VARCHAR(255) NOT NULL, ") + "street VARCHAR(255), " + "city VARCHAR(255), " + "zip INT, " + "PRIMARY KEY (" + (idJoin ? "id" : "name") + "))";
stmt.execute(tableCreation);
}
} catch (SQLException t) {
throw new AssertionError(t);
} finally {
FACTORY.releaseConnection(connection);
}
}
use of org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration in project infinispan by infinispan.
the class TableManagerTest method createConnection.
@BeforeClass
public void createConnection() throws Exception {
JdbcStringBasedStoreConfigurationBuilder storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
UnitTestDatabaseManager.setDialect(storeBuilder);
UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table());
ConnectionFactoryConfiguration factoryConfiguration = UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
if (factoryConfiguration instanceof SimpleConnectionFactoryConfiguration) {
SimpleConnectionFactoryConfiguration simpleConfiguration = (SimpleConnectionFactoryConfiguration) factoryConfiguration;
connectionFactory = ConnectionFactory.getConnectionFactory(SimpleConnectionFactory.class);
connectionFactory.start(simpleConfiguration, connectionFactory.getClass().getClassLoader());
connection = connectionFactory.getConnection();
} else if (factoryConfiguration instanceof PooledConnectionFactoryConfiguration) {
PooledConnectionFactoryConfiguration pooledConfiguration = (PooledConnectionFactoryConfiguration) factoryConfiguration;
connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
connectionFactory.start(pooledConfiguration, connectionFactory.getClass().getClassLoader());
connection = connectionFactory.getConnection();
}
Cache<?, ?> cache = mock(Cache.class);
when(cache.getCacheConfiguration()).thenReturn(new ConfigurationBuilder().build());
JdbcStringBasedStoreConfiguration config = storeBuilder.create();
GlobalConfiguration globalConfiguration = mock(GlobalConfiguration.class);
when(globalConfiguration.classLoader()).thenReturn(getClass().getClassLoader());
ctx = new DummyInitializationContext(config, cache, new TestObjectStreamMarshaller(), null, null, null, globalConfiguration, null, null, null);
tableManager = TableManagerFactory.getManager(ctx, connectionFactory, config, "aName");
}
use of org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration in project infinispan by infinispan.
the class PooledConnectionFactoryTest method testValuesNoOverrides.
@Test
public void testValuesNoOverrides() throws Exception {
storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
if (customFactoryConfiguration != null) {
factoryBuilder = storeBuilder.connectionPool().read(customFactoryConfiguration);
} else {
// We load agroal.properties to enable metrics and ensure that property file loading works as expected
factoryBuilder = storeBuilder.connectionPool().propertyFile("src/test/resources/configs/agroal.properties");
}
ConnectionFactoryConfiguration factoryConfiguration = factoryBuilder.create();
factory.start(factoryConfiguration, Thread.currentThread().getContextClassLoader());
int hardcodedMaxPoolSize = factory.getMaxPoolSize();
assert hardcodedMaxPoolSize == 20;
Set<Connection> connections = new HashSet<>();
for (int i = 0; i < hardcodedMaxPoolSize; i++) {
connections.add(factory.getConnection());
}
assert connections.size() == hardcodedMaxPoolSize;
assert factory.getActiveConnections() == hardcodedMaxPoolSize;
for (Connection conn : connections) {
conn.close();
}
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 2000) {
if (factory.getActiveConnections() == 0)
break;
}
// this must happen eventually
assert factory.getActiveConnections() == 0;
}
use of org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration in project infinispan by infinispan.
the class PooledConnectionFactoryTest method testNoDriverClassFound.
@Test(expectedExceptions = PersistenceException.class)
public void testNoDriverClassFound() {
storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
factoryBuilder = UnitTestDatabaseManager.configureBrokenConnectionFactory(storeBuilder);
ConnectionFactoryConfiguration factoryConfiguration = factoryBuilder.create();
factory.start(factoryConfiguration, Thread.currentThread().getContextClassLoader());
}
use of org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfiguration in project infinispan by infinispan.
the class TableManagerTest method testConnectionLeakGuessDialect.
public void testConnectionLeakGuessDialect() {
JdbcStringBasedStoreConfigurationBuilder storeBuilder = TestCacheManagerFactory.getDefaultCacheConfiguration(false).persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class);
UnitTestDatabaseManager.buildTableManipulation(storeBuilder.table());
PooledConnectionFactory connectionFactory = new PooledConnectionFactory();
ConnectionFactoryConfiguration config = UnitTestDatabaseManager.configureUniqueConnectionFactory(storeBuilder).create();
connectionFactory.start(config, Thread.currentThread().getContextClassLoader());
// JdbcStringBasedStoreConfiguration defaults to null dialect, so dialect and versions must be guessed
TableManager tableManager = TableManagerFactory.getManager(ctx, connectionFactory, storeBuilder.create(), "GuessDialect");
tableManager.start();
UnitTestDatabaseManager.verifyConnectionLeaks(connectionFactory);
tableManager.stop();
connectionFactory.stop();
}
Aggregations