use of org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper in project ignite by apache.
the class QueryUtils method typeForQueryEntity.
/**
* Create type candidate for query entity.
*
* @param cacheName Cache name.
* @param schemaName Schema name.
* @param cctx Cache context.
* @param qryEntity Query entity.
* @param mustDeserializeClss Classes which must be deserialized.
* @param escape Escape flag.
* @return Type candidate.
* @throws IgniteCheckedException If failed.
*/
public static QueryTypeCandidate typeForQueryEntity(String cacheName, String schemaName, GridCacheContext cctx, QueryEntity qryEntity, List<Class<?>> mustDeserializeClss, boolean escape) throws IgniteCheckedException {
GridKernalContext ctx = cctx.kernalContext();
CacheConfiguration<?, ?> ccfg = cctx.config();
boolean binaryEnabled = ctx.cacheObjects().isBinaryEnabled(ccfg);
CacheObjectContext coCtx = binaryEnabled ? ctx.cacheObjects().contextForCache(ccfg) : null;
QueryTypeDescriptorImpl desc = new QueryTypeDescriptorImpl(cacheName);
desc.schemaName(schemaName);
desc.aliases(qryEntity.getAliases());
// Key and value classes still can be available if they are primitive or JDK part.
// We need that to set correct types for _key and _val columns.
// We better box these types - otherwise, if user provides, say, raw 'byte' for
// key or value (which they could), we'll deem key or value as Object which clearly is not right.
Class<?> keyCls = U.box(U.classForName(qryEntity.findKeyType(), null, true));
Class<?> valCls = U.box(U.classForName(qryEntity.findValueType(), null, true));
// If local node has the classes and they are externalizable, we must use reflection properties.
boolean keyMustDeserialize = mustDeserializeBinary(ctx, keyCls);
boolean valMustDeserialize = mustDeserializeBinary(ctx, valCls);
boolean keyOrValMustDeserialize = keyMustDeserialize || valMustDeserialize;
if (keyCls == null)
keyCls = Object.class;
String simpleValType = ((valCls == null) ? typeName(qryEntity.findValueType()) : typeName(valCls));
desc.name(simpleValType);
desc.tableName(qryEntity.getTableName());
if (binaryEnabled && !keyOrValMustDeserialize) {
// Safe to check null.
if (SQL_TYPES.contains(valCls))
desc.valueClass(valCls);
else
desc.valueClass(Object.class);
if (SQL_TYPES.contains(keyCls))
desc.keyClass(keyCls);
else
desc.keyClass(Object.class);
} else {
if (valCls == null)
throw new IgniteCheckedException("Failed to find value class in the node classpath " + "(use default marshaller to enable binary objects) : " + qryEntity.findValueType());
desc.valueClass(valCls);
desc.keyClass(keyCls);
}
desc.keyTypeName(qryEntity.findKeyType());
desc.valueTypeName(qryEntity.findValueType());
desc.keyFieldName(qryEntity.getKeyFieldName());
desc.valueFieldName(qryEntity.getValueFieldName());
if (binaryEnabled && keyOrValMustDeserialize) {
if (keyMustDeserialize)
mustDeserializeClss.add(keyCls);
if (valMustDeserialize)
mustDeserializeClss.add(valCls);
}
QueryTypeIdKey typeId;
QueryTypeIdKey altTypeId = null;
int valTypeId = ctx.cacheObjects().typeId(qryEntity.findValueType());
if (valCls == null || (binaryEnabled && !keyOrValMustDeserialize)) {
processBinaryMeta(ctx, qryEntity, desc);
typeId = new QueryTypeIdKey(cacheName, valTypeId);
if (valCls != null)
altTypeId = new QueryTypeIdKey(cacheName, valCls);
String affField = null;
// Need to setup affinity key for distributed joins.
String keyType = qryEntity.getKeyType();
if (!cctx.customAffinityMapper() && keyType != null) {
if (coCtx != null) {
CacheDefaultBinaryAffinityKeyMapper mapper = (CacheDefaultBinaryAffinityKeyMapper) coCtx.defaultAffMapper();
BinaryField field = mapper.affinityKeyField(keyType);
if (field != null)
affField = field.name();
}
}
if (affField != null) {
if (!escape)
affField = normalizeObjectName(affField, false);
desc.affinityKey(affField);
}
} else {
processClassMeta(qryEntity, desc, coCtx);
AffinityKeyMapper keyMapper = cctx.config().getAffinityMapper();
if (keyMapper instanceof GridCacheDefaultAffinityKeyMapper) {
String affField = ((GridCacheDefaultAffinityKeyMapper) keyMapper).affinityKeyPropertyName(desc.keyClass());
if (affField != null) {
if (!escape)
affField = normalizeObjectName(affField, false);
desc.affinityKey(affField);
}
}
typeId = new QueryTypeIdKey(cacheName, valCls);
altTypeId = new QueryTypeIdKey(cacheName, valTypeId);
}
desc.typeId(valTypeId);
return new QueryTypeCandidate(typeId, altTypeId, desc);
}
Aggregations