/** */ @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; }
/** * @param node Ignite instance. * @return Cache. */ private static IgniteCache<Integer, Person> startPeopleCache(Ignite node) { CacheConfiguration<Integer, Person> cacheCfg = new CacheConfiguration<>("people"); QueryEntity qe = new QueryEntity(Integer.class, Person.class); qe.setTableName("people"); cacheCfg.setQueryEntities(Collections.singleton(qe)); cacheCfg.setSqlSchema("PUBLIC"); return node.getOrCreateCache(cacheCfg); }
@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");
/** {@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"); }
/** * @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.setTableName("TEST_CACHE");
.addQueryField("name", String.class.getName(), null) .addQueryField("salary", Integer.class.getName(), null) .setTableName("NO_ALIAS_NON_SQL_KEY") )));
.setKeyConfiguration(new CacheKeyConfiguration("Employee", "orgId")) .setQueryEntities(new QueryEntity(int.class.getName(), "Employee") .setTableName("EMPLOYEE") .setFields( Stream.of(
/** * Check affinity column if custom affinity mapper is specified. */ @Test public void testTablesNullAffinityKey() throws Exception { IgniteEx ignite = startGrid(getConfiguration()); AffinityKeyMapper fakeMapper = new ConstantMapper(); ignite.getOrCreateCache(defaultCacheConfiguration().setName("NO_KEY_FIELDS_CACHE").setAffinityMapper(fakeMapper) .setQueryEntities(Collections.singleton( // A cache with no key fields new QueryEntity(Object.class.getName(), "Object2") .addQueryField("name", String.class.getName(), null) .addQueryField("salary", Integer.class.getName(), null) .setTableName("NO_KEY_TABLE") ))); List<List<String>> expected = Collections.singletonList(asList("NO_KEY_TABLE", null)); assertEquals(expected, execSql("SELECT TABLE_NAME, AFFINITY_KEY_COLUMN " + "FROM IGNITE.TABLES " + "WHERE CACHE_NAME = 'NO_KEY_FIELDS_CACHE'")); assertEquals(expected, execSql("SELECT TABLE_NAME, AFFINITY_KEY_COLUMN " + "FROM IGNITE.TABLES " + "WHERE AFFINITY_KEY_COLUMN IS NULL")); }
/** * @throws Exception In case of an error. */ @Test public void testEntryReadQueryEntities() throws Exception { Ignite ignite = startGrid(0); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache binary = ignite.createCache(new CacheConfiguration<>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');")); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');")); GridTestUtils.assertThrowsAnyCause( log, new Callable<Object>() { @Override public Object call() { return ignite.cache("binary").iterator().next(); } }, BinaryInvalidTypeException.class, "IdKey"); }
String tblName = tableName(entity); entity.setTableName(tblName); normalEntity.setTableName(normalTblName);
/** * @throws Exception In case of an error. */ @Test public void testValueReadQueryEntities() throws Exception { Ignite ignite = startGrid(0); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache binary = ignite.createCache(new CacheConfiguration<>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary")))); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');")); binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');")); GridTestUtils.assertThrowsAnyCause( log, new Callable<Object>() { @Override public Object call() { return ignite.cache("binary").get(1); } }, BinaryInvalidTypeException.class, "Payload"); }
/** * @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"); }
/** * @throws Exception In case of an error. */ @Test public void testEntryWriteCacheIsolation() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<IdKey, Payload> regular = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("regular").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType(getClass().getName() + "$IdKey").setKeyFields(Collections.singleton("id")) .setValueType(getClass().getName() + "$Payload").setFields(fields).setTableName("binary")))); IgniteCache<IdKey, Payload> binary = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); regular.put(new IdKey(1), new Payload("foo")); regular.put(new IdKey(2), new Payload("bar")); binary.put(new IdKey(1), new Payload("foo")); binary.put(new IdKey(2), new Payload("bar")); assertEquals(0, countRows(binary)); assertEquals(2, countRows(regular)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); }
qryEntity.addQueryField("id", Integer.class.getName(), null); qryEntity.addQueryField("name", String.class.getName(), null); qryEntity.setTableName("Type2"); qryEntity.setIndexes(Arrays.asList(new QueryIndex("id") .setName("index~!@#$%^&*()_=-+;[]{}|?,.*`:nameWithNonLetterSymbols"))); qryEntity.addQueryField("id", Integer.class.getName(), null); qryEntity.addQueryField("name", String.class.getName(), null); qryEntity.setTableName("Type1"); qryEntity.setIndexes(Arrays.asList(new QueryIndex("id")));
/** * @throws Exception In case of an error. */ @Test public void testValueWriteQueryEntities() 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, Object> binary = ignite.createCache(new CacheConfiguration<Integer, Object>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(1, new Payload("foo")); binary.put(2, new IdKey(2)); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); assertContainsExactlyOnce(capture.toString(), "expValType=Payload, actualValType=o.a.i.i.processors.cache.BinaryTypeMismatchLoggingTest$IdKey"); }
.setKeyConfiguration(new CacheKeyConfiguration("Employee", "orgId")) .setQueryEntities(new QueryEntity(int.class.getName(), "Employee") .setTableName("EMPLOYEE") .setFields( Stream.of(
/** * @throws Exception In case of an error. */ @Test public void testEntryWriteQueryEntities() throws Exception { Ignite ignite = startGridWithLogCapture(); LinkedHashMap<String, String> fields = new LinkedHashMap<>(); fields.put("id", "java.lang.Integer"); fields.put("str", "java.lang.String"); IgniteCache<IdKey, Payload> binary = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(new IdKey(1), new Payload("foo")); binary.put(new IdKey(2), new Payload("bar")); assertEquals(0, countRows(binary)); binary.destroy(); binary = ignite.createCache(new CacheConfiguration<IdKey, Payload>() .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity() .setKeyType("IdKey").setKeyFields(Collections.singleton("id")) .setValueType("Payload").setFields(fields).setTableName("binary")))); binary.put(new IdKey(1), new Payload("foo")); binary.put(new IdKey(2), new Payload("bar")); assertEquals(0, countRows(binary)); assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE); }
.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())
ccfg2.setName("t2"); QueryEntity entity1 = new QueryEntity(KeyClass1.class, ValueClass.class).setTableName("t1"); QueryEntity entity2 = new QueryEntity(KeyClass2.class, ValueClass.class).setTableName("t2");