use of io.micronaut.data.model.jpa.criteria.impl.LiteralExpression in project micronaut-data by micronaut-projects.
the class SourcePersistentEntityCriteriaQueryImpl method getQueryResultTypeName.
@Override
public String getQueryResultTypeName() {
if (selection instanceof ISelection) {
String[] result = new String[1];
((SelectionVisitable) selection).accept(new SelectionVisitor() {
@Override
public void visit(Predicate predicate) {
}
@Override
public void visit(PersistentPropertyPath<?> persistentPropertyPath) {
result[0] = ((SourcePersistentPropertyPath) persistentPropertyPath).getProperty().getType().getName();
}
@Override
public void visit(AliasedSelection<?> aliasedSelection) {
((SelectionVisitable) aliasedSelection.getSelection()).accept(this);
}
@Override
public void visit(PersistentEntityRoot<?> entityRoot) {
result[0] = ((SourcePersistentEntity) entityRoot.getPersistentEntity()).getType().getName();
}
@Override
public void visit(AggregateExpression<?, ?> aggregateExpression) {
switch(aggregateExpression.getType()) {
case COUNT:
case COUNT_DISTINCT:
result[0] = Long.class.getName();
break;
case MAX:
case MIN:
result[0] = requireProperty(aggregateExpression.getExpression()).getProperty().getTypeName();
break;
case SUM:
case AVG:
ClassElement type = ((SourcePersistentProperty) requireProperty(aggregateExpression.getExpression()).getProperty()).getType();
if (aggregateExpression.getExpressionType() != null) {
result[0] = aggregateExpression.getExpressionType().getName();
}
if (TypeUtils.isNumber(type)) {
result[0] = Number.class.getName();
} else {
result[0] = type.getName();
}
break;
default:
return;
}
}
@Override
public void visit(CompoundSelection<?> compoundSelection) {
if (compoundSelection.getCompoundSelectionItems().size() == 1) {
// Multiple selection shouldn't result in one type
compoundSelection.getCompoundSelectionItems().forEach(s -> ((SelectionVisitable) s).accept(this));
}
}
@Override
public void visit(LiteralExpression<?> literalExpression) {
result[0] = literalExpression.getValue().getClass().getName();
}
@Override
public void visit(IdExpression<?, ?> idExpression) {
SourcePersistentEntity persistentEntity = (SourcePersistentEntity) idExpression.getRoot().getPersistentEntity();
if (persistentEntity.hasCompositeIdentity()) {
throw new IllegalStateException("IdClass is unknown!");
}
result[0] = persistentEntity.getIdentity().getType().getName();
}
});
return result[0];
}
return null;
}
Aggregations