mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Rename TQColumn -> Query.Property and move to api + use with UpdateQuery.set()
- Refactor rename TQColumn to Query.Property and move to ebean-api module - Add UpdateQuery.set() methods to use Query.Property (as per #2849)
This commit is contained in:
@@ -2,34 +2,35 @@ package io.ebean.typequery;
|
||||
|
||||
import io.ebean.Expr;
|
||||
import io.ebean.Expression;
|
||||
import io.ebean.Query;
|
||||
|
||||
public class StdExpressions {
|
||||
|
||||
public static Expression gt(TQColumn property, Object value) {
|
||||
public static Expression gt(Query.Property property, Object value) {
|
||||
return Expr.gt(property.toString(), value);
|
||||
}
|
||||
|
||||
public static Expression like(TQColumn property, String value) {
|
||||
public static Expression like(Query.Property property, String value) {
|
||||
return Expr.like(property.toString(), value);
|
||||
}
|
||||
|
||||
public static Expression ilike(TQColumn property, String value) {
|
||||
public static Expression ilike(Query.Property property, String value) {
|
||||
return Expr.ilike(property.toString(), value);
|
||||
}
|
||||
|
||||
public static Expression startsWith(TQColumn property, String value) {
|
||||
public static Expression startsWith(Query.Property property, String value) {
|
||||
return Expr.startsWith(property.toString(), value);
|
||||
}
|
||||
|
||||
public static Expression istartsWith(TQColumn property, String value) {
|
||||
public static Expression istartsWith(Query.Property property, String value) {
|
||||
return Expr.istartsWith(property.toString(), value);
|
||||
}
|
||||
|
||||
public static Expression contains(TQColumn property, String value) {
|
||||
public static Expression contains(Query.Property property, String value) {
|
||||
return Expr.contains(property.toString(), value);
|
||||
}
|
||||
|
||||
public static Expression icontains(TQColumn property, String value) {
|
||||
public static Expression icontains(Query.Property property, String value) {
|
||||
return Expr.icontains(property.toString(), value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package io.ebean.typequery;
|
||||
|
||||
import io.ebean.Query.Property;
|
||||
|
||||
public final class StdFunctions {
|
||||
|
||||
public static TQColumn max(TQColumn property) {
|
||||
public static Property max(Property property) {
|
||||
return new Standard("max(" + property + ")");
|
||||
}
|
||||
|
||||
public static TQColumn sum(TQColumn property) {
|
||||
public static Property sum(Property property) {
|
||||
return new Standard("sum(" + property + ")");
|
||||
}
|
||||
|
||||
public static TQColumn concat(TQColumn property, Object... values) {
|
||||
public static Property concat(Property property, Object... values) {
|
||||
StringBuilder expression = new StringBuilder(50);
|
||||
expression.append("concat(").append(property.toString());
|
||||
for (Object value : values) {
|
||||
@@ -20,7 +22,7 @@ public final class StdFunctions {
|
||||
return new Standard(expression.toString());
|
||||
}
|
||||
|
||||
public static TQColumn coalesce(TQColumn property, Object value) {
|
||||
public static Property coalesce(Property property, Object value) {
|
||||
StringBuilder expression = new StringBuilder(50);
|
||||
expression.append("coalesce(").append(property.toString()).append(",");
|
||||
expression.append(sqlStringExpression(value));
|
||||
@@ -29,14 +31,14 @@ public final class StdFunctions {
|
||||
}
|
||||
|
||||
private static String sqlStringExpression(Object value) {
|
||||
if (value instanceof TQColumn || value instanceof Number) {
|
||||
if (value instanceof Property || value instanceof Number) {
|
||||
return value.toString();
|
||||
} else {
|
||||
return "'" + value + "'";
|
||||
}
|
||||
}
|
||||
|
||||
private static class Standard implements TQColumn {
|
||||
private static class Standard implements Property {
|
||||
|
||||
private final String expression;
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package io.ebean.typequery;
|
||||
|
||||
/**
|
||||
* Marker interface for type safe properties and expressions.
|
||||
*/
|
||||
public interface TQColumn {
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package io.ebean.typequery;
|
||||
|
||||
import io.ebean.ExpressionList;
|
||||
import io.ebean.Query;
|
||||
|
||||
/**
|
||||
* A property used in type query.
|
||||
*
|
||||
* @param <R> The type of the owning root bean
|
||||
*/
|
||||
public class TQProperty<R> implements TQColumn {
|
||||
public class TQProperty<R> implements Query.Property {
|
||||
|
||||
protected final String _name;
|
||||
|
||||
|
||||
@@ -268,9 +268,9 @@ public abstract class TQRootBean<T, R> {
|
||||
return root;
|
||||
}
|
||||
|
||||
private Set<String> properties(TQColumn[] properties) {
|
||||
private Set<String> properties(Query.Property[] properties) {
|
||||
Set<String> props = new LinkedHashSet<>();
|
||||
for (TQColumn property : properties) {
|
||||
for (Query.Property property : properties) {
|
||||
props.add(property.toString());
|
||||
}
|
||||
return props;
|
||||
@@ -278,11 +278,11 @@ public abstract class TQRootBean<T, R> {
|
||||
|
||||
/**
|
||||
* Specify the properties to be loaded on the 'main' root level entity bean
|
||||
* also allowing for functions to be used like {@link StdFunctions#max(TQColumn)}.
|
||||
* also allowing for functions to be used like {@link StdFunctions#max(Query.Property)}.
|
||||
*
|
||||
* @param properties the list of properties to fetch
|
||||
*/
|
||||
public final R select(TQColumn... properties) {
|
||||
public final R select(Query.Property... properties) {
|
||||
((SpiQueryFetch) query).selectProperties(properties(properties));
|
||||
return root;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user