use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class PlatformConfigurationUtils method readCacheConfiguration.
/**
* Reads cache configuration from a stream.
*
* @param in Stream.
* @return Cache configuration.
*/
public static CacheConfiguration readCacheConfiguration(BinaryRawReaderEx in) {
assert in != null;
CacheConfiguration ccfg = new CacheConfiguration();
ccfg.setAtomicityMode(CacheAtomicityMode.fromOrdinal(in.readInt()));
ccfg.setBackups(in.readInt());
ccfg.setCacheMode(CacheMode.fromOrdinal(in.readInt()));
ccfg.setCopyOnRead(in.readBoolean());
ccfg.setEagerTtl(in.readBoolean());
ccfg.setInvalidate(in.readBoolean());
ccfg.setStoreKeepBinary(in.readBoolean());
ccfg.setLoadPreviousValue(in.readBoolean());
ccfg.setDefaultLockTimeout(in.readLong());
// noinspection deprecation
ccfg.setLongQueryWarningTimeout(in.readLong());
ccfg.setMaxConcurrentAsyncOperations(in.readInt());
ccfg.setName(in.readString());
ccfg.setReadFromBackup(in.readBoolean());
ccfg.setRebalanceBatchSize(in.readInt());
ccfg.setRebalanceDelay(in.readLong());
ccfg.setRebalanceMode(CacheRebalanceMode.fromOrdinal(in.readInt()));
ccfg.setRebalanceThrottle(in.readLong());
ccfg.setRebalanceTimeout(in.readLong());
ccfg.setSqlEscapeAll(in.readBoolean());
ccfg.setWriteBehindBatchSize(in.readInt());
ccfg.setWriteBehindEnabled(in.readBoolean());
ccfg.setWriteBehindFlushFrequency(in.readLong());
ccfg.setWriteBehindFlushSize(in.readInt());
ccfg.setWriteBehindFlushThreadCount(in.readInt());
ccfg.setWriteBehindCoalescing(in.readBoolean());
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(in.readInt()));
ccfg.setReadThrough(in.readBoolean());
ccfg.setWriteThrough(in.readBoolean());
ccfg.setStatisticsEnabled(in.readBoolean());
String dataRegionName = in.readString();
if (dataRegionName != null)
// noinspection deprecation
ccfg.setMemoryPolicyName(dataRegionName);
ccfg.setPartitionLossPolicy(PartitionLossPolicy.fromOrdinal((byte) in.readInt()));
ccfg.setGroupName(in.readString());
Object storeFactory = in.readObjectDetached();
if (storeFactory != null)
ccfg.setCacheStoreFactory(new PlatformDotNetCacheStoreFactoryNative(storeFactory));
ccfg.setSqlIndexMaxInlineSize(in.readInt());
ccfg.setOnheapCacheEnabled(in.readBoolean());
ccfg.setStoreConcurrentLoadAllThreshold(in.readInt());
ccfg.setRebalanceOrder(in.readInt());
ccfg.setRebalanceBatchesPrefetchCount(in.readLong());
ccfg.setMaxQueryIteratorsCount(in.readInt());
ccfg.setQueryDetailMetricsSize(in.readInt());
ccfg.setQueryParallelism(in.readInt());
ccfg.setSqlSchema(in.readString());
ccfg.setEncryptionEnabled(in.readBoolean());
int qryEntCnt = in.readInt();
if (qryEntCnt > 0) {
Collection<QueryEntity> entities = new ArrayList<>(qryEntCnt);
for (int i = 0; i < qryEntCnt; i++) entities.add(readQueryEntity(in));
ccfg.setQueryEntities(entities);
}
if (in.readBoolean())
ccfg.setNearConfiguration(readNearConfiguration(in));
ccfg.setEvictionPolicy(readEvictionPolicy(in));
if (ccfg.getEvictionPolicy() != null)
ccfg.setOnheapCacheEnabled(true);
ccfg.setAffinity(readAffinityFunction(in));
ccfg.setExpiryPolicyFactory(readExpiryPolicyFactory(in));
ccfg.setNodeFilter(readAttributeNodeFilter(in));
int keyCnt = in.readInt();
if (keyCnt > 0) {
CacheKeyConfiguration[] keys = new CacheKeyConfiguration[keyCnt];
for (int i = 0; i < keyCnt; i++) keys[i] = new CacheKeyConfiguration(in.readString(), in.readString());
ccfg.setKeyConfiguration(keys);
}
if (in.readBoolean())
ccfg.setPlatformCacheConfiguration(readPlatformCacheConfiguration(in));
int pluginCnt = in.readInt();
if (pluginCnt > 0) {
ArrayList<CachePluginConfiguration> plugins = new ArrayList<>();
for (int i = 0; i < pluginCnt; i++) {
if (in.readBoolean()) {
// Java cache plugin.
readCachePluginConfiguration(ccfg, in);
} else {
// Platform cache plugin.
plugins.add(new PlatformCachePluginConfiguration(in.readObjectDetached()));
}
}
if (ccfg.getPluginConfigurations() != null)
Collections.addAll(plugins, ccfg.getPluginConfigurations());
ccfg.setPluginConfigurations(plugins.toArray(new CachePluginConfiguration[plugins.size()]));
}
return ccfg;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class PlatformConfigurationUtils method readQueryEntity.
/**
* Reads the query entity. Version of function to be used from thin client.
*
* @param in Stream.
* @return QueryEntity.
*/
public static QueryEntity readQueryEntity(BinaryRawReader in) {
QueryEntity res = new QueryEntity();
res.setKeyType(in.readString());
res.setValueType(in.readString());
res.setTableName(in.readString());
res.setKeyFieldName(in.readString());
res.setValueFieldName(in.readString());
// Fields
int cnt = in.readInt();
Set<String> keyFields = new HashSet<>(cnt);
Set<String> notNullFields = new HashSet<>(cnt);
Map<String, Object> defVals = new HashMap<>(cnt);
Map<String, Integer> fieldsPrecision = new HashMap<>(cnt);
Map<String, Integer> fieldsScale = new HashMap<>(cnt);
if (cnt > 0) {
LinkedHashMap<String, String> fields = new LinkedHashMap<>(cnt);
for (int i = 0; i < cnt; i++) {
String fieldName = in.readString();
String fieldType = in.readString();
fields.put(fieldName, fieldType);
if (in.readBoolean())
keyFields.add(fieldName);
if (in.readBoolean())
notNullFields.add(fieldName);
Object defVal = in.readObject();
if (defVal != null)
defVals.put(fieldName, defVal);
int precision = in.readInt();
if (precision != -1)
fieldsPrecision.put(fieldName, precision);
int scale = in.readInt();
if (scale != -1)
fieldsScale.put(fieldName, scale);
}
res.setFields(fields);
if (!keyFields.isEmpty())
res.setKeyFields(keyFields);
if (!notNullFields.isEmpty())
res.setNotNullFields(notNullFields);
if (!defVals.isEmpty())
res.setDefaultFieldValues(defVals);
if (!fieldsPrecision.isEmpty())
res.setFieldsPrecision(fieldsPrecision);
if (!fieldsScale.isEmpty())
res.setFieldsScale(fieldsScale);
}
// Aliases
cnt = in.readInt();
if (cnt > 0) {
Map<String, String> aliases = new HashMap<>(cnt);
for (int i = 0; i < cnt; i++) aliases.put(in.readString(), in.readString());
res.setAliases(aliases);
}
// Indexes
cnt = in.readInt();
if (cnt > 0) {
Collection<QueryIndex> indexes = new ArrayList<>(cnt);
for (int i = 0; i < cnt; i++) indexes.add(readQueryIndex(in));
res.setIndexes(indexes);
}
return res;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class JettyRestProcessorAbstractSelfTest method testPutUnregistered.
/**
* Test adding a new (unregistered) binary object.
*
* @throws Exception If failed.
*/
@Test
@SuppressWarnings("ThrowableNotThrown")
public void testPutUnregistered() throws Exception {
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("id", Long.class.getName());
fields.put("name", String.class.getName());
fields.put("timestamp", Timestamp.class.getName());
fields.put("longs", long[].class.getName());
fields.put("igniteUuid", IgniteUuid.class.getName());
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>("testCache");
String valType = "SomeNewType";
ccfg.setQueryEntities(Collections.singletonList(new QueryEntity().setKeyType("java.lang.Integer").setValueType(valType).setFields(fields).setIndexes(Collections.singleton(new QueryIndex("id")))));
IgniteCache cache = grid(0).createCache(ccfg);
try {
List<Integer> list = F.asList(1, 2, 3);
OuterClass newType = new OuterClass(Long.MAX_VALUE, "unregistered", 0.1d, list, Timestamp.valueOf("2004-08-26 16:47:03.141592"), new long[] { Long.MAX_VALUE, -1, Long.MAX_VALUE }, UUID.randomUUID(), IgniteUuid.randomUuid(), null);
putObject(cache.getName(), "300", newType, valType);
GridTestUtils.assertThrowsWithCause(() -> cache.get(300), ClassNotFoundException.class);
assertEquals(newType, getObject(cache.getName(), "300", OuterClass.class));
// Sending "optional" (new) field for registered binary type.
OuterClass newTypeUpdate = new OuterClass(-1, "update", 0.7d, list, Timestamp.valueOf("2004-08-26 16:47:03.14"), new long[] { Long.MAX_VALUE, 0, Long.MAX_VALUE }, UUID.randomUUID(), IgniteUuid.randomUuid(), new OuterClass.OptionalObject("test"));
putObject(cache.getName(), "301", newTypeUpdate, valType);
assertEquals(newTypeUpdate, getObject(cache.getName(), "301", OuterClass.class));
// Check query result.
JsonNode res = queryObject(cache.getName(), GridRestCommand.EXECUTE_SQL_QUERY, "type", valType, "pageSize", "1", "keepBinary", "true", "qry", "timestamp < ?", "arg1", "2004-08-26 16:47:03.141");
assertEquals(newTypeUpdate, JSON_MAPPER.treeToValue(res, OuterClass.class));
// Check fields query result.
String qry = "select id, name, timestamp, igniteUuid, longs from " + valType + " where timestamp < '2004-08-26 16:47:03.141'";
res = queryObject(cache.getName(), GridRestCommand.EXECUTE_SQL_FIELDS_QUERY, "keepBinary", "true", "pageSize", "10", "qry", qry);
assertEquals(5, res.size());
assertEquals(newTypeUpdate.id, res.get(0).longValue());
assertEquals(newTypeUpdate.name, res.get(1).textValue());
assertEquals(newTypeUpdate.timestamp, Timestamp.valueOf(res.get(2).textValue()));
assertEquals(newTypeUpdate.igniteUuid, IgniteUuid.fromString(res.get(3).textValue()));
assertTrue(Arrays.equals(newTypeUpdate.longs, JSON_MAPPER.treeToValue(res.get(4), long[].class)));
} finally {
grid(0).destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class GridCommandHandlerIndexingCheckSizeTest method queryEntities.
/**
* Creating {@link QueryEntity}'s with filling functions.
*
* @return {@link QueryEntity}'s with filling functions.
*/
private Map<QueryEntity, Function<Random, Object>> queryEntities() {
Map<QueryEntity, Function<Random, Object>> qryEntities = new HashMap<>();
qryEntities.put(personEntity(), rand -> new Person(rand.nextInt(), valueOf(rand.nextLong())));
qryEntities.put(organizationEntity(), rand -> new Organization(rand.nextInt(), valueOf(rand.nextLong())));
return qryEntities;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class FunctionalTest method testCacheConfiguration.
/**
* Tested API:
* <ul>
* <li>{@link ClientCache#getName()}</li>
* <li>{@link ClientCache#getConfiguration()}</li>
* </ul>
*/
@Test
public void testCacheConfiguration() throws Exception {
final String dataRegionName = "functional-test-data-region";
IgniteConfiguration cfg = Config.getServerConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setName(dataRegionName)));
try (Ignite ignored = Ignition.start(cfg);
IgniteClient client = Ignition.startClient(getClientConfiguration())) {
final String CACHE_NAME = "testCacheConfiguration";
ClientCacheConfiguration cacheCfgTemplate = new ClientCacheConfiguration().setName(CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setBackups(3).setCacheMode(CacheMode.PARTITIONED).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setEagerTtl(false).setGroupName("FunctionalTest").setDefaultLockTimeout(12345).setPartitionLossPolicy(PartitionLossPolicy.READ_WRITE_SAFE).setReadFromBackup(true).setRebalanceBatchSize(67890).setRebalanceBatchesPrefetchCount(102938).setRebalanceDelay(54321).setRebalanceMode(CacheRebalanceMode.SYNC).setRebalanceOrder(2).setRebalanceThrottle(564738).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()), new SimpleEntry<>("orgId", Integer.class.getName())).collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new))).setKeyFields(Collections.emptySet()).setKeyFieldName("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)))).setExpiryPolicy(new PlatformExpiryPolicy(10, 20, 30)).setCopyOnRead(!CacheConfiguration.DFLT_COPY_ON_READ).setDataRegionName(dataRegionName).setMaxConcurrentAsyncOperations(4).setMaxQueryIteratorsCount(4).setOnheapCacheEnabled(true).setQueryDetailMetricsSize(1024).setQueryParallelism(4).setSqlEscapeAll(true).setSqlIndexMaxInlineSize(1024).setSqlSchema("functional-test-schema").setStatisticsEnabled(true);
ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration(cacheCfgTemplate);
ClientCache<Object, Object> cache = client.createCache(cacheCfg);
assertEquals(CACHE_NAME, cache.getName());
assertTrue(Comparers.equal(cacheCfgTemplate, cache.getConfiguration()));
}
}
Aggregations