use of io.micronaut.data.model.jpa.criteria.impl.query.QueryModelPredicateVisitor in project micronaut-data by micronaut-projects.
the class AbstractPersistentEntityCriteriaDelete method getQueryModel.
@Override
public QueryModel getQueryModel() {
if (entityRoot == null) {
throw new IllegalStateException("The root entity must be specified!");
}
QueryModel qm = QueryModel.from(entityRoot.getPersistentEntity());
Joiner joiner = new Joiner();
if (predicate instanceof PredicateVisitable) {
PredicateVisitable predicate = (PredicateVisitable) this.predicate;
predicate.accept(new QueryModelPredicateVisitor(qm));
predicate.accept(joiner);
}
for (Map.Entry<String, Joiner.Joined> e : joiner.getJoins().entrySet()) {
qm.join(e.getKey(), Optional.ofNullable(e.getValue().getType()).orElse(Join.Type.DEFAULT), e.getValue().getAlias());
}
return qm;
}
use of io.micronaut.data.model.jpa.criteria.impl.query.QueryModelPredicateVisitor in project micronaut-data by micronaut-projects.
the class AbstractPersistentEntityCriteriaUpdate method getQueryModel.
@Override
@NotNull
public QueryModel getQueryModel() {
if (entityRoot == null) {
throw new IllegalStateException("The root entity must be specified!");
}
QueryModel qm = QueryModel.from(entityRoot.getPersistentEntity());
Joiner joiner = new Joiner();
if (predicate instanceof PredicateVisitable) {
PredicateVisitable predicate = (PredicateVisitable) this.predicate;
predicate.accept(new QueryModelPredicateVisitor(qm));
predicate.accept(joiner);
}
for (Map.Entry<String, Joiner.Joined> e : joiner.getJoins().entrySet()) {
qm.join(e.getKey(), Optional.ofNullable(e.getValue().getType()).orElse(Join.Type.DEFAULT), e.getValue().getAlias());
}
return qm;
}
use of io.micronaut.data.model.jpa.criteria.impl.query.QueryModelPredicateVisitor in project micronaut-data by micronaut-projects.
the class AbstractPersistentEntityCriteriaQuery method getQueryModel.
@NotNull
@Override
public QueryModel getQueryModel() {
if (entityRoot == null) {
throw new IllegalStateException("The root entity must be specified!");
}
QueryModel qm = QueryModel.from(entityRoot.getPersistentEntity());
Joiner joiner = new Joiner();
if (predicate instanceof PredicateVisitable) {
PredicateVisitable predicate = (PredicateVisitable) this.predicate;
predicate.accept(new QueryModelPredicateVisitor(qm));
predicate.accept(joiner);
}
if (selection instanceof SelectionVisitable) {
SelectionVisitable selection = (SelectionVisitable) this.selection;
selection.accept(new QueryModelSelectionVisitor(qm, distinct));
selection.accept(joiner);
SelectionVisitable entityRoot = (SelectionVisitable) this.entityRoot;
entityRoot.accept(joiner);
} else {
SelectionVisitable entityRoot = (SelectionVisitable) this.entityRoot;
entityRoot.accept(new QueryModelSelectionVisitor(qm, distinct));
entityRoot.accept(joiner);
}
if (orders != null && !orders.isEmpty()) {
List<Sort.Order> sortOrders = orders.stream().map(o -> {
PersistentPropertyPath<?> propertyPath = requireProperty(o.getExpression());
joiner.joinIfNeeded(propertyPath);
String name = propertyPath.getProperty().getName();
// todo path
if (o.isAscending()) {
return Sort.Order.asc(name);
}
return Sort.Order.desc(name);
}).collect(Collectors.toList());
qm.sort(Sort.of(sortOrders));
}
for (Map.Entry<String, Joiner.Joined> e : joiner.getJoins().entrySet()) {
qm.join(e.getKey(), Optional.ofNullable(e.getValue().getType()).orElse(Join.Type.DEFAULT), e.getValue().getAlias());
}
qm.max(max);
qm.offset(offset);
if (forUpdate) {
qm.forUpdate();
}
return qm;
}
Aggregations