org.apache.ignite.cache.query.annotations.QuerySqlField Java Examples

The following examples show how to use org.apache.ignite.cache.query.annotations.QuerySqlField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PojoField.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates instance of {@link PojoField} from its field accessor.
 *
 * @param accessor field accessor.
 */
public PojoField(PojoFieldAccessor accessor) {
    this.name = accessor.getName();

    QuerySqlField sqlField = (QuerySqlField)accessor.getAnnotation(QuerySqlField.class);

    col = sqlField != null && sqlField.name() != null && !sqlField.name().isEmpty() ?
            sqlField.name() : name.toLowerCase();

    init(accessor);
}
 
Example #2
Source File: PojoValueField.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs Ignite cache value field descriptor.
 *
 * @param accessor field property accessor.
 */
public PojoValueField(PojoFieldAccessor accessor) {
    super(accessor);

    QuerySqlField sqlField = (QuerySqlField)accessor.getAnnotation(QuerySqlField.class);

    isIndexed = sqlField != null && sqlField.index();
}
 
Example #3
Source File: PojoKeyField.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs Ignite cache key POJO object descriptor.
 *
 * @param accessor property descriptor.
 */
public PojoKeyField(PojoFieldAccessor accessor) {
    super(accessor);

    QuerySqlField sqlField = (QuerySqlField)accessor.getAnnotation(QuerySqlField.class);

    if (sqlField != null && sqlField.descending())
        sortOrder = SortOrder.DESC;
}
 
Example #4
Source File: QueryEntity.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Process annotations for class.
 *
 * @param key If given class relates to key.
 * @param cls Class.
 * @param type Type descriptor.
 * @param parent Parent in case of embeddable.
 */
private static void processAnnotationsInClass(boolean key, Class<?> cls, QueryEntityTypeDescriptor type,
    @Nullable QueryEntityClassProperty parent) {
    if (U.isJdk(cls) || QueryUtils.isGeometryClass(cls)) {
        if (parent == null && !key && QueryUtils.isSqlType(cls)) { // We have to index primitive _val.
            String idxName = cls.getSimpleName() + "_" + QueryUtils.VAL_FIELD_NAME + "_idx";

            type.addIndex(idxName, QueryUtils.isGeometryClass(cls) ?
                QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED, QueryIndex.DFLT_INLINE_SIZE);

            type.addFieldToIndex(idxName, QueryUtils.VAL_FIELD_NAME, 0, false);
        }

        return;
    }

    if (parent != null && parent.knowsClass(cls))
        throw new CacheException("Recursive reference found in type: " + cls.getName());

    if (parent == null) { // Check class annotation at top level only.
        QueryTextField txtAnnCls = cls.getAnnotation(QueryTextField.class);

        if (txtAnnCls != null)
            type.valueTextIndex(true);

        QueryGroupIndex grpIdx = cls.getAnnotation(QueryGroupIndex.class);

        if (grpIdx != null)
            type.addIndex(grpIdx.name(), QueryIndexType.SORTED, grpIdx.inlineSize());

        QueryGroupIndex.List grpIdxList = cls.getAnnotation(QueryGroupIndex.List.class);

        if (grpIdxList != null && !F.isEmpty(grpIdxList.value())) {
            for (QueryGroupIndex idx : grpIdxList.value())
                type.addIndex(idx.name(), QueryIndexType.SORTED, idx.inlineSize());
        }
    }

    for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
        for (Field field : c.getDeclaredFields()) {
            QuerySqlField sqlAnn = field.getAnnotation(QuerySqlField.class);
            QueryTextField txtAnn = field.getAnnotation(QueryTextField.class);

            if (sqlAnn != null || txtAnn != null) {
                QueryEntityClassProperty prop = new QueryEntityClassProperty(field);

                prop.parent(parent);

                // Add parent property before its possible nested properties so that
                // resulting parent column comes before columns corresponding to those
                // nested properties in the resulting table - that way nested
                // properties override will happen properly (first parent, then children).
                type.addProperty(prop, key, true);

                processAnnotation(key, sqlAnn, txtAnn, cls, c, field.getType(), prop, type);
            }
        }
    }
}
 
Example #5
Source File: QueryEntity.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Processes annotation at field or method.
 *
 * @param key If given class relates to key.
 * @param sqlAnn SQL annotation, can be {@code null}.
 * @param txtAnn H2 text annotation, can be {@code null}.
 * @param cls Entity class.
 * @param curCls Current entity class.
 * @param fldCls Class of field or return type for method.
 * @param prop Current property.
 * @param desc Class description.
 */
private static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
    Class<?> cls, Class<?> curCls, Class<?> fldCls, QueryEntityClassProperty prop, QueryEntityTypeDescriptor desc) {
    if (sqlAnn != null) {
        processAnnotationsInClass(key, fldCls, desc, prop);

        if (!sqlAnn.name().isEmpty())
            prop.alias(sqlAnn.name());

        if (sqlAnn.index()) {
            String idxName = curCls.getSimpleName() + "_" + prop.alias() + "_idx";

            if (cls != curCls)
                idxName = cls.getSimpleName() + "_" + idxName;

            desc.addIndex(idxName, QueryUtils.isGeometryClass(prop.type()) ?
                QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED, sqlAnn.inlineSize());

            desc.addFieldToIndex(idxName, prop.fullName(), 0, sqlAnn.descending());
        }

        if (sqlAnn.notNull())
            desc.addNotNullField(prop.fullName());

        if (sqlAnn.precision() != -1)
            desc.addPrecision(prop.fullName(), sqlAnn.precision());

        if (sqlAnn.scale() != -1)
            desc.addScale(prop.fullName(), sqlAnn.scale());

        if ((!F.isEmpty(sqlAnn.groups()) || !F.isEmpty(sqlAnn.orderedGroups()))
            && sqlAnn.inlineSize() != QueryIndex.DFLT_INLINE_SIZE) {
            throw new CacheException("Inline size cannot be set on a field with group index [" +
                "type=" + cls.getName() + ", property=" + prop.fullName() + ']');
        }

        if (!F.isEmpty(sqlAnn.groups())) {
            for (String group : sqlAnn.groups())
                desc.addFieldToIndex(group, prop.fullName(), 0, false);
        }

        if (!F.isEmpty(sqlAnn.orderedGroups())) {
            for (QuerySqlField.Group idx : sqlAnn.orderedGroups())
                desc.addFieldToIndex(idx.name(), prop.fullName(), idx.order(), idx.descending());
        }
    }

    if (txtAnn != null)
        desc.addFieldToTextIndex(prop.fullName());
}