Search in sources :

Example 31 with CacheKeyConfiguration

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

the class ThinClientAbstractPartitionAwarenessTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setConsistentId(igniteInstanceName);
    CacheConfiguration ccfg0 = new CacheConfiguration().setName(REPL_CACHE_NAME).setCacheMode(CacheMode.REPLICATED);
    CacheConfiguration ccfg1 = new CacheConfiguration().setName(PART_CUSTOM_AFFINITY_CACHE_NAME).setCacheMode(CacheMode.PARTITIONED).setAffinity(new CustomAffinityFunction());
    CacheConfiguration ccfg2 = new CacheConfiguration().setName(PART_CACHE_NAME).setCacheMode(CacheMode.PARTITIONED).setKeyConfiguration(new CacheKeyConfiguration(TestNotAnnotatedAffinityKey.class.getName(), "affinityKey"), new CacheKeyConfiguration(TestAnnotatedAffinityKey.class));
    CacheConfiguration ccfg3 = new CacheConfiguration().setName(PART_CACHE_0_BACKUPS_NAME).setCacheMode(CacheMode.PARTITIONED).setBackups(0);
    CacheConfiguration ccfg4 = new CacheConfiguration().setName(PART_CACHE_1_BACKUPS_NAME).setCacheMode(CacheMode.PARTITIONED).setBackups(1);
    CacheConfiguration ccfg5 = new CacheConfiguration().setName(PART_CACHE_3_BACKUPS_NAME).setCacheMode(CacheMode.PARTITIONED).setBackups(3);
    return cfg.setCacheConfiguration(ccfg0, ccfg1, ccfg2, ccfg3, ccfg4, ccfg5);
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 32 with CacheKeyConfiguration

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

the class AffinityKeyNameAndValueFieldNameConflictTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration ccfg = new CacheConfiguration(PERSON_CACHE);
    if (qryEntityCfg) {
        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(keyCls.getName(), "name");
        cfg.setCacheKeyConfiguration(keyCfg);
        QueryEntity entity = new QueryEntity();
        entity.setKeyType(keyCls.getName());
        entity.setValueType(Person.class.getName());
        if (keyFieldSpecified)
            entity.setKeyFields(Stream.of("name").collect(Collectors.toSet()));
        entity.addQueryField("id", Integer.class.getName(), null);
        entity.addQueryField("name", String.class.getName(), null);
        ccfg.setQueryEntities(F.asList(entity));
    } else {
        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(keyCls);
        cfg.setCacheKeyConfiguration(keyCfg);
        ccfg.setIndexedTypes(keyCls, Person.class);
    }
    cfg.setCacheConfiguration(ccfg);
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 33 with CacheKeyConfiguration

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

the class PojoIndexLocalQueryTest method createPopulateAndVerify.

/**
 * Executes test scenario: <ul>
 * <li>Create cache</li>
 * <li>Populate cache with random data</li>
 * <li>Verify range query on created table</li>
 * <li>Verify that table stores the same data as the generated dataset</li>
 * <li>Destroy cache</li>
 * </ul>
 *
 * @param idxCls Index type class.
 * @param comp Comparator to sort data set to perform range check.
 * If {@code null} range check will not be performed.
 * @param keyCls Key type class. Will be used to generate KEY object
 * for cache operations. If {@code null} idxCls will be used.
 * @param <Key> Type of the key in terms of the cache.
 * @param <Idx> Type of the indexed field.
 */
private <Key extends ClassWrapper, Idx> void createPopulateAndVerify(Class<Idx> idxCls, @Nullable Comparator<Idx> comp, @Nullable Class<Key> keyCls) {
    Ignite ign = grid(0);
    String tblName = idxCls.getSimpleName().toUpperCase() + "_TBL" + TBL_ID.incrementAndGet();
    try {
        // Create cache
        LinkedHashMap<String, String> fields = new LinkedHashMap<>(2);
        fields.put("idxVal", idxCls.getName());
        fields.put("val", Integer.class.getName());
        QueryEntity qe = new QueryEntity(keyCls == null ? idxCls.getName() : keyCls.getName(), Integer.class.getName()).setTableName(tblName).setValueFieldName("val").setFields(fields);
        String idxName;
        String idxFieldName;
        if (keyCls == null) {
            qe.setKeyFieldName("idxVal");
            idxName = PK_IDX_NAME;
            idxFieldName = KEY_FIELD_NAME;
        } else {
            idxFieldName = "idxVal";
            qe.setKeyFields(Collections.singleton(idxFieldName));
            if (keyCls.equals(TestKeyWithAff.class))
                idxName = AFFINITY_KEY_IDX_NAME;
            else {
                idxName = "IDXVAL_IDX";
                qe.setIndexes(Collections.singleton(new QueryIndex(idxFieldName, true, idxName)));
            }
        }
        IgniteCache<Object, Integer> cache = ign.createCache(new CacheConfiguration<Object, Integer>(tblName + "_CACHE").setKeyConfiguration(new CacheKeyConfiguration((keyCls != null ? keyCls : idxCls).getName(), "idxVal")).setQueryEntities(Collections.singletonList(qe)).setSqlSchema("PUBLIC"));
        // Then populate it with random data
        Map<Idx, Integer> data = new TreeMap<>(comp);
        if (keyCls == null)
            populateTable(data, cache, idxCls);
        else
            populateTable(data, cache, keyCls, idxCls);
        // Perform necessary verifications
        if (comp != null)
            verifyRange(data, tblName, idxFieldName, idxName, comp);
        verifyEach(data, tblName, idxFieldName, idxName);
    } finally {
        // Destroy cache
        ign.destroyCache(tblName + "_CACHE");
    }
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryIndex(org.apache.ignite.cache.QueryIndex) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 34 with CacheKeyConfiguration

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

the class IgniteCacheLockPartitionOnAffinityRunAbstractTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    // Enables template with default test configuration
    cfg.setCacheConfiguration(F.concat(cfg.getCacheConfiguration(), cacheConfiguration(igniteInstanceName).setName("*")));
    ((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
    cfg.setMarshaller(new BinaryMarshaller());
    // TODO remove key configuration when https://issues.apache.org/jira/browse/IGNITE-5795 is fixed.
    cfg.setCacheKeyConfiguration(new CacheKeyConfiguration(Person.Key.class.getName(), "orgId"));
    AlwaysFailoverSpi failSpi = new AlwaysFailoverSpi();
    failSpi.setMaximumFailoverAttempts(MAX_FAILOVER_ATTEMPTS);
    cfg.setFailoverSpi(failSpi);
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) AlwaysFailoverSpi(org.apache.ignite.spi.failover.always.AlwaysFailoverSpi) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Example 35 with CacheKeyConfiguration

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

the class IgniteCachelessQueriesSelfTest method getConfiguration.

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

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