/** * @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); }
/** * @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); }
/** * @return Query entity for Person. */ private static Collection<QueryEntity> personQueryEntity() { QueryEntity entity = new QueryEntity(Integer.class, JoinSqlTestHelper.Person.class); entity.setKeyFieldName("ID"); entity.getFields().put("ID", String.class.getName()); return Collections.singletonList(entity); }
/** * @return Query entity for Organization. */ static Collection<QueryEntity> organizationQueryEntity() { QueryEntity entity = new QueryEntity(String.class, Organization.class); entity.setKeyFieldName("ID"); entity.getFields().put("ID", String.class.getName()); return Collections.singletonList(entity); }
/** * @return Query entity for Organization. */ static Collection<QueryEntity> personQueryEntity() { QueryEntity entity = new QueryEntity(String.class, Person.class); entity.setKeyFieldName("ID"); entity.getFields().put("ID", String.class.getName()); return Collections.singletonList(entity); }
res.setValueType(in.readString()); res.setTableName(in.readString()); res.setKeyFieldName(in.readString()); res.setValueFieldName(in.readString());
res.setKeyFieldName(pkCol.columnName());
/** * @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")); }
/** * @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; }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String testIgniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(testIgniteInstanceName); CacheConfiguration<Integer, Person> ccfg = new CacheConfiguration<>("Person"); ccfg.setIndexedTypes(Integer.class, Person.class); ccfg.getQueryEntities().iterator().next().setKeyFieldName("id"); ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT); ccfg.setCacheMode(CacheMode.PARTITIONED); cfg.setCacheConfiguration(ccfg); // Let the node with index 1 be client node. cfg.setClientMode(F.eq(testIgniteInstanceName, getTestIgniteInstanceName(CLI_IDX))); return cfg; }
queryEntity.setKeyFieldName("value3");
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)); entity.setValueType(null); entity.setKeyFieldName("id"); entity.setValueFieldName("v"); entity.setValueType(Person.class.getName()); entity.setKeyFieldName("id"); entity.setValueFieldName("v");
/** * @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; }
/** * @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 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"); }
normalEntity.setFields(entity.getFields()); normalEntity.setKeyFields(entity.getKeyFields()); normalEntity.setKeyFieldName(entity.getKeyFieldName()); normalEntity.setValueFieldName(entity.getValueFieldName()); normalEntity.setNotNullFields(entity.getNotNullFields());
.setKeyFieldName("id") .setNotNullFields(Collections.singleton("id")) .setDefaultFieldValues(Collections.singletonMap("id", 0))
.setIndexedTypes(Integer.class, City.class).setSqlSchema(QueryUtils.DFLT_SCHEMA); ccfg.getQueryEntities().iterator().next().setKeyFieldName("id");
QueryEntity qeWithPrecision = new QueryEntity() .setKeyType("java.lang.String") .setKeyFieldName("my_key") .setValueType("CustomKeyType") .addQueryField("my_key", "java.lang.String", "my_key")