Search in sources :

Example 1 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class IgniteSqlSegmentedIndexSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    CacheKeyConfiguration keyCfg = new CacheKeyConfiguration("MyCache", "affKey");
    cfg.setCacheKeyConfiguration(keyCfg);
    cfg.setPeerClassLoadingEnabled(false);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(disco);
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 2 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class BinaryContext method configure.

/**
 * @param globalIdMapper ID mapper.
 * @param globalSerializer Serializer.
 * @param typeCfgs Type configurations.
 * @throws BinaryObjectException In case of error.
 */
private void configure(BinaryNameMapper globalNameMapper, BinaryIdMapper globalIdMapper, BinarySerializer globalSerializer, Collection<BinaryTypeConfiguration> typeCfgs) throws BinaryObjectException {
    TypeDescriptors descs = new TypeDescriptors();
    Map<String, String> affFields = new HashMap<>();
    if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
        for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration()) affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
    }
    if (typeCfgs != null) {
        for (BinaryTypeConfiguration typeCfg : typeCfgs) {
            String clsName = typeCfg.getTypeName();
            if (clsName == null)
                throw new BinaryObjectException("Class name is required for binary type configuration.");
            // Resolve mapper.
            BinaryIdMapper idMapper = U.firstNotNull(typeCfg.getIdMapper(), globalIdMapper);
            BinaryNameMapper nameMapper = U.firstNotNull(typeCfg.getNameMapper(), globalNameMapper);
            BinarySerializer serializer = U.firstNotNull(typeCfg.getSerializer(), globalSerializer);
            BinaryIdentityResolver identity = BinaryArrayIdentityResolver.instance();
            BinaryInternalMapper mapper = resolveMapper(nameMapper, idMapper);
            if (clsName.endsWith(".*")) {
                String pkgName = clsName.substring(0, clsName.length() - 2);
                for (String clsName0 : classesInPackage(pkgName)) {
                    String affField = affFields.remove(clsName0);
                    descs.add(clsName0, mapper, serializer, identity, affField, typeCfg.isEnum(), typeCfg.getEnumValues(), true);
                }
            } else {
                String affField = affFields.remove(clsName);
                descs.add(clsName, mapper, serializer, identity, affField, typeCfg.isEnum(), typeCfg.getEnumValues(), false);
            }
        }
    }
    for (TypeDescriptor desc : descs.descriptors()) registerUserType(desc.clsName, desc.mapper, desc.serializer, desc.identity, desc.affKeyFieldName, desc.isEnum, desc.enumMap);
    BinaryInternalMapper globalMapper = resolveMapper(globalNameMapper, globalIdMapper);
    // Put affinity field names for unconfigured types.
    for (Map.Entry<String, String> entry : affFields.entrySet()) {
        String typeName = entry.getKey();
        int typeId = globalMapper.typeId(typeName);
        affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
    }
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryNameMapper(org.apache.ignite.binary.BinaryNameMapper) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) BinarySerializer(org.apache.ignite.binary.BinarySerializer)

Example 3 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class GridCacheBinaryObjectsAbstractSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration cacheCfg = createCacheConfig();
    cacheCfg.setCacheStoreFactory(singletonFactory(new TestStore()));
    CacheConfiguration binKeysCacheCfg = createCacheConfig();
    binKeysCacheCfg.setCacheStoreFactory(singletonFactory(new MapCacheStoreStrategy.MapCacheStore()));
    binKeysCacheCfg.setStoreKeepBinary(true);
    binKeysCacheCfg.setName("BinKeysCache");
    cfg.setCacheConfiguration(cacheCfg, binKeysCacheCfg);
    cfg.setMarshaller(new BinaryMarshaller());
    List<BinaryTypeConfiguration> binTypes = new ArrayList<>();
    binTypes.add(new BinaryTypeConfiguration() {

        {
            setTypeName("ArrayHashedKey");
        }
    });
    BinaryConfiguration binCfg = new BinaryConfiguration();
    binCfg.setTypeConfigurations(binTypes);
    cfg.setBinaryConfiguration(binCfg);
    CacheKeyConfiguration arrayHashCfg = new CacheKeyConfiguration("ArrayHashedKey", "fld1");
    cfg.setCacheKeyConfiguration(arrayHashCfg);
    GridCacheBinaryObjectsAbstractSelfTest.cfg = cfg;
    return cfg;
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) ArrayList(java.util.ArrayList) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 4 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration 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 5 with CacheKeyConfiguration

use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.

the class ClientCachePartitionAwarenessGroup method write.

/**
 * Write mapping using binary writer.
 * @param writer Writer.
 */
public void write(BinaryRawWriter writer) {
    writer.writeBoolean(mapping != null);
    writer.writeInt(cacheCfgs.size());
    for (Map.Entry<Integer, CacheConfiguration> entry : cacheCfgs.entrySet()) {
        writer.writeInt(entry.getKey());
        if (mapping == null)
            continue;
        CacheConfiguration ccfg = entry.getValue();
        CacheKeyConfiguration[] keyCfgs = ccfg.getKeyConfiguration();
        if (keyCfgs == null) {
            writer.writeInt(0);
            continue;
        }
        writer.writeInt(keyCfgs.length);
        for (CacheKeyConfiguration keyCfg : keyCfgs) {
            int keyTypeId = proc.typeId(keyCfg.getTypeName());
            int affinityKeyFieldId = proc.binaryContext().fieldId(keyTypeId, keyCfg.getAffinityKeyFieldName());
            writer.writeInt(keyTypeId);
            writer.writeInt(affinityKeyFieldId);
        }
    }
    if (mapping != null)
        mapping.write(writer);
}
Also used : CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)41 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)24 QueryEntity (org.apache.ignite.cache.QueryEntity)19 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)17 ArrayList (java.util.ArrayList)11 LinkedHashMap (java.util.LinkedHashMap)7 QueryIndex (org.apache.ignite.cache.QueryIndex)7 Ignite (org.apache.ignite.Ignite)6 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)6 HashMap (java.util.HashMap)5 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)5 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)4 SimpleEntry (java.util.AbstractMap.SimpleEntry)3 Collectors (java.util.stream.Collectors)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)3 CacheMode (org.apache.ignite.cache.CacheMode)3 CacheRebalanceMode (org.apache.ignite.cache.CacheRebalanceMode)3