Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setQueryEntities()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setQueryEntities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JdbcThinBulkLoadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates cache configuration with {@link QueryEntity} created
 * using {@link CacheConfiguration#setQueryEntities(Collection)} call.
 *
 * @return The cache configuration.
 */
private CacheConfiguration cacheConfigWithQueryEntity() {
    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);

    QueryEntity e = new QueryEntity();

    e.setKeyType(String.class.getName());
    e.setValueType("Person");

    e.addQueryField("id", Integer.class.getName(), null);
    e.addQueryField("age", Integer.class.getName(), null);
    e.addQueryField("firstName", String.class.getName(), null);
    e.addQueryField("lastName", String.class.getName(), null);

    cache.setQueryEntities(Collections.singletonList(e));

    return cache;
}
 
Example 2
Source File: QueryEntityValidationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Test null value type.
 *
 * @throws Exception If failed.
 */
@Test
public void testValueTypeNull() throws Exception {
    final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME);

    QueryEntity entity = new QueryEntity();

    entity.setKeyType("Key");

    ccfg.setQueryEntities(Collections.singleton(entity));

    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() throws Exception {
            grid(0).createCache(ccfg);

            return null;
        }
    }, IgniteCheckedException.class, "Value type cannot be null or empty");
}
 
Example 3
Source File: CacheBinaryKeyConcurrentQueryTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param name Cache name.
 * @param atomicityMode Cache atomicity mode.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(String name, CacheAtomicityMode atomicityMode) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName(name);
    ccfg.setCacheMode(PARTITIONED);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setAtomicityMode(atomicityMode);
    ccfg.setBackups(1);

    QueryEntity qryEntity = new QueryEntity();

    qryEntity.setKeyType(TestKey.class.getName());
    qryEntity.setValueType(TestValue.class.getName());

    qryEntity.addQueryField("id", Integer.class.getName(), null);
    qryEntity.addQueryField("val", Integer.class.getName(), null);

    qryEntity.setKeyFields(Collections.singleton("id"));

    qryEntity.setIndexes(F.asList(new QueryIndex("id"), new QueryIndex("val")));

    ccfg.setQueryEntities(F.asList(qryEntity));

    return ccfg;
}
 
Example 4
Source File: JdbcAbstractDmlStatementSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration for binary marshaller tests.
 */
final CacheConfiguration binaryCacheConfig() {
    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);

    QueryEntity e = new QueryEntity();

    e.setKeyType(String.class.getName());
    e.setValueType("Person");

    e.setKeyFieldName(KEY_ALIAS);

    e.addQueryField(KEY_ALIAS, e.getKeyType(), null);
    e.addQueryField("id", Integer.class.getName(), null);
    e.addQueryField("age", Integer.class.getName(), null);
    e.addQueryField("firstName", String.class.getName(), null);
    e.addQueryField("lastName", String.class.getName(), null);
    e.addQueryField("data", byte[].class.getName(), null);

    cache.setQueryEntities(Collections.singletonList(e));

    return cache;
}
 
Example 5
Source File: JdbcThinAbstractDmlStatementSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration for binary marshaller tests.
 */
final CacheConfiguration binaryCacheConfig() {
    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);

    QueryEntity e = new QueryEntity();

    e.setKeyType(String.class.getName());
    e.setValueType("Person");

    e.addQueryField("id", Integer.class.getName(), null);
    e.addQueryField("age", Integer.class.getName(), null);
    e.addQueryField("firstName", String.class.getName(), null);
    e.addQueryField("lastName", String.class.getName(), null);

    cache.setQueryEntities(Collections.singletonList(e));

    return cache;
}
 
Example 6
Source File: IgniteCacheJoinPartitionedAndReplicatedCollocationTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @return Cache configuration.
 */
private CacheConfiguration personCache() {
    CacheConfiguration ccfg = configuration(PERSON_CACHE, 0);

    // Person cache is replicated.
    ccfg.setCacheMode(REPLICATED);

    QueryEntity entity = new QueryEntity();
    entity.setKeyType(Integer.class.getName());
    entity.setValueType(Person.class.getName());
    entity.addQueryField("name", String.class.getName(), null);

    ccfg.setQueryEntities(F.asList(entity));

    return ccfg;
}
 
