Search in sources :

Example 21 with Expression

use of org.immutables.criteria.expression.Expression in project immutables by immutables.

the class CriteriaContext method appendPath.

/**
 *  adds an intermediate path to partial expression
 */
public <T> CriteriaContext appendPath(Class<?> type, String pathAsString, CriteriaCreator<T> creator) {
    final Member member = memberLookup.find(type, pathAsString).orElseThrow(() -> new IllegalArgumentException(String.format("Path %s not found in %s", pathAsString, type)));
    Path newPath;
    Expression partial = state.partial();
    if (partial == null) {
        newPath = Path.ofMember(member);
    } else if (partial instanceof Path) {
        newPath = Visitors.toPath(partial).append(member);
    } else {
        throw new IllegalStateException("Partial expression is not a path: " + partial);
    }
    return new CriteriaContext(this, state.withPartial(newPath).withCreator(creator));
}
Also used : Path(org.immutables.criteria.expression.Path) Expression(org.immutables.criteria.expression.Expression) Member(java.lang.reflect.Member)

Example 22 with Expression

use of org.immutables.criteria.expression.Expression in project immutables by immutables.

the class AsyncReader method select.

public AsyncMapperTuple.DistinctLimitOffset select(Iterable<Projection<?>> projections) {
    Objects.requireNonNull(projections, "projections");
    Preconditions.checkArgument(!Iterables.isEmpty(projections), "empty projections");
    List<Expression> expressions = StreamSupport.stream(projections.spliterator(), false).map(Matchers::toExpression).collect(Collectors.toList());
    Query newQuery = this.query.addProjections(expressions);
    return new AsyncMappers.MapperTuple(newQuery, session);
}
Also used : Query(org.immutables.criteria.expression.Query) ImmutableQuery(org.immutables.criteria.expression.ImmutableQuery) Expression(org.immutables.criteria.expression.Expression)

Example 23 with Expression

use of org.immutables.criteria.expression.Expression in project immutables by immutables.

the class Matchers method combine.

static <R extends Criterion<?>> R combine(R left, R right, Operator operator) {
    Preconditions.checkArgument(operator == Operators.AND || operator == Operators.OR, "Invalid operator %s", operator);
    CriteriaContext context = extract(left);
    Expression leftExpression = context.expression();
    Expression rightExpression = extract(right).expression();
    Combiner combiner = operator == Operators.AND ? Combiner.and() : Combiner.or();
    Expression expression = combiner.combine(leftExpression, rightExpression);
    CriteriaCreator<R> creator = context.creator();
    ImmutableState state = context.state();
    return creator.create(new CriteriaContext(null, state.withCurrent(expression).withPartial(state.defaultPartial())));
}
Also used : Expression(org.immutables.criteria.expression.Expression)

Example 24 with Expression

use of org.immutables.criteria.expression.Expression in project immutables by immutables.

the class RxJavaReader method select.

public RxJavaMapperTuple select(Iterable<Projection<?>> projections) {
    Objects.requireNonNull(projections, "projections");
    Preconditions.checkArgument(!Iterables.isEmpty(projections), "empty projections");
    List<Expression> expressions = StreamSupport.stream(projections.spliterator(), false).map(Matchers::toExpression).collect(Collectors.toList());
    Query newQuery = this.query.addProjections(expressions);
    return new RxJavaMappers.MapperTuple(newQuery, session);
}
Also used : Query(org.immutables.criteria.expression.Query) ImmutableQuery(org.immutables.criteria.expression.ImmutableQuery) Expression(org.immutables.criteria.expression.Expression)

Example 25 with Expression

use of org.immutables.criteria.expression.Expression in project immutables by immutables.

the class AggregationExpressionTest method assertProjection.

private static void assertProjection(Aggregation<?> aggregation, String... expectedLines) {
    Expression expression = Matchers.toExpression(aggregation);
    String out = expression.accept(new DebugExpressionVisitor<>(new StringBuilder())).toString();
    final String expected = Arrays.stream(expectedLines).collect(Collectors.joining(System.lineSeparator()));
    Assertions.assertEquals(expected, out.trim());
}
Also used : DebugExpressionVisitor(org.immutables.criteria.expression.DebugExpressionVisitor) Expression(org.immutables.criteria.expression.Expression)

Aggregations

Expression (org.immutables.criteria.expression.Expression)32 Path (org.immutables.criteria.expression.Path)11 Call (org.immutables.criteria.expression.Call)8 Operator (org.immutables.criteria.expression.Operator)8 Pattern (java.util.regex.Pattern)5 PathNaming (org.immutables.criteria.backend.PathNaming)5 OptionalOperators (org.immutables.criteria.expression.OptionalOperators)5 Query (org.immutables.criteria.expression.Query)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Collection (java.util.Collection)4 Objects (java.util.Objects)4 ComparableOperators (org.immutables.criteria.expression.ComparableOperators)4 Constant (org.immutables.criteria.expression.Constant)4 ImmutableQuery (org.immutables.criteria.expression.ImmutableQuery)4 Operators (org.immutables.criteria.expression.Operators)4 StringOperators (org.immutables.criteria.expression.StringOperators)4 Visitors (org.immutables.criteria.expression.Visitors)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Preconditions (com.google.common.base.Preconditions)3 ArrayList (java.util.ArrayList)3