Search in sources :

Example 21 with QueryEntity

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;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 22 with QueryEntity

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;
}
Also used : QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with QueryEntity

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);
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity)

Example 24 with QueryEntity

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap) QueryIndex(org.apache.ignite.cache.QueryIndex) HashSet(java.util.HashSet)

Example 25 with QueryEntity

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());
            }
        }
    }
}
Also used : PlatformDotNetCacheStoreFactoryNative(org.apache.ignite.platform.dotnet.PlatformDotNetCacheStoreFactoryNative) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) PlatformCachePluginConfiguration(org.apache.ignite.internal.processors.platform.plugin.cache.PlatformCachePluginConfiguration) CachePluginConfiguration(org.apache.ignite.plugin.CachePluginConfiguration) PlatformCachePluginConfiguration(org.apache.ignite.internal.processors.platform.plugin.cache.PlatformCachePluginConfiguration) PlatformCacheConfiguration(org.apache.ignite.configuration.PlatformCacheConfiguration) QueryEntity(org.apache.ignite.cache.QueryEntity) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Aggregations

QueryEntity (org.apache.ignite.cache.QueryEntity)221 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)115 QueryIndex (org.apache.ignite.cache.QueryIndex)87 LinkedHashMap (java.util.LinkedHashMap)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)42 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)41 HashMap (java.util.HashMap)27 HashSet (java.util.HashSet)22 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)21 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)21 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)19 List (java.util.List)18 Ignite (org.apache.ignite.Ignite)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)13 Map (java.util.Map)12 BinaryObject (org.apache.ignite.binary.BinaryObject)12 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)12