/** * */ private static CacheConfiguration createBinCacheConfig() { CacheConfiguration ccfg = cacheConfig("S2P-bin", true, false); QueryEntity e = new QueryEntity(String.class.getName(), "Person"); LinkedHashMap<String, String> flds = new LinkedHashMap<>(); flds.put("id", Integer.class.getName()); flds.put("firstName", String.class.getName()); flds.put("secondName", String.class.getName()); e.setFields(flds); e.setIndexes(Collections.<QueryIndex>emptyList()); ccfg.setQueryEntities(Collections.singletonList(e)); return ccfg; }
/** * 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; }
/** * @return Local cache configuration with a pre-configured index. */ CacheConfiguration<KeyClass, ValueClass> localCacheConfiguration() { CacheConfiguration<KeyClass, ValueClass> res = cacheConfiguration(); res.getQueryEntities().iterator().next().setIndexes(Collections.singletonList( new QueryIndex(FIELD_NAME_2_ESCAPED, true, IDX_NAME_LOCAL))); res.setCacheMode(CacheMode.LOCAL); return res; }
/** * */ public static List<QueryEntity> getIndexCfg() { ArrayList<QueryEntity> entities = new ArrayList<>(); QueryEntity qe = new QueryEntity(String.class.getName(), Person.class.getName()); LinkedHashMap<String, String> fieldsMap = new LinkedHashMap<>(); fieldsMap.put("name", String.class.getName()); fieldsMap.put("age", Integer.class.getName()); qe.setFields(fieldsMap); ArrayList<QueryIndex> indices = new ArrayList<>(); QueryIndex index = new QueryIndex("name", true, "LONG_NAME_123456789012345678901234567890" + "12345678901234567890123456789012345678901234567890123456789012345678901234567890"); QueryIndex index2 = new QueryIndex("age", true, "AGE_IDX"); indices.add(index); indices.add(index2); qe.setIndexes(indices); entities.add(qe); return entities; }
/** * @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; }
/** * @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 idxName Name index flag. * @param idxOrgId Org ID index flag. * @return Entity. */ 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 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; }
/** * @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; }
/** */ private CacheConfiguration cacheACfg() { CacheConfiguration<?,?> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); cfg.setName("A"); QueryEntity eA = new QueryEntity(Integer.class.getName(), "A"); eA.setFields(fieldsAA); QueryEntity eB = new QueryEntity(Integer.class.getName(), "B"); eB.setFields(fieldsAB); List<QueryEntity> list = new ArrayList<>(2); list.add(eA); list.add(eB); QueryIndex idx = new QueryIndex("txt"); idx.setIndexType(QueryIndexType.FULLTEXT); eB.setIndexes(Collections.singleton(idx)); cfg.setQueryEntities(list); return cfg; }
/** * @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); }
@Override public Object call() throws Exception { QueryEntity e = new QueryEntity(); e.setTableName("City"); e.setKeyFields(Collections.singleton("name")); e.setFields(new LinkedHashMap<>(Collections.singletonMap("name", String.class.getName()))); e.setIndexes(Collections.singleton(new QueryIndex("name").setName("idx"))); e.setKeyType("CityKey"); e.setValueType("City"); queryProcessor(client()).dynamicTableCreate("PUBLIC", e, CacheMode.PARTITIONED.name(), null, null, null, null, CacheAtomicityMode.ATOMIC, null, 10, false, false); return null; } }, SchemaOperationException.class, "Index already exists: idx");
/** * @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; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); cfg.setMarshaller(null); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME); QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(TestBuilderValue.class.getName()); ArrayList<QueryIndex> idxs = new ArrayList<>(); QueryIndex idx = new QueryIndex("iVal"); idxs.add(idx); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("iVal", Integer.class.getName()); entity.setFields(fields); entity.setIndexes(idxs); ccfg.setQueryEntities(Collections.singleton(entity)); cfg.setCacheConfiguration(ccfg); BinaryConfiguration binaryCfg = new BinaryConfiguration(); BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(); typeCfg.setTypeName(TestBuilderValue.class.getName()); binaryCfg.setTypeConfigurations(Collections.singletonList(typeCfg)); cfg.setBinaryConfiguration(binaryCfg); return cfg; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration commonConfiguration(int idx) throws Exception { IgniteConfiguration cfg = super.commonConfiguration(idx); if (idx != nodeIndex()) return cfg; CacheConfiguration staticCacheCfg = cacheConfiguration().setName(STATIC_CACHE_NAME); ((QueryEntity)staticCacheCfg.getQueryEntities().iterator().next()).setIndexes(Collections.singletonList(index( IDX_NAME_1, field(FIELD_NAME_1) ))); CacheConfiguration[] newCfgs = new CacheConfiguration[F.isEmpty(cfg.getCacheConfiguration()) ? 1 : cfg.getCacheConfiguration().length + 1]; if (newCfgs.length > 1) System.arraycopy(cfg.getCacheConfiguration(), 0, newCfgs, 0, newCfgs.length - 1); newCfgs[newCfgs.length - 1] = staticCacheCfg; cfg.setCacheConfiguration(newCfgs); 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 igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); CacheConfiguration cache = new CacheConfiguration(DEFAULT_CACHE_NAME); cache.setCacheMode(PARTITIONED); cache.setAtomicityMode(atomicityMode()); cache.setWriteSynchronizationMode(FULL_SYNC); cache.setBackups(1); cache.setRebalanceMode(CacheRebalanceMode.SYNC); QueryEntity qryEntity = new QueryEntity(); qryEntity.setKeyType(AffinityKey.class.getName()); qryEntity.setValueType(IndexedEntity.class.getName()); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("val", String.class.getName()); qryEntity.setFields(fields); qryEntity.setIndexes(Arrays.asList(new QueryIndex("val", QueryIndexType.FULLTEXT))); cache.setQueryEntities(Arrays.asList(qryEntity)); cfg.setCacheConfiguration(cache); TcpCommunicationSpi commSpi = new TcpCommunicationSpi(); commSpi.setSharedMemoryPort(-1); cfg.setCommunicationSpi(commSpi); 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; }
/** {@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 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; }