Search in sources :

Example 1 with QueryBinaryProperty

use of org.apache.ignite.internal.processors.query.property.QueryBinaryProperty in project ignite by apache.

the class QueryUtils method buildBinaryProperty.

/**
     * Builds binary object property.
     *
     * @param ctx Kernal context.
     * @param pathStr String representing path to the property. May contains dots '.' to identify
     *      nested fields.
     * @param resType Result type.
     * @param aliases Aliases.
     * @param isKeyField Key ownership flag, as defined in {@link QueryEntity#keyFields}: {@code true} if field belongs
     *      to key, {@code false} if it belongs to value, {@code null} if QueryEntity#keyFields is null.
     * @return Binary property.
     */
public static QueryBinaryProperty buildBinaryProperty(GridKernalContext ctx, String pathStr, Class<?> resType, Map<String, String> aliases, @Nullable Boolean isKeyField) throws IgniteCheckedException {
    String[] path = pathStr.split("\\.");
    QueryBinaryProperty res = null;
    StringBuilder fullName = new StringBuilder();
    for (String prop : path) {
        if (fullName.length() != 0)
            fullName.append('.');
        fullName.append(prop);
        String alias = aliases.get(fullName.toString());
        // The key flag that we've found out is valid for the whole path.
        res = new QueryBinaryProperty(ctx, prop, res, resType, isKeyField, alias);
    }
    return res;
}
Also used : QueryBinaryProperty(org.apache.ignite.internal.processors.query.property.QueryBinaryProperty)

Example 2 with QueryBinaryProperty

use of org.apache.ignite.internal.processors.query.property.QueryBinaryProperty in project ignite by apache.

the class QueryUtils method buildBinaryProperty.

/**
 * Builds binary object property.
 *
 * @param ctx Kernal context.
 * @param pathStr String representing path to the property. May contains dots '.' to identify
 *      nested fields.
 * @param resType Result type.
 * @param aliases Aliases.
 * @param isKeyField Key ownership flag, as defined in {@link QueryEntity#keyFields}: {@code true} if field belongs
 *      to key, {@code false} if it belongs to value, {@code null} if QueryEntity#keyFields is null.
 * @param notNull {@code true} if {@code null} value is not allowed.
 * @param dlftVal Default value.
 * @return Binary property.
 * @throws IgniteCheckedException On error.
 */
public static QueryBinaryProperty buildBinaryProperty(GridKernalContext ctx, String pathStr, Class<?> resType, Map<String, String> aliases, @Nullable Boolean isKeyField, boolean notNull, Object dlftVal) throws IgniteCheckedException {
    String[] path = pathStr.split("\\.");
    QueryBinaryProperty res = null;
    StringBuilder fullName = new StringBuilder();
    for (String prop : path) {
        if (fullName.length() != 0)
            fullName.append('.');
        fullName.append(prop);
        String alias = aliases.get(fullName.toString());
        // The key flag that we've found out is valid for the whole path.
        res = new QueryBinaryProperty(ctx, prop, res, resType, isKeyField, alias, notNull, dlftVal);
    }
    return res;
}
Also used : QueryBinaryProperty(org.apache.ignite.internal.processors.query.property.QueryBinaryProperty)

Example 3 with QueryBinaryProperty

use of org.apache.ignite.internal.processors.query.property.QueryBinaryProperty in project ignite by apache.

the class QueryUtils method buildBinaryProperty.

/**
 * Builds binary object property.
 *
 * @param ctx Kernal context.
 * @param pathStr String representing path to the property. May contains dots '.' to identify
 *      nested fields.
 * @param resType Result type.
 * @param aliases Aliases.
 * @param isKeyField Key ownership flag, {@code true} if this property is a field of the key object. Note that key
 * not a field of itself.
 * @param notNull {@code true} if {@code null} value is not allowed.
 * @param dlftVal Default value.
 * @param precision Precision.
 * @param scale Scale.
 * @return Binary property.
 */
public static QueryBinaryProperty buildBinaryProperty(GridKernalContext ctx, String pathStr, Class<?> resType, Map<String, String> aliases, boolean isKeyField, boolean notNull, Object dlftVal, int precision, int scale) {
    String[] path = pathStr.split("\\.");
    QueryBinaryProperty res = null;
    StringBuilder fullName = new StringBuilder();
    for (String prop : path) {
        if (fullName.length() != 0)
            fullName.append('.');
        fullName.append(prop);
        String alias = aliases.get(fullName.toString());
        // The key flag that we've found out is valid for the whole path.
        res = new QueryBinaryProperty(ctx, prop, res, resType, isKeyField, alias, notNull, dlftVal, precision, scale);
    }
    return res;
}
Also used : QueryBinaryProperty(org.apache.ignite.internal.processors.query.property.QueryBinaryProperty)

Example 4 with QueryBinaryProperty

use of org.apache.ignite.internal.processors.query.property.QueryBinaryProperty in project ignite by apache.

the class QueryUtils method processBinaryMeta.

