Search in sources :

Example 1 with ASTTrue

use of org.apache.cayenne.exp.parser.ASTTrue in project cayenne by apache.

the class ExpressionFactory method matchAllExp.

/**
 * @since 3.0
 */
public static Expression matchAllExp(String path, Object... values) {
    if (values == null) {
        throw new NullPointerException("Null values collection");
    }
    if (values.length == 0) {
        return new ASTTrue();
    }
    int split = path.indexOf(SPLIT_SEPARATOR);
    List<Expression> matches = new ArrayList<>(values.length);
    if (split >= 0 && split < path.length() - 1) {
        int splitEnd = path.indexOf(Entity.PATH_SEPARATOR, split + 1);
        String beforeSplit = split > 0 ? path.substring(0, split) + "." : "";
        String afterSplit = splitEnd > 0 ? "." + path.substring(splitEnd + 1) : "";
        String aliasBase = "split" + autoAliasId++ + "_";
        String splitChunk = splitEnd > 0 ? path.substring(split + 1, splitEnd) : path.substring(split + 1);
        // fix the path - replace split with dot if it's in the middle, or
        // strip it if
        // it's in the beginning
        path = split == 0 ? path.substring(1) : path.replace(SPLIT_SEPARATOR, '.');
        int i = 0;
        for (Object value : values) {
            String alias = aliasBase + i;
            String aliasedPath = beforeSplit + alias + afterSplit;
            i++;
            ASTPath pathExp = new ASTObjPath(aliasedPath);
            pathExp.setPathAliases(Collections.singletonMap(alias, splitChunk));
            matches.add(new ASTEqual(pathExp, value));
        }
    } else {
        for (Object value : values) {
            matches.add(new ASTEqual(new ASTObjPath(path), value));
        }
    }
    return joinExp(Expression.AND, matches);
}
Also used : ASTObjPath(org.apache.cayenne.exp.parser.ASTObjPath) ArrayList(java.util.ArrayList) ASTEqual(org.apache.cayenne.exp.parser.ASTEqual) ASTFullObject(org.apache.cayenne.exp.parser.ASTFullObject) ASTPath(org.apache.cayenne.exp.parser.ASTPath) ASTTrue(org.apache.cayenne.exp.parser.ASTTrue)

Aggregations

ArrayList (java.util.ArrayList)1 ASTEqual (org.apache.cayenne.exp.parser.ASTEqual)1 ASTFullObject (org.apache.cayenne.exp.parser.ASTFullObject)1 ASTObjPath (org.apache.cayenne.exp.parser.ASTObjPath)1 ASTPath (org.apache.cayenne.exp.parser.ASTPath)1 ASTTrue (org.apache.cayenne.exp.parser.ASTTrue)1