Add Query.Property.of(), Move StdFunctions to ebean-api

This commit is contained in:
Rob Bygrave
2022-11-07 12:57:39 +13:00
parent 5ad313d290
commit 3da924b943
8 changed files with 246 additions and 93 deletions
@@ -1,36 +0,0 @@
package io.ebean.typequery;
import io.ebean.Expr;
import io.ebean.Expression;
import io.ebean.Query;
public class StdExpressions {
public static Expression gt(Query.Property property, Object value) {
return Expr.gt(property.toString(), value);
}
public static Expression like(Query.Property property, String value) {
return Expr.like(property.toString(), value);
}
public static Expression ilike(Query.Property property, String value) {
return Expr.ilike(property.toString(), value);
}
public static Expression startsWith(Query.Property property, String value) {
return Expr.startsWith(property.toString(), value);
}
public static Expression istartsWith(Query.Property property, String value) {
return Expr.istartsWith(property.toString(), value);
}
public static Expression contains(Query.Property property, String value) {
return Expr.contains(property.toString(), value);
}
public static Expression icontains(Query.Property property, String value) {
return Expr.icontains(property.toString(), value);
}
}
@@ -1,54 +0,0 @@
package io.ebean.typequery;
import io.ebean.Query.Property;
public final class StdFunctions {
public static Property max(Property property) {
return new Standard("max(" + property + ")");
}
public static Property sum(Property property) {
return new Standard("sum(" + property + ")");
}
public static Property concat(Property property, Object... values) {
StringBuilder expression = new StringBuilder(50);
expression.append("concat(").append(property.toString());
for (Object value : values) {
expression.append(",").append(sqlStringExpression(value));
}
expression.append(")");
return new Standard(expression.toString());
}
public static Property coalesce(Property property, Object value) {
StringBuilder expression = new StringBuilder(50);
expression.append("coalesce(").append(property.toString()).append(",");
expression.append(sqlStringExpression(value));
expression.append(")");
return new Standard(expression.toString());
}
private static String sqlStringExpression(Object value) {
if (value instanceof Property || value instanceof Number) {
return value.toString();
} else {
return "'" + value + "'";
}
}
private static class Standard implements Property {
private final String expression;
private Standard(String expression) {
this.expression = expression;
}
@Override
public String toString() {
return expression;
}
}
}