/** * @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); }
entity.setTableName(tblName); Map<String, String> aliases = new HashMap<>(entity.getAliases()); for (String fieldName : entity.getFields().keySet()) { String fieldAlias = entity.getAliases().get(fieldName); entity.setAliases(aliases); for (QueryIndex idx : entity.getIndexes()) idx.setName(indexName(tblName, idx)); QueryEntity normalEntity = entity instanceof QueryEntityEx ? new QueryEntityEx() : new QueryEntity(); normalEntity.setKeyType(entity.getKeyType()); normalEntity.setValueType(entity.getValueType()); normalEntity.setFields(entity.getFields()); normalEntity.setKeyFields(entity.getKeyFields()); normalEntity.setKeyFieldName(entity.getKeyFieldName()); normalEntity.setValueFieldName(entity.getValueFieldName()); normalEntity.setNotNullFields(entity.getNotNullFields()); normalEntity.setDefaultFieldValues(entity.getDefaultFieldValues()); normalEntity.setFieldsPrecision(entity.getFieldsPrecision()); normalEntity.setFieldsScale(entity.getFieldsScale()); String normalTblName = entity.getTableName(); normalEntity.setTableName(normalTblName);
/** * Create data transfer object for given cache type metadata. * * @param q Actual cache query entities. */ private VisorQueryEntity(QueryEntity q) { assert q != null; keyType = q.getKeyType(); valType = q.getValueType(); keyFields = toList(q.getKeyFields()); LinkedHashMap<String, String> qryFields = q.getFields(); qryFlds = new LinkedHashMap<>(qryFields); aliases = U.copyMap(q.getAliases()); Collection<QueryIndex> qryIdxs = q.getIndexes(); grps = new ArrayList<>(qryIdxs.size()); for (QueryIndex qryIdx : qryIdxs) grps.add(new VisorQueryIndex(qryIdx)); tblName = q.getTableName(); keyFieldName = q.getKeyFieldName(); valFieldName = q.getValueFieldName(); }
/** * @return Query entity for Organization. */ private static Collection<QueryEntity> organizationQueryEntity() { QueryEntity entity = new QueryEntity(Integer.class, JoinSqlTestHelper.Organization.class); entity.setKeyFieldName("ID"); entity.getFields().put("ID", String.class.getName()); return Collections.singletonList(entity); }
/** * Add validate property to QueryTypeDescriptor. * * @param ctx Kernel context. * @param qryEntity Query entity. * @param d Descriptor. * @param name Field name. * @throws IgniteCheckedException */ private static void addKeyValueValidationProperty(GridKernalContext ctx, QueryEntity qryEntity, QueryTypeDescriptorImpl d, String name, boolean isKey) throws IgniteCheckedException { Map<String, Object> dfltVals = qryEntity.getDefaultFieldValues(); Map<String, Integer> precision = qryEntity.getFieldsPrecision(); Map<String, Integer> scale = qryEntity.getFieldsScale(); String typeName = isKey ? qryEntity.getKeyType() : qryEntity.getValueType(); Object dfltVal = dfltVals.get(name); QueryBinaryProperty prop = buildBinaryProperty( ctx, name, U.classForName(typeName, Object.class, true), d.aliases(), isKey, true, dfltVal, precision == null ? -1 : precision.getOrDefault(name, -1), scale == null ? -1 : scale.getOrDefault(name, -1)); d.addProperty(prop, true, false); }
QueryEntity res = new QueryEntity(); res.setKeyType(in.readString()); res.setValueType(in.readString()); res.setTableName(in.readString()); res.setKeyFieldName(in.readString()); res.setValueFieldName(in.readString()); res.setFields(fields); res.setKeyFields(keyFields); res.setNotNullFields(notNullFields); res.setDefaultFieldValues(defVals); res.setFieldsPrecision(fieldsPrecision); res.setFieldsScale(fieldsScale); aliases.put(in.readString(), in.readString()); res.setAliases(aliases); indexes.add(readQueryIndex(in)); res.setIndexes(indexes);
QueryEntity res = new QueryEntity(); res.setTableName(createTbl.tableName()); res.addQueryField(e.getKey(), getTypeClassName(gridCol), null); res.setDefaultFieldValues(dfltValues); res.setFieldsPrecision(precision); res.setFieldsScale(scale); res.setKeyFieldName(pkCol.columnName()); res.setKeyFields(createTbl.primaryKeyColumns()); res.setValueFieldName(valCol.columnName()); res.setValueType(valTypeName); res.setKeyType(keyTypeName);
@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");
private CacheConfiguration buildCacheConfiguration(String name) { if (name.equals(NODE_BAD_CONF_MISS_KEY_FIELD)) { CacheConfiguration ccfg = new CacheConfiguration(NODE_BAD_CONF_MISS_KEY_FIELD); QueryEntity qe = new QueryEntity(Object.class.getName(), Object.class.getName()); qe.setKeyFieldName("k"); qe.addQueryField("a", Integer.class.getName(), null); ccfg.setQueryEntities(F.asList(qe)); return ccfg; QueryEntity qe = new QueryEntity(Object.class.getName(), Object.class.getName()); qe.setValueFieldName("v"); qe.addQueryField("a", Integer.class.getName(), null); ccfg.setQueryEntities(F.asList(qe)); return ccfg; QueryEntity entity = new QueryEntity(); entity.setKeyType(Integer.class.getName()); entity.setValueType(Person.class.getName()); entity.setFields(fields); QueryEntity entity = new QueryEntity(); entity.setKeyType(null); entity.setValueType(null); entity.setKeyFieldName("id"); entity.setValueFieldName("v");
.setRebalanceTimeout(142536) .setKeyConfiguration(new CacheKeyConfiguration("Employee", "orgId")) .setQueryEntities(new QueryEntity(int.class.getName(), "Employee") .setTableName("EMPLOYEE") .setFields( Stream.of( new SimpleEntry<>("id", Integer.class.getName()), )) .setKeyFields(Collections.singleton("id")) .setNotNullFields(Collections.singleton("id")) .setDefaultFieldValues(Collections.singletonMap("id", 0)) .setIndexes(Collections.singletonList(new QueryIndex("id", true, "IDX_EMPLOYEE_ID"))) .setAliases(Stream.of("id", "orgId").collect(Collectors.toMap(f -> f, String::toUpperCase))) );
/** * @throws Exception In case of an error. */ @Test public void testValueWriteMultipleQueryEntities() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<Integer, Payload> binary = ignite.createCache(new CacheConfiguration<Integer, Payload>() .setName("binary").setQueryEntities(Arrays.asList( new QueryEntity().setKeyType("Foo").setKeyFieldName("id") .setValueType("Bar").setFields(fields).setTableName("regular"), new QueryEntity().setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(1, new Payload("foo")); binary.put(2, new Payload("bar")); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), "valType=o.a.i.i.processors.cache.BinaryTypeMismatchLoggingTest$Payload"); }
/** * @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; }
/** * @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")); }
QueryEntity queryEntity = new QueryEntity(); queryEntity.setKeyType("java.lang.Integer"); queryEntity.setValueType("org.apache.ignite.cache.store.jdbc.model.TestPojo"); queryEntity.setTableName("TEST_CACHE"); queryEntity.setKeyFieldName("value3"); queryEntity.setKeyFields(keyFiles); queryEntity.setFields(fields); queryEntity.setAliases(aliases);
/** * @return cache configuration with test table */ @NotNull private CacheConfiguration<Object, Object> getTestTableConfiguration() { LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("a", "java.lang.Integer"); fields.put("B", "java.lang.String"); CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(TEST_CACHE_NAME); ccfg.setQueryEntities(Collections.singletonList( new QueryEntity() .setKeyType("java.lang.Integer") .setValueType("TestIndexObject") .setFields(fields) )); 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; }
assert qryEntity != null; writer.writeString(qryEntity.getKeyType()); writer.writeString(qryEntity.getValueType()); writer.writeString(qryEntity.getTableName()); writer.writeString(qryEntity.getKeyFieldName()); writer.writeString(qryEntity.getValueFieldName()); LinkedHashMap<String, String> fields = qryEntity.getFields(); Set<String> keyFields = qryEntity.getKeyFields(); Set<String> notNullFields = qryEntity.getNotNullFields(); Map<String, Object> defVals = qryEntity.getDefaultFieldValues(); Map<String, Integer> fieldsPrecision = qryEntity.getFieldsPrecision(); Map<String, Integer> fieldsScale = qryEntity.getFieldsScale(); Map<String, String> aliases = qryEntity.getAliases(); Collection<QueryIndex> indexes = qryEntity.getIndexes();
@Test public void testExecuteWithMetaDataAndCustomKeyPrecision() throws Exception { QueryEntity qeWithPrecision = new QueryEntity() .setKeyType("java.lang.String") .setKeyFieldName("my_key") .setValueType("CustomKeyType") .addQueryField("my_key", "java.lang.String", "my_key") .addQueryField("strField", "java.lang.String", "strField") .setFieldsPrecision(ImmutableMap.of("strField", 999, "my_key", 777));
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); Map<String, Object> defsFK2 = new HashMap<>(); defsFK2.put("fk2", DEFAULT_FK2_VAL); cache = jcache(grid(0), defaultCacheConfiguration() .setName("testCache") .setQueryEntities(Arrays.asList( new QueryEntity(Key.class.getName(), Val.class.getName()) .addQueryField("fk1", "java.lang.Long", null) .addQueryField("fk2", "java.lang.Long", null) .addQueryField("fv1", "java.lang.Long", null) .addQueryField("fv2", "java.lang.Long", null) .setTableName("FORGOTTEN_KEY_FLDS"), new QueryEntity(Key.class.getName(), Integer.class.getName()) .addQueryField("fk1", "java.lang.Long", null) .addQueryField("fk2", "java.lang.Long", null) .setDefaultFieldValues(defsFK2) .setKeyFields(new HashSet<>(Arrays.asList("fk1", "fk2"))) .setTableName("WITH_KEY_FLDS"), new QueryEntity(Integer.class.getName(), Val2.class.getName()) .addQueryField("fv1", "java.lang.Long", null) .addQueryField("fv2", "java.lang.Long", null) .setTableName("INT_KEY_TAB"), new QueryEntity(SuperKey.class, String.class) .setTableName("SUPER_TAB") )) , "testCache"); }
/** */ @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; }