Example 7
Source File: JdbcThinMetadataSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param qryEntity Query entity.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfiguration(QueryEntity qryEntity) {
    CacheConfiguration<?,?> cache = defaultCacheConfiguration();

    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);

    cache.setQueryEntities(Collections.singletonList(qryEntity));

    return cache;
}
 
Example 8
Source File: IgniteCacheSqlInsertValidationSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param qryEntity Query entity.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfiguration(QueryEntity qryEntity) {
    CacheConfiguration<?, ?> cache = defaultCacheConfiguration();

    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setQueryEntities(Collections.singletonList(qryEntity));

    return cache;
}
 
Example 9
Source File: ClientReconnectAfterClusterRestartTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return CacheConfiguration Cache configuration.
 */
@NotNull private CacheConfiguration getCacheConfiguration() {
    CacheConfiguration ccfg = defaultCacheConfiguration();

    ccfg.setName(CACHE_PARAMS);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setCacheMode(CacheMode.PARTITIONED);

    List<QueryEntity> queryEntities = new ArrayList<>();

    QueryEntity entity = new QueryEntity();

    entity.setValueType("Params");
    entity.setKeyType("java.lang.Long");

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();

    fields.put("ID", "java.lang.Long");
    fields.put("PARTITIONID", "java.lang.Long");
    fields.put("CLIENTID", "java.lang.Long");
    fields.put("PARAMETRCODE", "java.lang.Long");
    fields.put("PARAMETRVALUE", "java.lang.Object");
    fields.put("PARENTID", "java.lang.Long");

    entity.setFields(fields);

    List<QueryIndex> indexes = new ArrayList<>();

    indexes.add(new QueryIndex("CLIENTID"));
    indexes.add(new QueryIndex("ID"));
    indexes.add(new QueryIndex("PARENTID"));

    entity.setIndexes(indexes);

    queryEntities.add(entity);

    ccfg.setQueryEntities(queryEntities);
    return ccfg;
}
 
Example 10
Source File: IgniteSqlNotNullConstraintTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private CacheConfiguration buildCacheConfiguration(CacheMode mode,
    CacheAtomicityMode atomicityMode, boolean hasNear, boolean writeThrough, boolean notNullAnnotated) {

    CacheConfiguration cfg = new CacheConfiguration(CACHE_PREFIX + "-" +
        mode.name() + "-" + atomicityMode.name() + (hasNear ? "-near" : "") +
        (writeThrough ? "-writethrough" : "") + (notNullAnnotated ? "-annot" : ""));

    cfg.setCacheMode(mode);
    cfg.setAtomicityMode(atomicityMode);
    cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

    QueryEntity qe = new QueryEntity(new QueryEntity(Integer.class, Person.class));

    if (!notNullAnnotated)
        qe.setNotNullFields(Collections.singleton("name"));

    cfg.setQueryEntities(F.asList(qe));

    if (hasNear)
        cfg.setNearConfiguration(new NearCacheConfiguration().setNearStartSize(100));

    if (writeThrough) {
        cfg.setCacheStoreFactory(singletonFactory(new TestStore()));
        cfg.setWriteThrough(true);
    }

    return cfg;
}
 
Example 11
Source File: KillQueryTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and populates a new cache that is used in distributed join scenario: We have table of Persons with some
 * autogenerated PK. Join filter should be based on Person.id column which is not collocated with the pk. Result
 * size of such join (with eq condition) is {@link #MAX_ROWS} rows.
 *
 * @param cacheName name of the created cache.
 * @param shift integer to avoid collocation, put different value for the different caches.
 */
private void createJoinCache(String cacheName, int shift) {
    CacheConfiguration<Long, Person> ccfg = GridAbstractTest.defaultCacheConfiguration();

    ccfg.setName(cacheName);

    ccfg.setCacheMode(PARTITIONED);
    ccfg.setBackups(1);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);
    ccfg.setSqlFunctionClasses(TestSQLFunctions.class);

    ccfg.setQueryEntities(Collections.singleton(
        new QueryEntity(Integer.class.getName(), Person.class.getName())
            .setTableName("PERSON")
            .setKeyFieldName("rec_id") // PK
            .addQueryField("rec_id", Integer.class.getName(), null)
            .addQueryField("id", Integer.class.getName(), null)
            .addQueryField("lastName", String.class.getName(), null)
            .setIndexes(Collections.singleton(new QueryIndex("id", true, "idx_" + cacheName)))
    ));

    grid(0).createCache(ccfg);

    try (IgniteDataStreamer<Object, Object> ds = grid(0).dataStreamer(cacheName)) {

        for (int recordId = 0; recordId < MAX_ROWS; recordId++) {
            // If two caches has the same PK, FK fields ("id") will be different.
            int intTabIdFK = (recordId + shift) % MAX_ROWS;

            ds.addData(recordId,
                new Person(intTabIdFK,
                    "Name_" + recordId,
                    "LastName_" + recordId,
                    42));
        }
    }
}
 
