/** * Create type metadata for class. * * @param cls Class. * @return Type metadata. */ private static QueryEntity entityForClass(Class cls) { QueryEntity entity = new QueryEntity(Integer.class.getName(), cls.getName()); entity.addQueryField("val", Integer.class.getName(), null); entity.setIndexes(Collections.singletonList(new QueryIndex("val", true))); return entity; }
/** */ @NotNull private CacheConfiguration<Integer, Salary> cacheCfg(String tabName, String cacheName) { CacheConfiguration<Integer, Salary> ccfg = new CacheConfiguration<>(cacheName); QueryEntity queryEntity = new QueryEntity(Integer.class.getName(), Salary.class.getName()); queryEntity.setTableName(tabName); queryEntity.addQueryField("id", Integer.class.getName(), null); queryEntity.addQueryField("amount", BigDecimal.class.getName(), null); Map<String, Integer> precision = new HashMap<>(); Map<String, Integer> scale = new HashMap<>(); precision.put("amount",PRECISION); scale.put("amount", SCALE); queryEntity.setFieldsPrecision(precision); queryEntity.setFieldsScale(scale); ccfg.setQueryEntities(Collections.singletonList(queryEntity)); return ccfg; }
/** * @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; }
/** * @param grpName Group name. * @param cacheName Cache name. * @return Person cache configuration. */ private CacheConfiguration personCacheConfiguration(String grpName, String cacheName) { QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Person.class.getName()); entity.addQueryField("name", String.class.getName(), null); return cacheConfiguration(grpName, cacheName, entity); }
/** * @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; }
/** * @param idxName Index name. * @param idxOrgId Index org id. */ private QueryEntity personEntity(boolean idxName, boolean idxOrgId) { QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Person.class.getName()); entity.addQueryField("orgId", Integer.class.getName(), null); entity.addQueryField("name", String.class.getName(), null); List<QueryIndex> idxs = new ArrayList<>(); if (idxName) { QueryIndex idx = new QueryIndex("name"); idxs.add(idx); } if (idxOrgId) { QueryIndex idx = new QueryIndex("orgId"); idxs.add(idx); } entity.setIndexes(idxs); return entity; }
/** * @param igniteInstanceName Ignite instance name. * @return Grid configuration used for starting the grid ready for manipulating binary objects. * @throws Exception If failed. */ IgniteConfiguration getBinaryConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = getConfiguration0(igniteInstanceName); cfg.setMarshaller(new BinaryMarshaller()); CacheConfiguration ccfg = cfg.getCacheConfiguration()[0]; ccfg.getQueryEntities().clear(); 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); ccfg.setQueryEntities(Collections.singletonList(e)); return cfg; }
/** * @param tbl Table name. * @param cacheName Cache name. * @return Cache with registered query entity. */ private IgniteCache<Long, Person> registerQueryEntity(String tbl, String cacheName) { QueryEntity qe = new QueryEntity() .setValueType(Person.class.getName()) .setKeyType(Long.class.getName()) .setValueFieldName("_value") .setKeyFieldName("id") .addQueryField("id", Long.class.getName(), null) .addQueryField("_value", Person.class.getName(), null) .addQueryField("name", String.class.getName(), null) .addQueryField("orgId", Long.class.getName(), null); qe.setTableName(tbl); return node.createCache(new CacheConfiguration<Long, Person>() .setName(cacheName) .setQueryEntities(Collections.singletonList(qe)) .setSqlSchema("TEST")); }
/** * @param grpName Group name. * @param cacheName Cache name. * @return Account cache configuration. */ private CacheConfiguration accountCacheConfiguration(String grpName, String cacheName) { QueryEntity entity = new QueryEntity(); entity.setKeyType(AffinityKey.class.getName()); entity.setValueType(Account.class.getName()); entity.addQueryField("personId", Integer.class.getName(), null); entity.addQueryField("attr", String.class.getName(), null); entity.setIndexes(F.asList(new QueryIndex("personId"))); return cacheConfiguration(grpName, cacheName, entity); }
/** @throws Exception If failed.*/ private void createCachesForDecimalPrecisionTests() throws Exception { Map<String, Integer> decDecPrecision = new HashMap<>(); decDecPrecision.put(KEY_FIELD_NAME, 4); decDecPrecision.put(VAL_FIELD_NAME, 4); jcache(grid(0), cacheConfiguration(new QueryEntity(BigDecimal.class.getName(), BigDecimal.class.getName()) .setFieldsPrecision(decDecPrecision)), DEC_CACHE_NAME_FOR_PREC); Map<String, Integer> orgEmployeePrecision = new HashMap<>(); orgEmployeePrecision.put("id", 4); orgEmployeePrecision.put("salary", 4); jcache(grid(0), cacheConfiguration(new QueryEntity(DecOrganization.class.getName(), Employee.class.getName()) .setKeyFields(Collections.singleton("id")) .addQueryField("id", "java.math.BigDecimal", "id") .addQueryField("salary", "java.math.BigDecimal", "salary") .setFieldsPrecision(orgEmployeePrecision)), OBJ_CACHE_NAME_FOR_PREC); Map<String, Integer> decEmployeePrecision = new HashMap<>(); decEmployeePrecision.put(KEY_FIELD_NAME, 4); decEmployeePrecision.put("salary", 4); jcache(grid(0), cacheConfiguration(new QueryEntity(BigDecimal.class.getName(), Employee.class.getName()) .addQueryField("salary", "java.math.BigDecimal", "salary") .setFieldsPrecision(decEmployeePrecision)), DEC_EMPL_CACHE_NAME_FOR_PREC); }
/** * @param backups Number of backups. * @return Cache configuration. */ private CacheConfiguration accountCache(int backups) { CacheConfiguration ccfg = configuration(ACCOUNT_CACHE, backups); QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Account.class.getName()); entity.addQueryField("personId", Integer.class.getName(), null); entity.addQueryField("name", String.class.getName(), null); entity.setIndexes(F.asList(new QueryIndex("personId"))); ccfg.setQueryEntities(F.asList(entity)); return ccfg; }
/** * @param cacheName Cache name. * @return Cache config. */ protected CacheConfiguration getCacheConfiguration(final String cacheName) { CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME); ccfg.setWriteSynchronizationMode(FULL_SYNC); QueryEntity person = new QueryEntity(); person.setKeyType(TestKey.class.getName()); person.setValueType(Person.class.getName()); person.addQueryField("name", String.class.getName(), null); ccfg.setQueryEntities(Collections.singletonList(person)); ccfg.setName(cacheName); return ccfg; }
/** * @param idxName Name index flag. * @return Entity. */ private QueryEntity organizationEntity(boolean idxName) { QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Organization.class.getName()); entity.addQueryField("name", String.class.getName(), null); if (idxName) { QueryIndex idx = new QueryIndex("name"); entity.setIndexes(F.asList(idx)); } return entity; }
/** * @return Default cache configuration. */ protected CacheConfiguration<KeyClass, ValueClass> cacheConfiguration() { CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME); QueryEntity entity = new QueryEntity(); entity.setKeyType(KeyClass.class.getName()); entity.setValueType(ValueClass.class.getName()); entity.setKeyFieldName(FIELD_KEY_ALIAS); entity.addQueryField(FIELD_KEY_ALIAS, entity.getKeyType(), null); entity.addQueryField(FIELD_KEY, Long.class.getName(), null); entity.addQueryField(FIELD_NAME_1_ESCAPED, Long.class.getName(), null); entity.addQueryField(FIELD_NAME_2_ESCAPED, Long.class.getName(), null); entity.setKeyFields(Collections.singleton(FIELD_KEY)); entity.setAliases(Collections.singletonMap(FIELD_NAME_2_ESCAPED, alias(FIELD_NAME_2_ESCAPED))); ccfg.setQueryEntities(Collections.singletonList(entity)); ccfg.setNodeFilter(new NodeFilter()); ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); ccfg.setBackups(1); ccfg.setAffinity(new RendezvousAffinityFunction(false, 128)); return ccfg; }
/** * @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; }
/** {@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; }
/** * @return Cache configuration. */ private CacheConfiguration<?, ?> cacheConfiguration() { CacheConfiguration ccfg = new CacheConfiguration(PERSON_CACHE); ccfg.setSqlSchema(PERSON_SCHEMA); ccfg.setCacheMode(CacheMode.PARTITIONED); QueryEntity person = new QueryEntity(); person.setKeyType(Integer.class.getName()); person.setValueType(Person.class.getName()); person.addQueryField("orgId", Integer.class.getName(), null); person.addQueryField("name", String.class.getName(), null); person.setIndexes(F.asList(new QueryIndex("orgId"), new QueryIndex("name"))); ccfg.setQueryEntities(F.asList(person)); return ccfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName()); IgniteConfiguration cfg = super.getConfiguration(gridName); CacheConfiguration<?,?> cache = defaultCacheConfiguration(); cache.setWriteSynchronizationMode(FULL_SYNC); cache.setAtomicityMode(TRANSACTIONAL); cfg.setConnectorConfiguration(new ConnectorConfiguration()); QueryEntity queryEntity = new QueryEntity(); queryEntity.setKeyType("java.lang.String"); queryEntity.setValueType("org.apache.ignite.internal.JdbcTestObject"); queryEntity.addQueryField("id", "java.lang.Integer", null); queryEntity.addQueryField("testObject", "org.apache.ignite.internal.JdbcTestObject2", null); queryEntity.setIndexes(Collections.singletonList(new QueryIndex("id"))); cache.setQueryEntities(Collections.singletonList(queryEntity)); cfg.setCacheConfiguration(cache); return cfg; }
/** * @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; }
/** * @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; }