/** * Constructor. * * @param ccfg Cache configuration. */ public StoredCacheData(CacheConfiguration<?, ?> ccfg) { A.notNull(ccfg, "ccfg"); this.ccfg = ccfg; this.qryEntities = ccfg.getQueryEntities(); }
/** * @return {@code True} in case cache supports query. */ public boolean isQueryEnabled() { return !F.isEmpty(cacheCfg.getQueryEntities()); }
/** * @param ccfg Cache configuration. * @return {@code true} If query index must be enabled for this cache. */ public static boolean isEnabled(CacheConfiguration<?,?> ccfg) { return !F.isEmpty(ccfg.getIndexedTypes()) || !F.isEmpty(ccfg.getQueryEntities()); }
/** * @param cache Cache. * @return Name of the table contained by this cache. */ @SuppressWarnings("unchecked") private static String tableName(IgniteCache<?, ?> cache) { return ((Collection<QueryEntity>)cache.getConfiguration(CacheConfiguration.class).getQueryEntities()) .iterator().next().getTableName(); }
/** * @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; }
/** * @throws Exception If failed. */ @Test public void testGroupIndex() throws Exception { CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setIndexedTypes(Integer.class, TestValueGroupIndex.class); assertEquals(1, ccfg.getQueryEntities().size()); QueryEntity ent = (QueryEntity)ccfg.getQueryEntities().iterator().next(); assertEquals(1, ent.getIndexes().size()); QueryIndex idx = ent.getIndexes().iterator().next(); assertEquals(10, idx.getInlineSize()); }
/** * @param ctx Context. * @param cfg0 Template configuration. * @return Request to add template. */ static DynamicCacheChangeRequest addTemplateRequest(GridKernalContext ctx, CacheConfiguration<?, ?> cfg0) { CacheConfiguration<?, ?> cfg = new CacheConfiguration<>(cfg0); DynamicCacheChangeRequest req = new DynamicCacheChangeRequest(UUID.randomUUID(), cfg.getName(), ctx.localNodeId()); req.template(true); req.startCacheConfiguration(cfg); req.schema(new QuerySchema(cfg.getQueryEntities())); req.deploymentId(IgniteUuid.randomUuid()); return req; }
/** * @throws Exception If failed. */ @Test public void testSingleFieldIndexes() throws Exception { CacheConfiguration ccfg = defaultCacheConfiguration(); ccfg.setIndexedTypes(Integer.class, TestValueSingleFieldIndexes.class); assertEquals(1, ccfg.getQueryEntities().size()); QueryEntity ent = (QueryEntity)ccfg.getQueryEntities().iterator().next(); assertEquals(2, ent.getIndexes().size()); for (QueryIndex idx : ent.getIndexes()) { if(idx.getFields().containsKey("val0")) assertEquals(10, idx.getInlineSize()); else if(idx.getFields().containsKey("val1")) assertEquals(20, idx.getInlineSize()); } }
/** * @param tabName Table name. * @return QueryEntity of table. */ private QueryEntity findTableInfo(String tabName) { IgniteEx ignite = grid(0); Collection<String> cacheNames = ignite.cacheNames(); for (String cacheName : cacheNames) { CacheConfiguration ccfg = ignite.cache(cacheName).getConfiguration(CacheConfiguration.class); Collection<QueryEntity> entities = ccfg.getQueryEntities(); for (QueryEntity entity : entities) if (entity.getTableName().equalsIgnoreCase(tabName)) return entity; } return null; }
/** * @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; }
for (QueryEntity e : ccfg.getQueryEntities()) { if (!tblNames.add(e.getTableName())) return new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, e.getTableName());
/** {@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; }
/** {@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; }
/** * Performs scan query with custom transformer (mapper). * * @param cache cache to query. * @param filter filter for rows. * @param transformer result mapper. */ @SuppressWarnings("unchecked") protected static <K, V, R> List<R> select( IgniteCache<K, V> cache, @Nullable IgnitePredicate<Map<String, Object>> filter, IgniteClosure<Map<String, Object>, R> transformer) { Collection<QueryEntity> entities = cache.getConfiguration(CacheConfiguration.class).getQueryEntities(); assert entities.size() == 1 : "Cache should contain exactly one table"; final QueryEntity meta = entities.iterator().next(); IgniteClosure<Cache.Entry<K, V>, R> transformerAdapter = entry -> { Map<String, Object> row = entryToMap(meta, entry.getKey(), entry.getValue()); return transformer.apply(row); }; IgniteBiPredicate<K, V> filterAdapter = (filter == null) ? null : (key, val) -> filter.apply(entryToMap(meta, key, val)); QueryCursor<R> cursor = cache.withKeepBinary() .query(new ScanQuery<>(filterAdapter), transformerAdapter); return cursor.getAll(); }
/** */ @Test public void testDynamicTableCreateNotNullFieldsAllowed() throws Exception { executeSql("CREATE TABLE test(id INT PRIMARY KEY, field INT NOT NULL)"); String cacheName = QueryUtils.createTableCacheName("PUBLIC", "TEST"); IgniteEx client = grid(NODE_CLIENT); CacheConfiguration ccfg = client.context().cache().cache(cacheName).configuration(); QueryEntity qe = (QueryEntity)F.first(ccfg.getQueryEntities()); assertEquals(Collections.singleton("FIELD"), qe.getNotNullFields()); checkState("PUBLIC", "TEST", "FIELD"); }
.setIndexedTypes(Integer.class, City.class).setSqlSchema(QueryUtils.DFLT_SCHEMA); ccfg.getQueryEntities().iterator().next().setKeyFieldName("id");
assertEquals(1, ccfg.getQueryEntities().size()); QueryEntity e = (QueryEntity)ccfg.getQueryEntities().iterator().next();
Collection<QueryEntity> qryEntities = cfg.getQueryEntities();
interceptor = compactClass(ccfg.getInterceptor()); dfltLockTimeout = ccfg.getDefaultLockTimeout(); qryEntities = VisorQueryEntity.list(ccfg.getQueryEntities()); jdbcTypes = VisorCacheJdbcType.list(ccfg.getCacheStoreFactory()); statisticsEnabled = ccfg.isStatisticsEnabled();
Collection<QueryEntity> entities = cfg.getQueryEntities();