public static ConnectionFactoryConfigurationBuilder<?> configureUniqueConnectionFactory(AbstractJdbcStoreConfigurationBuilder<?, ?> store) { switch (dt) { case H2: return store .connectionPool() .driverClass(org.h2.Driver.class) .connectionUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", extractTestName() + userIndex.incrementAndGet())) .username("sa"); case MYSQL: return store .simpleConnection() .driverClass(com.mysql.jdbc.Driver.class) .connectionUrl("jdbc:mysql://localhost/infinispan?user=ispn&password=ispn") .username("ispn") .password("ispn"); default: throw new RuntimeException("Cannot configure connection for database type "+dt); } }
public void testImplicitPooledConnectionFactory() { ConfigurationBuilder b = new ConfigurationBuilder(); b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .connectionPool().connectionUrl(JDBC_URL); Configuration configuration = b.build(); JdbcStringBasedStoreConfiguration store = (JdbcStringBasedStoreConfiguration) configuration.persistence().stores().get(0); assert store.connectionFactory() instanceof PooledConnectionFactoryConfiguration; }
public void testTableProperties() { Properties props = new Properties(); props.put("createOnStart", "false"); props.put("dropOnExit", "true"); ConfigurationBuilder b = new ConfigurationBuilder(); b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .connectionPool().connectionUrl(JDBC_URL) .withProperties(props); Configuration stringConfiguration = b.build(); JdbcStringBasedStoreConfiguration stringStoreConfiguration = (JdbcStringBasedStoreConfiguration) stringConfiguration.persistence().stores().get(0); assertFalse(stringStoreConfiguration.table().createOnStart()); assertTrue(stringStoreConfiguration.table().dropOnExit()); } }
private static void createConnectionConfig(StoreProperties props, JdbcStringBasedStoreConfigurationBuilder storeBuilder) { props.required(props.key(CONNECTION_POOL, CONNECTION_URL)); props.required(props.key(CONNECTION_POOL, DRIVER_CLASS)); storeBuilder.connectionPool() .connectionUrl(props.get(CONNECTION_POOL, CONNECTION_URL)) .driverClass(props.get(CONNECTION_POOL, DRIVER_CLASS)) .username(props.get(CONNECTION_POOL, USERNAME)) .password(props.get(CONNECTION_POOL, PASSWORD)) .create(); } }
private void parseConnectionPoolAttributes(XMLExtendedStreamReader reader, PooledConnectionFactoryConfigurationBuilder<?> builder) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { ParseUtils.requireNoNamespaceAttribute(reader, i); String value = replaceProperties(reader.getAttributeValue(i)); Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case CONNECTION_URL: { builder.connectionUrl(value); break; } case DRIVER_CLASS: { builder.driverClass(value); break; } case PASSWORD: { builder.password(value); break; } case USERNAME: { builder.username(value); break; } default: { throw ParseUtils.unexpectedAttribute(reader, i); } } } ParseUtils.requireNoContent(reader); }
builder.connectionUrl(value); break;
b.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class) .connectionPool() .connectionUrl(JDBC_URL) .fetchPersistentState(true) .table()
@Override protected EmbeddedCacheManager createCacheManager() throws Exception { ConfigurationBuilder cb = TestCacheManagerFactory.getDefaultCacheConfiguration(false); cb.persistence() .addStore(JdbcStringBasedStoreConfigurationBuilder.class) .preload(true) .key2StringMapper(LuceneKey2StringMapper.class) .table() .idColumnName("ID_COLUMN") .idColumnType("VARCHAR(255)") .tableNamePrefix("ISPN_JDBC") .dataColumnName("DATA_COLUMN") .dataColumnType("BLOB") .timestampColumnName("TIMESTAMP_COLUMN") .timestampColumnType("BIGINT") .connectionPool() .driverClass(org.h2.Driver.class) .connectionUrl("jdbc:h2:mem:infinispan;DB_CLOSE_DELAY=0") .username("sa"); return TestCacheManagerFactory.createClusteredCacheManager(cb); }