/**
 * Processes declarative metadata for binary object.
 *
 * @param ctx Kernal context.
 * @param qryEntity Declared metadata.
 * @param d Type descriptor.
 * @throws IgniteCheckedException If failed.
 */
public static void processBinaryMeta(GridKernalContext ctx, QueryEntity qryEntity, QueryTypeDescriptorImpl d) throws IgniteCheckedException {
    LinkedHashMap<String, String> fields = qryEntity.getFields();
    Set<String> keyFields = qryEntity.getKeyFields();
    Set<String> notNulls = qryEntity.getNotNullFields();
    Map<String, Object> dlftVals = qryEntity.getDefaultFieldValues();
    Map<String, Integer> precision = qryEntity.getFieldsPrecision();
    Map<String, Integer> scale = qryEntity.getFieldsScale();
    boolean hasKeyFields = (keyFields != null);
    boolean isKeyClsSqlType = isSqlType(d.keyClass());
    if (hasKeyFields && !isKeyClsSqlType) {
        // ensure that 'keyFields' is case sensitive subset of 'fields'
        for (String keyField : keyFields) {
            if (!fields.containsKey(keyField))
                throw new IgniteCheckedException("QueryEntity 'keyFields' property must be a subset of keys " + "from 'fields' property (case sensitive): " + keyField);
        }
    }
    // value.
    for (Map.Entry<String, String> entry : fields.entrySet()) {
        String fieldName = entry.getKey();
        String fieldType = entry.getValue();
        boolean isKeyField;
        if (isKeyClsSqlType)
            // Entire key is not field of itself, even if it is set in "keyFields".
            isKeyField = false;
        else
            isKeyField = hasKeyFields && keyFields.contains(fieldName);
        boolean notNull = notNulls != null && notNulls.contains(fieldName);
        Object dfltVal = dlftVals != null ? dlftVals.get(fieldName) : null;
        QueryBinaryProperty prop = buildBinaryProperty(ctx, fieldName, U.classForName(fieldType, Object.class, true), d.aliases(), isKeyField, notNull, dfltVal, precision == null ? -1 : precision.getOrDefault(fieldName, -1), scale == null ? -1 : scale.getOrDefault(fieldName, -1));
        d.addProperty(prop, false);
    }
    if (!isKeyClsSqlType && qryEntity instanceof QueryEntityEx && ((QueryEntityEx) qryEntity).isPreserveKeysOrder())
        d.primaryKeyFields(keyFields);
    // so we have to add binary properties for them
    if ((qryEntity.getKeyFieldName() == null && F.mapContainsKey(precision, KEY_FIELD_NAME)) || F.isEmpty(fields))
        addKeyValueProperty(ctx, qryEntity, d, KEY_FIELD_NAME, true);
    if ((qryEntity.getValueFieldName() == null && F.mapContainsKey(precision, VAL_FIELD_NAME)) || F.isEmpty(fields))
        addKeyValueProperty(ctx, qryEntity, d, VAL_FIELD_NAME, false);
    processIndexes(qryEntity, d);
}
Also used : IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QueryBinaryProperty(org.apache.ignite.internal.processors.query.property.QueryBinaryProperty)

Example 5 with QueryBinaryProperty

use of org.apache.ignite.internal.processors.query.property.QueryBinaryProperty in project ignite by apache.

the class QueryUtils method addKeyValueProperty.

/**
 * Add validate property to QueryTypeDescriptor.
 *
 * @param ctx Kernel context.
 * @param qryEntity Query entity.
 * @param d Descriptor.
 * @param name Field name.
 * @throws IgniteCheckedException
 */
private static void addKeyValueProperty(GridKernalContext ctx, QueryEntity qryEntity, QueryTypeDescriptorImpl d, String name, boolean isKey) throws IgniteCheckedException {
    Map<String, Object> dfltVals = qryEntity.getDefaultFieldValues();
    Map<String, Integer> precision = qryEntity.getFieldsPrecision();
    Map<String, Integer> scale = qryEntity.getFieldsScale();
    String typeName = isKey ? qryEntity.getKeyType() : qryEntity.getValueType();
    Object dfltVal = dfltVals.get(name);
    QueryBinaryProperty prop = buildBinaryProperty(ctx, name, U.classForName(typeName, Object.class, true), d.aliases(), isKey, true, dfltVal, precision == null ? -1 : precision.getOrDefault(name, -1), scale == null ? -1 : scale.getOrDefault(name, -1));
    d.addProperty(prop, true, false);
}
Also used : IgniteSystemProperties.getInteger(org.apache.ignite.IgniteSystemProperties.getInteger) QueryBinaryProperty(org.apache.ignite.internal.processors.query.property.QueryBinaryProperty)

Aggregations

QueryBinaryProperty (org.apache.ignite.internal.processors.query.property.QueryBinaryProperty)5 IgniteSystemProperties.getInteger (org.apache.ignite.IgniteSystemProperties.getInteger)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1