Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codegen Support for nested (object) Criterias
Allow user to chain methods like `person.friend.name.isEqualTo("John")`
- Loading branch information
1 parent
5bf91b5
commit bc21046
Showing
15 changed files
with
203 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
criteria/common/src/org/immutables/criteria/ValueCriteria.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
criteria/common/src/org/immutables/criteria/constraints/CriteriaContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.immutables.criteria.constraints; | ||
|
||
import org.immutables.criteria.DocumentCriteria; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
/** | ||
* Link between front-end (codegened Criteria) and back-end (built {@link Expression}). | ||
*/ | ||
public final class CriteriaContext<R extends DocumentCriteria<R>> { | ||
|
||
private final CriteriaCreator<R> creator; | ||
private final DnfExpression<?> expression; | ||
private final Path<?> path; | ||
private final Operator operator; | ||
|
||
public CriteriaContext(CriteriaCreator<R> creator) { | ||
this(Operators.AND, DnfExpression.create(), null, creator); | ||
} | ||
|
||
private CriteriaContext(Operator operator, DnfExpression<?> expression, Path<?> path, CriteriaCreator<R> creator) { | ||
this.creator = creator; | ||
this.expression = expression; | ||
this.path = path; | ||
this.operator = operator; | ||
} | ||
|
||
public R create() { | ||
return creator.create(this); | ||
} | ||
|
||
/** | ||
* adds an intermediate step (list of paths usually) | ||
*/ | ||
public CriteriaContext<R> add(Path<?> path) { | ||
final Path<?> newPath = this.path != null ? Expressions.path(this.path.path() + "." + path.path()) : path; | ||
return new CriteriaContext<>(operator, expression, newPath, creator); | ||
} | ||
|
||
public CriteriaContext<R> or() { | ||
if (operator == Operators.OR) { | ||
return this; | ||
} | ||
|
||
return new CriteriaContext<>(Operators.OR, expression, path, creator); | ||
} | ||
|
||
public Expression<?> expression() { | ||
return this.expression; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public R create(UnaryOperator<Expression<?>> operator) { | ||
final Expression<Object> apply = (Expression<Object>) operator.apply(path); | ||
final DnfExpression<Object> existing = (DnfExpression<Object>) expression; | ||
final DnfExpression<?> newExpression = this.operator == Operators.AND ? existing.and(apply) : existing.or(apply); | ||
return new CriteriaContext<R>(Operators.AND, newExpression, null, creator).create(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.