Search in sources :

Example 1 with QueriesJdbcStoreConfigurationBuilder

use of org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder in project infinispan by infinispan.

the class QueriesJdbcJoinTest method testUpsertMultipleValues.

public void testUpsertMultipleValues() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.encoding().mediaType(MediaType.APPLICATION_PROTOSTREAM_TYPE);
    QueriesJdbcStoreConfigurationBuilder queriesBuilder = builder.persistence().addStore(QueriesJdbcStoreConfigurationBuilder.class);
    queriesBuilder.keyColumns("name");
    queriesBuilder.schemaJdbcConfigurationBuilder().messageName("Person").packageName("org.infinispan.test.core");
    UnitTestDatabaseManager.configureUniqueConnectionFactory(queriesBuilder);
    createTables(queriesBuilder.getConnectionFactory(), false);
    TestType.PASS.modifyConfiguration(queriesBuilder, false);
    queriesBuilder.queriesJdbcConfigurationBuilder().delete("DELETE FROM " + TABLE1_NAME + " t1 WHERE t1.name = :name; DELETE FROM " + TABLE2_NAME + " t2 where t2.name = :name").deleteAll("DELETE FROM " + TABLE1_NAME + "; DELETE FROM " + TABLE2_NAME).upsert(insertTable1Statement(false, true) + "; " + insertTable2Statement(false, true));
    EmbeddedCacheManager embeddedCacheManager = TestCacheManagerFactory.createCacheManager(TestDataSCI.INSTANCE, builder);
    Cache<String, Person> cache = embeddedCacheManager.getCache();
    String name = "Mircea Markus";
    Person person = samplePerson(name);
    cache.put(name, person);
    assertEquals(person, cache.get(name));
    cache.remove(name);
    assertNull(cache.get(name));
}
Also used : ConnectionFactoryConfigurationBuilder(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) QueriesJdbcConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcConfigurationBuilder) QueriesJdbcStoreConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder) QueriesJdbcStoreConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Person(org.infinispan.test.data.Person)

Example 2 with QueriesJdbcStoreConfigurationBuilder

use of org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder in project infinispan by infinispan.

the class QueriesJdbcJoinTest method createCacheManager.

protected EmbeddedCacheManager createCacheManager(TestType type, boolean idJoin) {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.encoding().mediaType(MediaType.APPLICATION_PROTOSTREAM_TYPE);
    QueriesJdbcStoreConfigurationBuilder queriesBuilder = builder.persistence().addStore(QueriesJdbcStoreConfigurationBuilder.class).ignoreModifications(true);
    queriesBuilder.keyColumns("name");
    queriesBuilder.schemaJdbcConfigurationBuilder().messageName("Person").packageName("org.infinispan.test.core");
    UnitTestDatabaseManager.configureUniqueConnectionFactory(queriesBuilder);
    createTables(queriesBuilder.getConnectionFactory(), idJoin);
    type.modifyConfiguration(queriesBuilder, idJoin);
    return TestCacheManagerFactory.createCacheManager(TestDataSCI.INSTANCE, builder);
}
Also used : ConnectionFactoryConfigurationBuilder(org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) QueriesJdbcConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcConfigurationBuilder) QueriesJdbcStoreConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder) QueriesJdbcStoreConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder)

Example 3 with QueriesJdbcStoreConfigurationBuilder

use of org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder in project infinispan by infinispan.

the class QueriesJdbcStoreFunctionalTest method createCacheStoreConfig.

