Search in sources :

Example 1 with SqlManager

use of org.infinispan.persistence.jdbc.common.SqlManager 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

SqlManager (org.infinispan.persistence.jdbc.common.SqlManager)1 QueriesJdbcStoreConfigurationBuilder (org.infinispan.persistence.sql.configuration.QueriesJdbcStoreConfigurationBuilder)1