use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class GridCommandHandlerIndexingUtils method complexIndexEntity.
/**
* Adds three indexes one of which is built on two fields
* to {@code QueryEntity} provided by {@code prepareQueryEntity()}.
*
* @return {@code QueryEntity} with indexes.
*/
static QueryEntity complexIndexEntity() {
QueryEntity entity = prepareQueryEntity();
entity.setIndexes(asList(new QueryIndex(ID_NAME), new QueryIndex(STR_NAME), new QueryIndex(asList(STR_NAME, DOUBLE_NAME), QueryIndexType.SORTED)));
return entity;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class GridCommandHandlerInterruptCommandTest method createQueryEntity.
/**
* Creates predifened query entity.
*
* @return Query entity.
*/
private QueryEntity createQueryEntity() {
QueryEntity qryEntity = new QueryEntity();
qryEntity.setKeyType(Integer.class.getTypeName());
qryEntity.setValueType(UserValue.class.getName());
qryEntity.setTableName("USER_TEST_TABLE");
LinkedHashMap<String, String> fields = new LinkedHashMap<>();
fields.put("x", "java.lang.Integer");
fields.put("y", "java.lang.Integer");
fields.put("z", "java.lang.Integer");
qryEntity.setFields(fields);
LinkedHashMap<String, Boolean> idxFields = new LinkedHashMap<>();
QueryIndex idx2 = new QueryIndex();
idx2.setName("IDX_2");
idx2.setIndexType(QueryIndexType.SORTED);
idxFields = new LinkedHashMap<>();
idxFields.put("x", false);
idx2.setFields(idxFields);
QueryIndex idx3 = new QueryIndex();
idx3.setName("IDX_3");
idx3.setIndexType(QueryIndexType.SORTED);
idxFields = new LinkedHashMap<>();
idxFields.put("y", false);
idx3.setFields(idxFields);
QueryIndex idx4 = new QueryIndex();
idx4.setName("IDX_4");
idx4.setIndexType(QueryIndexType.SORTED);
idxFields = new LinkedHashMap<>();
idxFields.put("z", false);
idx4.setFields(idxFields);
qryEntity.setIndexes(Arrays.asList(idx2, idx3, idx4));
return qryEntity;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class ClientCacheConfigurationSerializer method write.
/**
* Writes the cache configuration.
* @param writer Writer.
* @param cfg Configuration.
* @param protocolCtx Client protocol context.
*/
static void write(BinaryRawWriterEx writer, CacheConfiguration cfg, ClientProtocolContext protocolCtx) {
assert writer != null;
assert cfg != null;
// Reserve for length.
int pos = writer.reserveInt();
PlatformConfigurationUtils.writeEnumInt(writer, cfg.getAtomicityMode(), CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE);
writer.writeInt(cfg.getBackups());
PlatformConfigurationUtils.writeEnumInt(writer, cfg.getCacheMode(), CacheConfiguration.DFLT_CACHE_MODE);
writer.writeBoolean(cfg.isCopyOnRead());
writer.writeString(cfg.getDataRegionName());
writer.writeBoolean(cfg.isEagerTtl());
writer.writeBoolean(cfg.isStatisticsEnabled());
writer.writeString(cfg.getGroupName());
writer.writeLong(cfg.getDefaultLockTimeout());
writer.writeInt(cfg.getMaxConcurrentAsyncOperations());
writer.writeInt(cfg.getMaxQueryIteratorsCount());
writer.writeString(cfg.getName());
writer.writeBoolean(cfg.isOnheapCacheEnabled());
writer.writeInt(cfg.getPartitionLossPolicy().ordinal());
writer.writeInt(cfg.getQueryDetailMetricsSize());
writer.writeInt(cfg.getQueryParallelism());
writer.writeBoolean(cfg.isReadFromBackup());
writer.writeInt(cfg.getRebalanceBatchSize());
writer.writeLong(cfg.getRebalanceBatchesPrefetchCount());
writer.writeLong(cfg.getRebalanceDelay());
PlatformConfigurationUtils.writeEnumInt(writer, cfg.getRebalanceMode(), CacheConfiguration.DFLT_REBALANCE_MODE);
writer.writeInt(cfg.getRebalanceOrder());
writer.writeLong(cfg.getRebalanceThrottle());
writer.writeLong(cfg.getRebalanceTimeout());
writer.writeBoolean(cfg.isSqlEscapeAll());
writer.writeInt(cfg.getSqlIndexMaxInlineSize());
writer.writeString(cfg.getSqlSchema());
PlatformConfigurationUtils.writeEnumInt(writer, cfg.getWriteSynchronizationMode());
CacheKeyConfiguration[] keys = cfg.getKeyConfiguration();
if (keys != null) {
writer.writeInt(keys.length);
for (CacheKeyConfiguration key : keys) {
writer.writeString(key.getTypeName());
writer.writeString(key.getAffinityKeyFieldName());
}
} else {
writer.writeInt(0);
}
// noinspection unchecked
Collection<QueryEntity> qryEntities = cfg.getQueryEntities();
if (qryEntities != null) {
writer.writeInt(qryEntities.size());
for (QueryEntity e : qryEntities) writeQueryEntity(writer, e, protocolCtx);
} else
writer.writeInt(0);
if (protocolCtx.isFeatureSupported(ClientProtocolVersionFeature.EXPIRY_POLICY))
PlatformConfigurationUtils.writeExpiryPolicyFactory(writer, cfg.getExpiryPolicyFactory());
// Write length (so that part of the config can be skipped).
writer.writeInt(pos, writer.out().position() - pos - 4);
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class ClientCacheConfigurationSerializer method readQueryEntity.
/**
* Reads the query entity. Version of function to be used from thin client.
*
* @param in Stream.
* @param protocolCtx Client protocol version.
* @return QueryEntity.
*/
public static QueryEntity readQueryEntity(BinaryRawReader in, ClientProtocolContext protocolCtx) {
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);
if (protocolCtx.isFeatureSupported(QUERY_ENTITY_PRECISION_AND_SCALE)) {
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(PlatformConfigurationUtils.readQueryIndex(in));
res.setIndexes(indexes);
}
return res;
}
use of org.apache.ignite.cache.QueryEntity in project ignite by apache.
the class PlatformConfigurationUtils method writeCacheConfiguration.
/**
* Writes cache configuration.
*
* @param writer Writer.
* @param ccfg Configuration.
*/
public static void writeCacheConfiguration(BinaryRawWriter writer, CacheConfiguration ccfg) {
assert writer != null;
assert ccfg != null;
writeEnumInt(writer, ccfg.getAtomicityMode(), CacheConfiguration.DFLT_CACHE_ATOMICITY_MODE);
writer.writeInt(ccfg.getBackups());
writeEnumInt(writer, ccfg.getCacheMode(), CacheConfiguration.DFLT_CACHE_MODE);
writer.writeBoolean(ccfg.isCopyOnRead());
writer.writeBoolean(ccfg.isEagerTtl());
writer.writeBoolean(ccfg.isInvalidate());
writer.writeBoolean(ccfg.isStoreKeepBinary());
writer.writeBoolean(ccfg.isLoadPreviousValue());
writer.writeLong(ccfg.getDefaultLockTimeout());
// noinspection deprecation
writer.writeLong(ccfg.getLongQueryWarningTimeout());
writer.writeInt(ccfg.getMaxConcurrentAsyncOperations());
writer.writeString(ccfg.getName());
writer.writeBoolean(ccfg.isReadFromBackup());
writer.writeInt(ccfg.getRebalanceBatchSize());
writer.writeLong(ccfg.getRebalanceDelay());
writeEnumInt(writer, ccfg.getRebalanceMode(), CacheConfiguration.DFLT_REBALANCE_MODE);
writer.writeLong(ccfg.getRebalanceThrottle());
writer.writeLong(ccfg.getRebalanceTimeout());
writer.writeBoolean(ccfg.isSqlEscapeAll());
writer.writeInt(ccfg.getWriteBehindBatchSize());
writer.writeBoolean(ccfg.isWriteBehindEnabled());
writer.writeLong(ccfg.getWriteBehindFlushFrequency());
writer.writeInt(ccfg.getWriteBehindFlushSize());
writer.writeInt(ccfg.getWriteBehindFlushThreadCount());
writer.writeBoolean(ccfg.getWriteBehindCoalescing());
writeEnumInt(writer, ccfg.getWriteSynchronizationMode());
writer.writeBoolean(ccfg.isReadThrough());
writer.writeBoolean(ccfg.isWriteThrough());
writer.writeBoolean(ccfg.isStatisticsEnabled());
// noinspection deprecation
writer.writeString(ccfg.getMemoryPolicyName());
writer.writeInt(ccfg.getPartitionLossPolicy().ordinal());
writer.writeString(ccfg.getGroupName());
if (ccfg.getCacheStoreFactory() instanceof PlatformDotNetCacheStoreFactoryNative)
writer.writeObject(((PlatformDotNetCacheStoreFactoryNative) ccfg.getCacheStoreFactory()).getNativeFactory());
else
writer.writeObject(null);
writer.writeInt(ccfg.getSqlIndexMaxInlineSize());
writer.writeBoolean(ccfg.isOnheapCacheEnabled());
writer.writeInt(ccfg.getStoreConcurrentLoadAllThreshold());
writer.writeInt(ccfg.getRebalanceOrder());
writer.writeLong(ccfg.getRebalanceBatchesPrefetchCount());
writer.writeInt(ccfg.getMaxQueryIteratorsCount());
writer.writeInt(ccfg.getQueryDetailMetricsSize());
writer.writeInt(ccfg.getQueryParallelism());
writer.writeString(ccfg.getSqlSchema());
writer.writeBoolean(ccfg.isEncryptionEnabled());
Collection<QueryEntity> qryEntities = ccfg.getQueryEntities();
if (qryEntities != null) {
writer.writeInt(qryEntities.size());
for (QueryEntity e : qryEntities) writeQueryEntity(writer, e);
} else
writer.writeInt(0);
NearCacheConfiguration nearCfg = ccfg.getNearConfiguration();
if (nearCfg != null) {
writer.writeBoolean(true);
writeNearConfiguration(writer, nearCfg);
} else
writer.writeBoolean(false);
writeEvictionPolicy(writer, ccfg.getEvictionPolicy());
writeAffinityFunction(writer, ccfg.getAffinity());
writeExpiryPolicyFactory(writer, ccfg.getExpiryPolicyFactory());
writeAttributeNodeFilter(writer, ccfg.getNodeFilter());
CacheKeyConfiguration[] keys = ccfg.getKeyConfiguration();
if (keys != null) {
writer.writeInt(keys.length);
for (CacheKeyConfiguration key : keys) {
writer.writeString(key.getTypeName());
writer.writeString(key.getAffinityKeyFieldName());
}
} else {
writer.writeInt(0);
}
PlatformCacheConfiguration platCfg = ccfg.getPlatformCacheConfiguration();
if (platCfg != null) {
writer.writeBoolean(true);
writer.writeString(platCfg.getKeyTypeName());
writer.writeString(platCfg.getValueTypeName());
writer.writeBoolean(platCfg.isKeepBinary());
} else {
writer.writeBoolean(false);
}
CachePluginConfiguration[] plugins = ccfg.getPluginConfigurations();
if (plugins != null) {
int cnt = 0;
for (CachePluginConfiguration cfg : plugins) {
if (cfg instanceof PlatformCachePluginConfiguration)
cnt++;
}
writer.writeInt(cnt);
for (CachePluginConfiguration cfg : plugins) {
if (cfg instanceof PlatformCachePluginConfiguration) {
// Pure platform plugin.
writer.writeBoolean(false);
writer.writeObject(((PlatformCachePluginConfiguration) cfg).nativeCfg());
}
}
}
}
Aggregations