void initializeConnectionFactory(ConnectionFactory connectionFactory) throws PersistenceException { this.connectionFactory = connectionFactory; tableManager = getTableManager(); tableManager.setCacheName(cacheName); tableManager.start(); }
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(); }