/** * @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 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 with query entities - unfortunately, we need this to enable indexing at all. */ private CacheConfiguration cacheConfigurationForIndexing() { CacheConfiguration<?, ?> ccfg = cacheConfiguration(); ccfg.setName(INDEXED_CACHE_NAME); ccfg.setQueryEntities(Collections.singletonList( new QueryEntity() .setKeyType(Integer.class.getName()) .setValueType(Integer.class.getName()) )); return ccfg; }
/** * @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 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; }
/** * @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); }
/** * @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; }
@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");
/** * @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 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 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; }
/** * Creates cache configuration with {@link QueryEntity} created * using {@link CacheConfiguration#setQueryEntities(Collection)} call. * * @return The cache configuration. */ private CacheConfiguration cacheConfigWithQueryEntity() { 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; }
/** * Test null value type. * * @throws Exception If failed. */ @Test public void testValueTypeNull() throws Exception { final CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME); QueryEntity entity = new QueryEntity(); entity.setKeyType("Key"); ccfg.setQueryEntities(Collections.singleton(entity)); GridTestUtils.assertThrows(log, new Callable<Void>() { @Override public Void call() throws Exception { grid(0).createCache(ccfg); return null; } }, IgniteCheckedException.class, "Value type cannot be null or empty"); }
/** * @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; }
/** * @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; }
/** {@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; }
/** * @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"); }