@Override public void start() { if (configuration.manageConnectionFactory()) { ConnectionFactory factory = ConnectionFactory.getConnectionFactory(configuration.connectionFactory().connectionFactoryClass()); factory.start(configuration.connectionFactory(), factory.getClass().getClassLoader()); initializeConnectionFactory(factory); } try { Object mapper = Util.loadClassStrict(configuration.key2StringMapper(), globalConfiguration.classLoader()).newInstance(); if (mapper instanceof Key2StringMapper) key2StringMapper = (Key2StringMapper) mapper; } catch (Exception e) { log.errorf("Trying to instantiate %s, however it failed due to %s", configuration.key2StringMapper(), e.getClass().getName()); throw new IllegalStateException("This should not happen.", e); } if (trace) { log.tracef("Using key2StringMapper: %s", key2StringMapper.getClass().getName()); } if (configuration.preload()) { enforceTwoWayMapper("preload"); } if (isDistributedCache) { enforceTwoWayMapper("distribution/rehashing"); } }
@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"); }