private TableManager getTableManager(boolean binary) { TableManipulationConfiguration tableConfig = binary ? binaryConfig : stringConfig; TableManager tableManager = TableManagerFactory.getManager(metaData, connectionFactory, tableConfig); tableManager.setCacheName(props.cacheName()); return tableManager; }
void initializeConnectionFactory(ConnectionFactory connectionFactory) throws PersistenceException { this.connectionFactory = connectionFactory; tableManager = getTableManager(); tableManager.setCacheName(cacheName); tableManager.start(); }
public void testTableQuoting() throws Exception { tableManager.setCacheName("my.cache"); assert !existsTable(connection, tableManager.getTableName()); tableManager.createTable(connection); assert existsTable(connection, tableManager.getTableName()); }
@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(); } tableManager = TableManagerFactory.getManager(connectionFactory, storeBuilder.create()); tableManager.setCacheName("aName"); }
public void testConnectionLeakGuessDialect() throws Exception { 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(connectionFactory, storeBuilder.create()); tableManager.setCacheName("GuessDialect"); tableManager.start(); UnitTestDatabaseManager.verifyConnectionLeaks(connectionFactory); tableManager.stop(); connectionFactory.stop(); }
public void testNotCreateConnectionFactory() throws Exception { ConfigurationBuilder builder = TestCacheManagerFactory .getDefaultCacheConfiguration(false); JdbcStringBasedStoreConfigurationBuilder storeBuilder = builder .persistence() .addStore(JdbcStringBasedStoreConfigurationBuilder.class) .manageConnectionFactory(false) .dialect(DatabaseType.H2) .dbMajorVersion(1) .dbMinorVersion(4); storeBuilder.table().createOnStart(false); JdbcStringBasedStore stringBasedCacheStore = new JdbcStringBasedStore(); stringBasedCacheStore.init(createContext(builder.build())); stringBasedCacheStore.start(); assertNull(stringBasedCacheStore.getConnectionFactory()); // this will make sure that if a method like stop is called on the connection then it will barf an exception ConnectionFactory connectionFactory = mock(ConnectionFactory.class); TableManager tableManager = mock(TableManager.class); tableManager.start(); tableManager.setCacheName("otherName"); stringBasedCacheStore.initializeConnectionFactory(connectionFactory); //stop should be called even if this is an external reset(tableManager, connectionFactory); tableManager.stop(); stringBasedCacheStore.stop(); }