Example 12
Source File: ReadStoreStreamerService.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 5 votes vote down vote up
/**
 * check if the read side cache is already created or create it if missing
 * usually you should not need that as the writer and reader should be different nodes
 */
private IgniteCache<String, JournalReadItem> getOrCreateReadStoreCache() {
	IgniteCache<String, JournalReadItem> cache = igniteExtension.getIgnite().cache(READ_CACHE);

	if (null == cache) {
		CacheConfiguration<String, JournalReadItem> readItemCacheConfiguration = new CacheConfiguration<>();
		readItemCacheConfiguration.setBackups(1);
		readItemCacheConfiguration.setName(READ_CACHE);
		readItemCacheConfiguration.setAtomicityMode(CacheAtomicityMode.ATOMIC);
		readItemCacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
		readItemCacheConfiguration.setQueryEntities(Collections.singletonList(createJournalBinaryQueryEntity()));
		cache = igniteExtension.getIgnite().getOrCreateCache(readItemCacheConfiguration);
	}
	return cache;
}
 
Example 13
Source File: QueryDataPageScanTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
@Ignore("https://issues.apache.org/jira/browse/IGNITE-11998")
public void testMultipleIndexedTypes() throws Exception {
    final String cacheName = "test_multi_type";

    IgniteEx server = startGrid(0);
    server.cluster().active(true);

    CacheConfiguration<Object,Object> ccfg = new CacheConfiguration<>(cacheName);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 1));
    ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
    ccfg.setIndexedTypes(
        Integer.class, Integer.class,
        Long.class, String.class,
        Long.class, TestData.class
    );
    ccfg.setQueryEntities(
        Arrays.asList(
            new QueryEntity()
                .setValueType(UUID.class.getName())
                .setKeyType(Integer.class.getName())
                .setTableName("Uuids"),
            new QueryEntity()
                .setValueType(Person.class.getName())
                .setKeyType(Integer.class.getName())
                .setTableName("My_Persons")
                .setFields(Person.getFields())
        )
    );

    IgniteCache<Object,Object> cache = server.createCache(ccfg);

    cache.put(1L, "bla-bla");
    cache.put(2L, new TestData(777L));
    cache.put(3, 3);
    cache.put(7, UUID.randomUUID());
    cache.put(9, new Person("Vasya", 99));

    CacheDataTree.isLastFindWithDataPageScan();

    List<List<?>> res = cache.query(new SqlFieldsQuery("select z, _key, _val from TestData use index()")).getAll();
    assertEquals(1, res.size());
    assertEquals(777L, res.get(0).get(0));
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());

    res = cache.query(new SqlFieldsQuery("select _val, _key from String use index()")).getAll();
    assertEquals(1, res.size());
    assertEquals("bla-bla", res.get(0).get(0));
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());

    res = cache.query(new SqlFieldsQuery("select _key, _val from Integer use index()")).getAll();
    assertEquals(1, res.size());
    assertEquals(3, res.get(0).get(0));
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());

    res = cache.query(new SqlFieldsQuery("select _key, _val from uuids use index()")).getAll();
    assertEquals(1, res.size());
    assertEquals(7, res.get(0).get(0));
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());

    res = cache.query(new SqlFieldsQuery("select age, name from my_persons use index()")).getAll();
    assertEquals(1, res.size());
    assertEquals(99, res.get(0).get(0));
    assertEquals("Vasya", res.get(0).get(1));
    assertTrue(CacheDataTree.isLastFindWithDataPageScan());
}
 
