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;
}
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());
}
}
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;
}
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);
}
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);
}
Aggregations