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));
}
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);
}
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())));
}
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);
}
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());
}
Aggregations