Example 14
Source File: IgniteCrossCachesJoinsQueryTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @param cacheMode Cache mode.
 * @param backups Number of backups.
 * @param idx Index flag.
 * @param accountCache Account cache flag.
 * @param personCache Person cache flag.
 * @param orgCache Organization cache flag.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(String cacheName,
    CacheMode cacheMode,
    int backups,
    boolean idx,
    boolean accountCache,
    boolean personCache,
    boolean orgCache) {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName(cacheName);
    ccfg.setCacheMode(cacheMode);

    if (cacheMode == PARTITIONED)
        ccfg.setBackups(backups);

    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    List<QueryEntity> entities = new ArrayList<>();

    if (accountCache) {
        QueryEntity account = new QueryEntity();
        account.setKeyType(useCollocatedData() ? AffinityKey.class.getName() : Integer.class.getName());
        account.setValueType(Account.class.getName());
        account.addQueryField("id", Integer.class.getName(), null);
        account.addQueryField("personId", Integer.class.getName(), null);
        account.addQueryField("personDateId", Date.class.getName(), null);
        account.addQueryField("personStrId", String.class.getName(), null);

        if (idx) {
            account.setIndexes(F.asList(new QueryIndex("id"),
                new QueryIndex("personId"),
                new QueryIndex("personDateId"),
                new QueryIndex("personStrId")));
        }

        entities.add(account);
    }

    if (personCache) {
        QueryEntity person = new QueryEntity();
        person.setKeyType(useCollocatedData() ? AffinityKey.class.getName() : Integer.class.getName());
        person.setValueType(Person.class.getName());
        person.addQueryField("id", Integer.class.getName(), null);
        person.addQueryField("dateId", Date.class.getName(), null);
        person.addQueryField("strId", String.class.getName(), null);
        person.addQueryField("orgId", Integer.class.getName(), null);
        person.addQueryField("orgDateId", Date.class.getName(), null);
        person.addQueryField("orgStrId", String.class.getName(), null);
        person.addQueryField("name", String.class.getName(), null);
        person.addQueryField("salary", Integer.class.getName(), null);

        if (idx) {
            person.setIndexes(F.asList(new QueryIndex("id"),
                new QueryIndex("dateId"),
                new QueryIndex("strId"),
                new QueryIndex("orgId"),
                new QueryIndex("orgDateId"),
                new QueryIndex("orgStrId"),
                new QueryIndex("name"),
                new QueryIndex("salary")));
        }

        entities.add(person);
    }

    if (orgCache) {
        QueryEntity org = new QueryEntity();
        org.setKeyType(Integer.class.getName());
        org.setValueType(Organization.class.getName());
        org.addQueryField("id", Integer.class.getName(), null);
        org.addQueryField("dateId", Date.class.getName(), null);
        org.addQueryField("strId", String.class.getName(), null);
        org.addQueryField("name", String.class.getName(), null);

        if (idx) {
            org.setIndexes(F.asList(new QueryIndex("id"),
                new QueryIndex("dateId"),
                new QueryIndex("strId"),
                new QueryIndex("name")));
        }

        entities.add(org);
    }

    ccfg.setQueryEntities(entities);

    return ccfg;
}
 
Example 15
Source File: IgniteCachePrimitiveFieldsQuerySelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration<Integer, IndexedType> cacheConfiguration(String cacheName) {
    CacheConfiguration<Integer, IndexedType> ccfg = new CacheConfiguration<>(cacheName);

    QueryEntity entity = new QueryEntity(Integer.class.getName(), IndexedType.class.getName());

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();

    // Test will pass if we use java.lang.Integer instead of int.
    fields.put("iVal", "int");

    entity.setFields(fields);

    entity.setIndexes(F.asList(
        new QueryIndex("iVal")
    ));

    ccfg.setQueryEntities(F.asList(entity));

    return ccfg;
}
 
Example 16
Source File: DemoCachesLoadService.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Configure cacheEmployee.
 */
