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(); }
static TableManipulationConfiguration createTableConfig(StoreProperties props, Element tableType, JdbcStringBasedStoreConfigurationBuilder storeBuilder) { return storeBuilder.table() .createOnStart(props.isTargetStore()) .tableNamePrefix(props.get(TABLE, tableType, TABLE_NAME_PREFIX)) .idColumnName(props.get(TABLE, tableType, ID, NAME)) .idColumnType(props.get(TABLE, tableType, ID, TYPE)) .dataColumnName(props.get(TABLE, tableType, DATA, NAME)) .dataColumnType(props.get(TABLE, tableType, DATA, TYPE)) .timestampColumnName(props.get(TABLE, tableType, TIMESTAMP, NAME)) .timestampColumnType(props.get(TABLE, tableType, TIMESTAMP, TYPE)) .segmentColumnName(props.get(TABLE, tableType, SEGMENT, NAME)) .segmentColumnType(props.get(TABLE, tableType, SEGMENT, TYPE)) .create(); }