Search in sources :

Example 36 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class AbstractPartitionPruningBaseTest method createCacheTable.

/**
 * Create table with the QueryEntity API.
 *
 * @param name Name.
 * @param replicated Replicated table flag.
 * @param mvcc MVCC flag.
 * @param cols Columns.
 */
private void createCacheTable(String name, boolean replicated, boolean mvcc, Object... cols) {
    QueryEntity e = new QueryEntity().setValueType(name).setTableName(name);
    List<String> pkCols = new ArrayList<>();
    String affCol = null;
    for (Object col : cols) {
        Column col0 = col instanceof Column ? (Column) col : new Column((String) col);
        e.addQueryField(col0.name, String.class.getName(), col0.alias);
        if (col0.pk())
            pkCols.add(col0.name());
        if (col0.affinity()) {
            if (affCol != null)
                throw new IllegalStateException("Only one affinity column is allowed: " + col0.name());
            affCol = col0.name();
            pkCols.add(affCol);
        }
    }
    if (pkCols.isEmpty())
        throw new IllegalStateException("No PKs!");
    e.setKeyFields(new HashSet<>(pkCols));
    if (pkCols.size() == 1)
        e.setKeyFieldName(pkCols.get(0));
    String keyTypeName = pkCols.size() == 1 ? String.class.getName() : name + "_key";
    e.setKeyType(keyTypeName);
    CacheConfiguration<?, ?> ccfg = new CacheConfiguration<>().setName(name).setSqlSchema(DFLT_SCHEMA).setAtomicityMode(mvcc ? CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT : CacheAtomicityMode.TRANSACTIONAL).setCacheMode(replicated ? CacheMode.REPLICATED : CacheMode.PARTITIONED).setQueryEntities(Collections.singletonList(e));
    if (affCol != null)
        ccfg.setKeyConfiguration(new CacheKeyConfiguration().setTypeName(keyTypeName).setAffinityKeyFieldName(affCol));
    client().createCache(ccfg);
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 37 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteSqlRoutingTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(gridName);
    c.setMarshaller(new BinaryMarshaller());
    List<CacheConfiguration> ccfgs = new ArrayList<>();
    CacheConfiguration ccfg = buildCacheConfiguration(gridName);
    if (ccfg != null)
        ccfgs.add(ccfg);
    ccfgs.add(buildCacheConfiguration(CACHE_PERSON));
    ccfgs.add(buildCacheConfiguration(CACHE_CALL));
    c.setCacheConfiguration(ccfgs.toArray(new CacheConfiguration[ccfgs.size()]));
    c.setCacheKeyConfiguration(new CacheKeyConfiguration(CallKey.class));
    c.setIncludeEventTypes(EventType.EVTS_ALL);
    return c;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) ArrayList(java.util.ArrayList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 38 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteSqlSplitterSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestKey.class.getName(), "affKey");
    cfg.setCacheKeyConfiguration(keyCfg);
    cfg.setPeerClassLoadingEnabled(false);
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration)

Example 39 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteSqlGroupConcatCollocatedTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCacheConfiguration(new CacheConfiguration(CACHE_NAME).setAffinity(new RendezvousAffinityFunction().setPartitions(8)).setQueryEntities(Collections.singletonList(new QueryEntity(Key.class, Value.class)))).setCacheKeyConfiguration(new CacheKeyConfiguration(Key.class));
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 40 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteSqlSkipReducerOnUpdateDmlSelfTest method buildCacheConfiguration.

/**
 * Creates cache configuration.
 *
 * @param name Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration buildCacheConfiguration(String name) {
    if (name.equals(CACHE_ORG)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_ORG);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(Integer.class, Organization.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        ccfg.setSqlFunctionClasses(IgniteSqlSkipReducerOnUpdateDmlSelfTest.class);
        return ccfg;
    }
    if (name.equals(CACHE_PERSON)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_PERSON);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        QueryEntity entity = new QueryEntity(PersonKey.class, Person.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        ccfg.setKeyConfiguration(new CacheKeyConfiguration(PersonKey.class));
        ccfg.setSqlFunctionClasses(IgniteSqlSkipReducerOnUpdateDmlSelfTest.class);
        return ccfg;
    }
    if (name.equals(CACHE_POSITION)) {
        CacheConfiguration ccfg = new CacheConfiguration(CACHE_POSITION);
        ccfg.setCacheMode(CacheMode.REPLICATED);
        QueryEntity entity = new QueryEntity(Integer.class, Position.class);
        ccfg.setQueryEntities(Collections.singletonList(entity));
        ccfg.setSqlFunctionClasses(IgniteSqlSkipReducerOnUpdateDmlSelfTest.class);
        return ccfg;
    }
    assert false;
    return null;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)41 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)24 QueryEntity (org.apache.ignite.cache.QueryEntity)19 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)17 ArrayList (java.util.ArrayList)11 LinkedHashMap (java.util.LinkedHashMap)7 QueryIndex (org.apache.ignite.cache.QueryIndex)7 Ignite (org.apache.ignite.Ignite)6 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)6 HashMap (java.util.HashMap)5 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 SimpleEntry (java.util.AbstractMap.SimpleEntry)3 Collectors (java.util.stream.Collectors)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)3 CacheMode (org.apache.ignite.cache.CacheMode)3 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)3