use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class IgniteCacheCrossCacheJoinRandomTest method configuration.
/**
* @param name Cache name.
* @param cacheMode Cache mode.
* @param backups Number of backups.
* @return Cache configuration.
*/
private CacheConfiguration configuration(String name, CacheMode cacheMode, int backups) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setName(name);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setAtomicityMode(ATOMIC);
ccfg.setCacheMode(cacheMode);
if (cacheMode == PARTITIONED)
ccfg.setBackups(backups);
QueryEntity entity = new QueryEntity();
entity.setKeyType(Integer.class.getName());
entity.setValueType(TestObject.class.getName());
entity.addQueryField("parentId", Integer.class.getName(), null);
entity.setIndexes(F.asList(new QueryIndex("parentId")));
ccfg.setQueryEntities(F.asList(entity));
return ccfg;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class IgniteCacheMultipleIndexedTypesTest method testMultipleIndexedTypes.
/**
* @throws Exception If failed.
*/
public void testMultipleIndexedTypes() throws Exception {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
List<QueryEntity> qryEntities = new ArrayList<>();
{
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(Person.class.getName());
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("name", String.class.getName());
qryEntity.setFields(fields);
qryEntity.setIndexes(F.asList(new QueryIndex("name")));
qryEntities.add(qryEntity);
}
{
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType(Organization.class.getName());
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("name", String.class.getName());
qryEntity.setFields(fields);
qryEntity.setIndexes(F.asList(new QueryIndex("name")));
qryEntities.add(qryEntity);
}
ccfg.setQueryEntities(qryEntities);
Ignite ignite = ignite(0);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
checkCount(cache, Person.class, 0);
cache.put(1, new Person("a"));
checkCount(cache, Person.class, 1);
cache.remove(1);
checkCount(cache, Person.class, 0);
cache.put(1, new Person("a"));
checkCount(cache, Person.class, 1);
cache.put(1, new Organization("a"));
checkCount(cache, Person.class, 0);
checkCount(cache, Organization.class, 1);
cache.put(1, new Person("a"));
checkCount(cache, Person.class, 1);
checkCount(cache, Organization.class, 0);
cache.put(2, new Person("a"));
checkCount(cache, Person.class, 2);
checkCount(cache, Organization.class, 0);
cache.put(1, new Organization("a"));
checkCount(cache, Person.class, 1);
checkCount(cache, Organization.class, 1);
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class IgniteCacheNoClassQuerySelfTest method getConfiguration.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration c = super.getConfiguration(igniteInstanceName);
c.setDiscoverySpi(new TcpDiscoverySpi().setForceServerMode(true).setIpFinder(ipFinder));
CacheConfiguration cc = defaultCacheConfiguration();
c.setMarshaller(new BinaryMarshaller());
cc.setName("cache");
cc.setAtomicityMode(TRANSACTIONAL);
cc.setWriteSynchronizationMode(FULL_SYNC);
cc.setRebalanceMode(SYNC);
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getName());
qryEntity.setValueType("MyClass");
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("strField", String.class.getName());
fields.put("intField", Integer.class.getName());
fields.put("doubleField", Double.class.getName());
qryEntity.setFields(fields);
qryEntity.setFields(fields);
qryEntity.setIndexes(Arrays.asList(new QueryIndex("strField"), new QueryIndex("intField"), new QueryIndex("doubleField")));
cc.setQueryEntities(Collections.singletonList(qryEntity));
c.setCacheConfiguration(cc);
return c;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class IgniteCacheQueriesLoadTest1 method getDepositCfg.
/**
* @param parentCfg Parent config.
* @return Configuration.
*/
private static CacheConfiguration<Object, Object> getDepositCfg(CacheConfiguration<Object, Object> parentCfg) {
CacheConfiguration<Object, Object> depositCfg = new CacheConfiguration<>(parentCfg);
depositCfg.setName(DEPOSIT_CACHE);
String strCls = String.class.getCanonicalName();
String dblCls = Double.class.getCanonicalName();
String intCls = Integer.class.getCanonicalName();
LinkedHashMap<String, String> qryFields = new LinkedHashMap<>();
qryFields.put(ID, strCls);
qryFields.put(TRADER_ID, strCls);
qryFields.put(TRADER_LINK, intCls);
qryFields.put(BALANCE, dblCls);
qryFields.put(MARGIN_RATE, dblCls);
qryFields.put(BALANCE_ON_DAY_OPEN, dblCls);
QueryEntity qryEntity = new QueryEntity();
qryEntity.setValueType(DEPOSIT);
qryEntity.setKeyType(strCls);
qryEntity.setFields(qryFields);
qryEntity.setIndexes(Collections.singleton(new QueryIndex(ID, false)));
depositCfg.setQueryEntities(Collections.singleton(qryEntity));
return depositCfg;
}
use of org.apache.ignite.cache.QueryIndex in project ignite by apache.
the class QueryEntityValidationSelfTest method testIndexTypeNull.
/**
* Test failure if index type is null.
*
* @throws Exception If failed.
*/
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");
}
Aggregations