private static CacheConfiguration cacheCar() {
    CacheConfiguration ccfg = cacheConfiguration(CAR_CACHE_NAME);

    // Configure cacheCar types.
    Collection<QueryEntity> qryEntities = new ArrayList<>();

    // CAR.
    QueryEntity type = new QueryEntity();

    qryEntities.add(type);

    type.setKeyType(Integer.class.getName());
    type.setValueType(Car.class.getName());

    // Query fields for CAR.
    LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();

    qryFlds.put("id", "java.lang.Integer");
    qryFlds.put("parkingId", "java.lang.Integer");
    qryFlds.put("name", "java.lang.String");

    type.setFields(qryFlds);

    // Indexes for CAR.

    ArrayList<QueryIndex> indexes = new ArrayList<>();

    indexes.add(new QueryIndex("parkingId", QueryIndexType.SORTED, false, "CAR_PARKING"));
    type.setIndexes(indexes);

    ccfg.setQueryEntities(qryEntities);

    return ccfg;
}
 
Example 17
Source File: QueryEntityValidationSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Test failure if index type is null.
 *
 * @throws Exception If failed.
 */
@Test
public void testIndexTypeNull() throws Exception {
    final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME);

    QueryEntity entity = new QueryEntity();

    entity.setKeyType("Key");
    entity.setValueType("Value");

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();

    fields.put("a", Integer.class.getName());

    entity.setFields(fields);

    LinkedHashMap<String, Boolean> idxFields = new LinkedHashMap<>();

    idxFields.put("a", true);

    QueryIndex idx = new QueryIndex().setName("idx").setFields(idxFields).setIndexType(null);

    List<QueryIndex> idxs = new ArrayList<>();

    idxs.add(idx);

    entity.setIndexes(idxs);

    ccfg.setQueryEntities(Collections.singleton(entity));

    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() throws Exception {
            grid(0).createCache(ccfg);

            return null;
        }
    }, IgniteCheckedException.class, "Index type is not set");
}
 
Example 18
Source File: DemoCachesLoadService.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Configure cacheEmployee.
 */
private static CacheConfiguration cacheParking() {
    CacheConfiguration ccfg = cacheConfiguration(PARKING_CACHE_NAME);

    // Configure cacheParking types.
    Collection<QueryEntity> qryEntities = new ArrayList<>();

    // PARKING.
    QueryEntity type = new QueryEntity();

    qryEntities.add(type);

    type.setKeyType(Integer.class.getName());
    type.setValueType(Parking.class.getName());

    // Query fields for PARKING.
    LinkedHashMap<String, String> qryFlds = new LinkedHashMap<>();

    qryFlds.put("id", "java.lang.Integer");
    qryFlds.put("name", "java.lang.String");
    qryFlds.put("capacity", "java.lang.Integer");

    type.setFields(qryFlds);

    ccfg.setQueryEntities(qryEntities);

    return ccfg;
}
 
Example 19
Source File: QueryEntityCaseMismatchTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    cfg.setLocalHost("127.0.0.1");

    cfg.setPeerClassLoadingEnabled(true);

    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
    ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));

    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setIpFinder(ipFinder);

    cfg.setDiscoverySpi(discoSpi);

    CacheConfiguration<Object, Integer> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    cfg.setMarshaller(new BinaryMarshaller());

    QueryEntity queryEntity = new QueryEntity("KeyType", Integer.class.getName());

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();

    fields.put("a", "TypeA");
    fields.put("b", "TypeB");

    queryEntity.setFields(fields);

    //Specify key fields in upper register
    HashSet<String> keyFields = new HashSet<>();

    keyFields.add("a");
    keyFields.add("B");

    queryEntity.setKeyFields(keyFields);

    ccfg.setQueryEntities(F.asList(queryEntity));

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 20
Source File: CacheRegisterMetadataLocallyTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param name Cache name.
 * @param keyCls Key {@link Class}.
 * @param valCls Value {@link Class}.
 * @param <K> Key type.
 * @param <V> Value type.
 * @return Cache configuration
 */
private static <K, V> CacheConfiguration<K, V> cacheConfiguration(String name, Class<K> keyCls, Class<V> valCls) {
    CacheConfiguration<K, V> cfg = new CacheConfiguration<>(name);
    cfg.setQueryEntities(Collections.singleton(new QueryEntity(keyCls, valCls)));
    return cfg;
}