@Override
protected PersistenceConfigurationBuilder createCacheStoreConfig(PersistenceConfigurationBuilder persistence, String cacheName, boolean preload) {
    QueriesJdbcStoreConfigurationBuilder storeBuilder = persistence.addStore(QueriesJdbcStoreConfigurationBuilder.class).transactional(transactionalStore).preload(preload);
    configureCommonConfiguration(storeBuilder);
    // Just prepend the first letter of the Test to make the tables unique so we can run them in parallel
    String tableName = getClass().getSimpleName().subSequence(0, 1) + cacheName;
    SqlManager manager = SqlManager.fromDatabaseType(DB_TYPE, tableName, true);
    String KEY_COLUMN = "keycolumn";
    storeBuilder.queriesJdbcConfigurationBuilder().deleteAll("DELETE FROM " + tableName).size("SELECT COUNT(*) FROM " + tableName);
    storeBuilder.keyColumns(KEY_COLUMN);
    if (cacheName.equalsIgnoreCase("testPreloadStoredAsBinary")) {
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT " + KEY_COLUMN + ", name, STREET, city, ZIP, picture, sex, birthdate, accepted_tos FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN).selectAll("SELECT " + KEY_COLUMN + ", name, street, city, zip, picture, sex, birthdate, accepted_tos FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList(KEY_COLUMN), Arrays.asList(KEY_COLUMN, "name", "street", "CITY", "zip", "picture", "sex", "birthdate", "accepted_tos"))).delete("DELETE FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN);
    } else if (cacheName.equalsIgnoreCase("testStoreByteArrays")) {
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT " + KEY_COLUMN + ", value1 FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN).selectAll("SELECT " + KEY_COLUMN + ", value1 FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList(KEY_COLUMN), Arrays.asList(KEY_COLUMN, "value1"))).delete("DELETE FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN);
    } else if (cacheName.toUpperCase().startsWith("TESTDBHASMOREVALUECOLUMNS")) {
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT " + KEY_COLUMN + ", name, STREET, city, ZIP, picture, sex, birthdate, value2, value3 FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN).selectAll("SELECT " + KEY_COLUMN + ", name, street, city, zip, picture, sex, birthdate, value2, value3 FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList(KEY_COLUMN), Arrays.asList(KEY_COLUMN, "name", "street", "CITY", "zip", "picture", "sex", "birthdate", "value2", "value3"))).delete("DELETE FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN);
    } else if (cacheName.toUpperCase().startsWith("TESTDBHASMOREKEYCOLUMNS")) {
        // The colum has to be value to match our Key proto schema
        KEY_COLUMN = "value";
        storeBuilder.keyColumns(KEY_COLUMN + ", keycolumn2");
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT " + KEY_COLUMN + ", keycolumn2, value1 FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN).selectAll("SELECT " + KEY_COLUMN + ", keycolumn2, value1 FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList(KEY_COLUMN), Arrays.asList(KEY_COLUMN, "value1"))).delete("DELETE FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN + " AND keycolumn2 = :keycolumn2");
    } else if (cacheName.toUpperCase().startsWith("TESTDBHASLESSVALUECOLUMNS")) {
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT " + KEY_COLUMN + ", name, STREET FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN).selectAll("SELECT " + KEY_COLUMN + ", name, street FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList(KEY_COLUMN), Arrays.asList(KEY_COLUMN, "name", "street"))).delete("DELETE FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN);
    } else if (cacheName.toUpperCase().startsWith("TESTEMBEDDEDKEY")) {
        storeBuilder.keyColumns("name");
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT name, STREET, city, ZIP, picture, sex, birthdate FROM " + tableName + " WHERE name = :name").selectAll("SELECT name, street, city, zip, picture, sex, birthdate FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList("name"), Arrays.asList("name", "street", "CITY", "zip", "picture", "sex", "birthdate"))).delete("DELETE FROM " + tableName + " WHERE name = :name");
    } else if (cacheName.toUpperCase().startsWith("TESTENUMFORVALUE")) {
        storeBuilder.keyColumns("name");
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT name, sex FROM " + tableName + " WHERE name = :name").selectAll("SELECT name, sex FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList("name"), Arrays.asList("name", "sex"))).delete("DELETE FROM " + tableName + " WHERE name = :name");
    } else if (cacheName.toUpperCase().startsWith("TESTENUMFORKEY")) {
        storeBuilder.keyColumns("sex");
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT name, sex FROM " + tableName + " WHERE sex = :sex").selectAll("SELECT name, sex FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList("sex"), Arrays.asList("name", "sex"))).delete("DELETE FROM " + tableName + " WHERE sex = :sex");
    } else {
        storeBuilder.queriesJdbcConfigurationBuilder().select("SELECT " + KEY_COLUMN + ", value1 FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN).selectAll("SELECT " + KEY_COLUMN + ", value1 FROM " + tableName).upsert(manager.getUpsertStatement(Collections.singletonList(KEY_COLUMN), Arrays.asList(KEY_COLUMN, "value1"))).delete("DELETE FROM " + tableName + " WHERE " + KEY_COLUMN + " = :" + KEY_COLUMN);
    }
    createTable(cacheName, tableName, storeBuilder.getConnectionFactory());
    return persistence;
}
Also used : SqlManager(org.infinispan.persistence.jdbc.common.SqlManager) QueriesJdbcStoreConfigurationBuilder(org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder)

Aggregations

QueriesJdbcStoreConfigurationBuilder (org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 ConnectionFactoryConfigurationBuilder (org.infinispan.persistence.jdbc.common.configuration.ConnectionFactoryConfigurationBuilder)2 QueriesJdbcConfigurationBuilder (org.infinispan.persistence.sql.configuration.QueriesJdbcConfigurationBuilder)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 SqlManager (org.infinispan.persistence.jdbc.common.SqlManager)1 Person (org.infinispan.test.data.Person)1