use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class ClientCacheConfigurationSerializer method read.
/**
* Reads the cache configuration.
*
* @param reader Reader.
* @param protocolCtx Client protocol context.
* @return Configuration.
*/
static CacheConfiguration read(BinaryRawReader reader, ClientProtocolContext protocolCtx) {
// Skip length.
reader.readInt();
short propCnt = reader.readShort();
CacheConfiguration cfg = new CacheConfiguration();
for (int i = 0; i < propCnt; i++) {
short code = reader.readShort();
switch(code) {
case ATOMICITY_MODE:
cfg.setAtomicityMode(CacheAtomicityMode.fromOrdinal(reader.readInt()));
break;
case BACKUPS:
cfg.setBackups(reader.readInt());
break;
case CACHE_MODE:
cfg.setCacheMode(CacheMode.fromOrdinal(reader.readInt()));
break;
case COPY_ON_READ:
cfg.setCopyOnRead(reader.readBoolean());
break;
case DATA_REGION_NAME:
cfg.setDataRegionName(reader.readString());
break;
case EAGER_TTL:
cfg.setEagerTtl(reader.readBoolean());
break;
case EXPIRY_POLICY:
cfg.setExpiryPolicyFactory(PlatformConfigurationUtils.readExpiryPolicyFactory(reader));
break;
case STATISTICS_ENABLED:
cfg.setStatisticsEnabled(reader.readBoolean());
break;
case GROUP_NAME:
cfg.setGroupName(reader.readString());
break;
case DEFAULT_LOCK_TIMEOUT:
cfg.setDefaultLockTimeout(reader.readLong());
break;
case MAX_CONCURRENT_ASYNC_OPERATIONS:
cfg.setMaxConcurrentAsyncOperations(reader.readInt());
break;
case MAX_QUERY_ITERATORS_COUNT:
cfg.setMaxQueryIteratorsCount(reader.readInt());
break;
case NAME:
cfg.setName(reader.readString());
break;
case ONHEAP_CACHE_ENABLED:
cfg.setOnheapCacheEnabled(reader.readBoolean());
break;
case PARTITION_LOSS_POLICY:
cfg.setPartitionLossPolicy(PartitionLossPolicy.fromOrdinal((byte) reader.readInt()));
break;
case QUERY_DETAIL_METRICS_SIZE:
cfg.setQueryDetailMetricsSize(reader.readInt());
break;
case QUERY_PARALLELISM:
cfg.setQueryParallelism(reader.readInt());
break;
case READ_FROM_BACKUP:
cfg.setReadFromBackup(reader.readBoolean());
break;
case REBALANCE_BATCH_SIZE:
cfg.setRebalanceBatchSize(reader.readInt());
break;
case REBALANCE_BATCHES_PREFETCH_COUNT:
cfg.setRebalanceBatchesPrefetchCount(reader.readLong());
break;
case REBALANCE_DELAY:
cfg.setRebalanceDelay(reader.readLong());
break;
case REBALANCE_MODE:
cfg.setRebalanceMode(CacheRebalanceMode.fromOrdinal(reader.readInt()));
break;
case REBALANCE_ORDER:
cfg.setRebalanceOrder(reader.readInt());
break;
case REBALANCE_THROTTLE:
cfg.setRebalanceThrottle(reader.readLong());
break;
case REBALANCE_TIMEOUT:
cfg.setRebalanceTimeout(reader.readLong());
break;
case SQL_ESCAPE_ALL:
cfg.setSqlEscapeAll(reader.readBoolean());
break;
case SQL_INDEX_MAX_INLINE_SIZE:
cfg.setSqlIndexMaxInlineSize(reader.readInt());
break;
case SQL_SCHEMA:
cfg.setSqlSchema(reader.readString());
break;
case WRITE_SYNCHRONIZATION_MODE:
cfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(reader.readInt()));
break;
case KEY_CONFIGURATION:
int keyCnt = reader.readInt();
if (keyCnt > 0) {
CacheKeyConfiguration[] keys = new CacheKeyConfiguration[keyCnt];
for (int j = 0; j < keyCnt; j++) {
keys[j] = new CacheKeyConfiguration(reader.readString(), reader.readString());
}
cfg.setKeyConfiguration(keys);
}
break;
case QUERY_ENTITIES:
int qryEntCnt = reader.readInt();
if (qryEntCnt > 0) {
Collection<QueryEntity> entities = new ArrayList<>(qryEntCnt);
for (int j = 0; j < qryEntCnt; j++) entities.add(readQueryEntity(reader, protocolCtx));
cfg.setQueryEntities(entities);
}
break;
}
}
return cfg;
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class AffinityCollocationExample method configureAffinityKeyWithCacheKeyConfiguration.
// end::affinity-key-class[]
// tag::config-with-key-configuration[]
public void configureAffinityKeyWithCacheKeyConfiguration() {
CacheConfiguration<PersonKey, Person> personCfg = new CacheConfiguration<PersonKey, Person>("persons");
personCfg.setBackups(1);
// Configure the affinity key
personCfg.setKeyConfiguration(new CacheKeyConfiguration("Person", "companyId"));
CacheConfiguration<String, Company> companyCfg = new CacheConfiguration<String, Company>("companies");
companyCfg.setBackups(1);
Ignite ignite = Ignition.start();
IgniteCache<PersonKey, Person> personCache = ignite.getOrCreateCache(personCfg);
IgniteCache<String, Company> companyCache = ignite.getOrCreateCache(companyCfg);
Company c1 = new Company("company1", "My company");
Person p1 = new Person(1, c1.getId(), "John");
// Both the p1 and c1 objects will be cached on the same node
personCache.put(new PersonKey(1, c1.getId()), p1);
companyCache.put(c1.getId(), c1);
// Get the person object
p1 = personCache.get(new PersonKey(1, "company1"));
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class GridCacheClientNodeBinaryObjectMetadataTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
BinaryMarshaller marsh = new BinaryMarshaller();
BinaryConfiguration bCfg = new BinaryConfiguration();
bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setTypeName(TestObject1.class.getName());
CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject1.class.getName(), "val2");
cfg.setCacheKeyConfiguration(keyCfg);
bCfg.setTypeConfigurations(Arrays.asList(typeCfg));
cfg.setBinaryConfiguration(bCfg);
if (igniteInstanceName.equals(getTestIgniteInstanceName(gridCount() - 1)))
cfg.setClientMode(true);
cfg.setMarshaller(marsh);
((TcpDiscoverySpi) cfg.getDiscoverySpi()).setForceServerMode(true);
return cfg;
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class GridCacheAffinityRoutingBinarySelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setTypeName(AffinityTestKey.class.getName());
CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey");
cfg.setCacheKeyConfiguration(keyCfg);
BinaryConfiguration bCfg = new BinaryConfiguration();
bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
cfg.setBinaryConfiguration(bCfg);
cfg.setMarshaller(new BinaryMarshaller());
return cfg;
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class GridQueryProcessor method dynamicTableCreate.
/**
* Create cache and table from given query entity.
*
* @param schemaName Schema name to create table in. Case sensitive, must not be \"quoted\".
* @param entity Entity to create table from.
* @param templateName Template name.
* @param cacheName Cache name.
* @param cacheGroup Cache group name.
* @param dataRegion Data region name.
* @param affinityKey Affinity key column name.
* @param atomicityMode Atomicity mode.
* @param writeSyncMode Write synchronization mode.
* @param backups Backups.
* @param ifNotExists Quietly ignore this command if table already exists.
* @param encrypted Encrypted flag.
* @param qryParallelism query parallelism value for configuration of underlying cache.
* @throws IgniteCheckedException If failed.
*/
public void dynamicTableCreate(String schemaName, QueryEntity entity, String templateName, String cacheName, String cacheGroup, @Nullable String dataRegion, String affinityKey, @Nullable CacheAtomicityMode atomicityMode, @Nullable CacheWriteSynchronizationMode writeSyncMode, @Nullable Integer backups, boolean ifNotExists, @Nullable Boolean encrypted, @Nullable Integer qryParallelism) throws IgniteCheckedException {
assert !F.isEmpty(templateName);
assert backups == null || backups >= 0;
assert qryParallelism == null || qryParallelism > 0;
CacheConfiguration<?, ?> ccfg = ctx.cache().getConfigFromTemplate(templateName);
if (ccfg == null) {
if (QueryUtils.TEMPLATE_PARTITIONED.equalsIgnoreCase(templateName))
ccfg = new CacheConfiguration<>().setCacheMode(CacheMode.PARTITIONED);
else if (QueryUtils.TEMPLATE_REPLICATED.equalsIgnoreCase(templateName))
ccfg = new CacheConfiguration<>().setCacheMode(CacheMode.REPLICATED);
else
throw new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, templateName);
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
}
if (!F.isEmpty(ccfg.getQueryEntities()))
throw new SchemaOperationException("Template cache already contains query entities which it should not: " + templateName);
if (!F.isEmpty(entity.getNotNullFields()))
QueryUtils.checkNotNullAllowed(ccfg);
if (F.isEmpty(cacheName))
cacheName = QueryUtils.createTableCacheName(schemaName, entity.getTableName());
ccfg.setName(cacheName);
if (!F.isEmpty(cacheGroup))
ccfg.setGroupName(cacheGroup);
if (!F.isEmpty(dataRegion))
ccfg.setDataRegionName(dataRegion);
if (atomicityMode != null)
ccfg.setAtomicityMode(atomicityMode);
if (writeSyncMode != null)
ccfg.setWriteSynchronizationMode(writeSyncMode);
if (backups != null)
ccfg.setBackups(backups);
if (qryParallelism != null)
ccfg.setQueryParallelism(qryParallelism);
if (encrypted != null)
ccfg.setEncryptionEnabled(encrypted);
ccfg.setSqlSchema("\"" + schemaName + "\"");
ccfg.setSqlEscapeAll(true);
ccfg.setQueryEntities(Collections.singleton(entity));
if (!QueryUtils.isCustomAffinityMapper(ccfg.getAffinityMapper()))
ccfg.setAffinityMapper(null);
if (affinityKey != null)
ccfg.setKeyConfiguration(new CacheKeyConfiguration(entity.getKeyType(), affinityKey));
boolean res;
try {
res = ctx.grid().getOrCreateCache0(ccfg, true).get2();
} catch (CacheException e) {
if (e.getCause() instanceof SchemaOperationException)
throw (SchemaOperationException) e.getCause();
else
throw e;
}
if (!res && !ifNotExists)
throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_EXISTS, entity.getTableName());
}
Aggregations