diff --git a/ebean-api/src/main/java/io/ebean/Query.java b/ebean-api/src/main/java/io/ebean/Query.java index 0a9723d24..ad15fc047 100644 --- a/ebean-api/src/main/java/io/ebean/Query.java +++ b/ebean-api/src/main/java/io/ebean/Query.java @@ -1772,14 +1772,18 @@ public interface Query extends CancelableQuery { * Type safe query bean properties and expressions (marker interface). *

* Implemented by query bean properties and expressions based on those properties. + *

+ * The base type determines which {@link StdFunctions} can be used on the property. + * + * @param The base type of the property Number, String, Temporal, Boolean or Object. */ - interface Property { + interface Property { /** * Return a property given the expression. */ - static Property of(String expression) { - return new SimpleProperty(expression); + static Property of(String expression) { + return new SimpleProperty<>(expression); } /** diff --git a/ebean-api/src/main/java/io/ebean/SimpleProperty.java b/ebean-api/src/main/java/io/ebean/SimpleProperty.java index 274978246..044f2aa31 100644 --- a/ebean-api/src/main/java/io/ebean/SimpleProperty.java +++ b/ebean-api/src/main/java/io/ebean/SimpleProperty.java @@ -1,6 +1,6 @@ package io.ebean; -final class SimpleProperty implements Query.Property { +final class SimpleProperty implements Query.Property { private final String expression; diff --git a/ebean-api/src/main/java/io/ebean/StdFunctions.java b/ebean-api/src/main/java/io/ebean/StdFunctions.java index 35d9140c5..6a36c58d8 100644 --- a/ebean-api/src/main/java/io/ebean/StdFunctions.java +++ b/ebean-api/src/main/java/io/ebean/StdFunctions.java @@ -2,37 +2,43 @@ package io.ebean; import io.ebean.Query.Property; +import java.time.temporal.Temporal; + public final class StdFunctions { - public static Property avg(Property property) { - return Property.of("avg(" + property + ")"); - } - - public static Property count(Property property) { + public static Property count(Property property) { return Property.of("count(" + property + ")"); } - public static Property max(Property property) { - return Property.of("max(" + property + ")"); - } - - public static Property min(Property property) { - return Property.of("min(" + property + ")"); - } - - public static Property sum(Property property) { + public static Property sum(Property property) { return Property.of("sum(" + property + ")"); } - public static Property lower(Property property) { + public static Property avg(Property property) { + return Property.of("avg(" + property + ")"); + } + + public static Property max(Property property) { + return Property.of("max(" + property + ")"); + } + + public static Property min(Property property) { + return Property.of("min(" + property + ")"); + } + + public static Property coalesce(Property property, Object value) { + return Property.of("coalesce(" + property.toString() + "," + sqlValue(value) + ")"); + } + + public static Property lower(Property property) { return Property.of("lower(" + property + ")"); } - public static Property upper(Property property) { + public static Property upper(Property property) { return Property.of("upper(" + property + ")"); } - public static Property concat(Property 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) { @@ -42,10 +48,6 @@ public final class StdFunctions { return Property.of(expression.toString()); } - public static Property coalesce(Property property, Object value) { - return Property.of("coalesce(" + property.toString() + "," + sqlValue(value) + ")"); - } - private static String sqlConcatString(Object value) { String asStr = String.valueOf(value); return (value instanceof Property || isSqlQuoted(asStr)) ? asStr : "'" + value + "'"; @@ -66,35 +68,67 @@ public final class StdFunctions { // -------------------------------------------------------------------------------------------- // // ---- Expressions --------------------------------------------------------------------------- // - public static Expression eq(Property property, Object value) { + public static Expression eq(Property property, Number value) { return Expr.eq(property.toString(), value); } - public static Expression gt(Property property, Object value) { + public static Expression eq(Property property, String value) { + return Expr.eq(property.toString(), value); + } + + public static Expression eq(Property property, Temporal value) { + return Expr.eq(property.toString(), value); + } + + public static Expression eq(Property property, boolean value) { + return Expr.eq(property.toString(), value); + } + + public static Expression eq(Property property, Object value) { + return Expr.eq(property.toString(), value); + } + + //---- + + public static Expression gt(Property property, Number value) { return Expr.gt(property.toString(), value); } - public static Expression like(Property property, String value) { + public static Expression gt(Property property, String value) { + return Expr.gt(property.toString(), value); + } + + public static Expression gt(Property property, Temporal value) { + return Expr.gt(property.toString(), value); + } + + public static Expression gt(Property property, Object value) { + return Expr.gt(property.toString(), value); + } + + //---- + + public static Expression like(Property property, String value) { return Expr.like(property.toString(), value); } - public static Expression ilike(Property property, String value) { + public static Expression ilike(Property property, String value) { return Expr.ilike(property.toString(), value); } - public static Expression startsWith(Property property, String value) { + public static Expression startsWith(Property property, String value) { return Expr.startsWith(property.toString(), value); } - public static Expression istartsWith(Property property, String value) { + public static Expression istartsWith(Property property, String value) { return Expr.istartsWith(property.toString(), value); } - public static Expression contains(Property property, String value) { + public static Expression contains(Property property, String value) { return Expr.contains(property.toString(), value); } - public static Expression icontains(Property property, String value) { + public static Expression icontains(Property property, String value) { return Expr.icontains(property.toString(), value); } } diff --git a/ebean-api/src/main/java/io/ebean/UpdateQuery.java b/ebean-api/src/main/java/io/ebean/UpdateQuery.java index a7abe00ea..bb293c748 100644 --- a/ebean-api/src/main/java/io/ebean/UpdateQuery.java +++ b/ebean-api/src/main/java/io/ebean/UpdateQuery.java @@ -118,7 +118,7 @@ public interface UpdateQuery { * @param property The bean property to be set * @param value The value to set the property to */ - UpdateQuery set(Query.Property property, Object value); + UpdateQuery set(Query.Property property, Object value); /** * Set the property to be null. @@ -142,7 +142,7 @@ public interface UpdateQuery { * * @param property The bean property to be set */ - UpdateQuery setNull(Query.Property property); + UpdateQuery setNull(Query.Property property); /** * Set using a property expression that does not need any bind values. diff --git a/ebean-api/src/test/java/io/ebean/StdFunctionsTest.java b/ebean-api/src/test/java/io/ebean/StdFunctionsTest.java index e22344c43..4cce8ed1a 100644 --- a/ebean-api/src/test/java/io/ebean/StdFunctionsTest.java +++ b/ebean-api/src/test/java/io/ebean/StdFunctionsTest.java @@ -9,8 +9,9 @@ import static org.assertj.core.api.Assertions.assertThat; class StdFunctionsTest { - final Query.Property foo = Query.Property.of("foo"); - final Query.Property bar = Query.Property.of("bar"); + final Query.Property amount = Query.Property.of("amount"); + final Query.Property foo = Query.Property.of("foo"); + final Query.Property bar = Query.Property.of("bar"); @Test void testAvg() { @@ -34,7 +35,7 @@ class StdFunctionsTest { @Test void testSum() { - assertThat(sum(foo).toString()).isEqualTo("sum(foo)"); + assertThat(sum(amount).toString()).isEqualTo("sum(amount)"); } @Test diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PArray.java b/ebean-querybean/src/main/java/io/ebean/typequery/PArray.java index 504a4b5d6..17076b9bd 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PArray.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PArray.java @@ -6,7 +6,7 @@ package io.ebean.typequery; * @param the root query bean type * @param the element type of the DbArray */ -public final class PArray extends TQPropertyBase { +public final class PArray extends TQPropertyBase { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java index cc50bd0d0..1faa6d7aa 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseCompareable.java @@ -6,11 +6,11 @@ import io.ebean.Query; /** * Base property for all comparable types. * - * @param the root query bean type - * @param the type of the scalar property + * @param the root query bean type + * @param the type of the scalar property + * @param the base type of the property */ -@SuppressWarnings("rawtypes") -public class PBaseCompareable extends PBaseValueEqual { +public abstract class PBaseCompareable extends PBaseValueEqual { /** * Construct with a property name and root instance. @@ -44,11 +44,14 @@ public class PBaseCompareable extends PBaseValueEqual { /** * Greater than other property. + *

+ * Note that the other property must have the same common "Base type" (String, Number, Temporal, Boolean or Object). * * @param other the other property to compare + * * @return the root query bean instance */ - public final R gt(TQProperty other) { + public final R gt(TQProperty other) { expr().raw(_name + " > " + other.propertyName()); return _root; } @@ -81,7 +84,7 @@ public class PBaseCompareable extends PBaseValueEqual { * @param other the other property to compare * @return the root query bean instance */ - public final R ge(TQProperty other) { + public final R ge(TQProperty other) { expr().raw(_name + " >= " + other.propertyName()); return _root; } @@ -114,7 +117,7 @@ public class PBaseCompareable extends PBaseValueEqual { * @param other the other property to compare * @return the root query bean instance */ - public final R lt(TQProperty other) { + public final R lt(TQProperty other) { expr().raw(_name + " < " + other.propertyName()); return _root; } @@ -147,7 +150,7 @@ public class PBaseCompareable extends PBaseValueEqual { * @param other the other property to compare * @return the root query bean instance */ - public final R le(TQProperty other) { + public final R le(TQProperty other) { expr().raw(_name + " <= " + other.propertyName()); return _root; } @@ -197,7 +200,7 @@ public class PBaseCompareable extends PBaseValueEqual { * The most common use of this could be called "effective dating" where 2 date or * timestamp columns represent the date range in which */ - public final R inRangeWith(TQProperty highProperty, T value) { + public final R inRangeWith(TQProperty highProperty, T value) { expr().inRangeWith(_name, highProperty._name, value); return _root; } @@ -220,7 +223,7 @@ public class PBaseCompareable extends PBaseValueEqual { *

* This is a convenience expression combining a number of simple expressions. */ - public final R inRangeWith(TQProperty lowProperty, TQProperty highProperty) { + public final R inRangeWith(TQProperty lowProperty, TQProperty highProperty) { expr().inRangeWithProperties(_name, lowProperty.propertyName(), highProperty.propertyName()); return _root; } diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseDate.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseDate.java index 740e4f2d2..8759baa7b 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseDate.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseDate.java @@ -1,5 +1,7 @@ package io.ebean.typequery; +import java.time.temporal.Temporal; + /** * Base property for date and date time types. * @@ -7,7 +9,7 @@ package io.ebean.typequery; * @param the date time type */ @SuppressWarnings("rawtypes") -public abstract class PBaseDate extends PBaseCompareable { +public abstract class PBaseDate extends PBaseCompareable { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseNumber.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseNumber.java index 3f1de62d9..6e2e2a496 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseNumber.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseNumber.java @@ -7,7 +7,7 @@ package io.ebean.typequery; * @param the number type */ @SuppressWarnings("rawtypes") -public abstract class PBaseNumber extends PBaseCompareable { +public abstract class PBaseNumber extends PBaseCompareable { /** * Construct with a property name and root instance. @@ -16,7 +16,7 @@ public abstract class PBaseNumber extends PBaseCompareab * @param root the root query bean instance */ public PBaseNumber(String name, R root) { - super(name , root); + super(name, root); } /** diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseString.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseString.java index a0f3643d5..fb65af6ad 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseString.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseString.java @@ -5,7 +5,7 @@ package io.ebean.typequery; * * @param the root query bean type */ -public abstract class PBaseString extends PBaseCompareable { +public abstract class PBaseString extends PBaseCompareable { /** * Construct with a property name and root instance. @@ -25,22 +25,28 @@ public abstract class PBaseString extends PBaseCompareable { } /** + * Deprecated migrate to eq(). + *

* Is equal to. The same as eq but uses the strong type as argument rather than String. * * @param value the equal to bind value * @return the root query bean instance */ + @Deprecated public final R equalToType(T value) { expr().eq(_name, value); return _root; } /** + * Deprecated migrate to ne(). + *

* Is not equal to. The same as ne but uses the strong type as argument rather than String. * * @param value the equal to bind value * @return the root query bean instance */ + @Deprecated public final R notEqualToType(T value) { expr().ne(_name, value); return _root; @@ -49,7 +55,146 @@ public abstract class PBaseString extends PBaseCompareable { // common string / expressions ------------ /** - * Case insensitive is equal to. + * Equal to. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R eq(String value) { + expr().eq(_name, value); + return _root; + } + + /** + * Not equal to. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R ne(String value) { + expr().ne(_name, value); + return _root; + } + + /** + * Greater than. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R gt(String value) { + expr().gt(_name, value); + return _root; + } + + /** + * Greater than OR Null. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R gtOrNull(String value) { + expr().gtOrNull(_name, value); + return _root; + } + + /** + * Greater than or Equal to. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R ge(String value) { + expr().ge(_name, value); + return _root; + } + + /** + * Greater than or Equal to OR Null. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R geOrNull(String value) { + expr().geOrNull(_name, value); + return _root; + } + + /** + * Less than. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R lt(String value) { + expr().lt(_name, value); + return _root; + } + + /** + * Less than OR Null. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R ltOrNull(String value) { + expr().ltOrNull(_name, value); + return _root; + } + + /** + * Less than or Equal to. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R le(String value) { + expr().le(_name, value); + return _root; + } + + /** + * Less than or Equal to OR null. + * + * @param value the bind value + * @return the root query bean instance + */ + public final R leOrNull(String value) { + expr().leOrNull(_name, value); + return _root; + } + + /** + * Greater or equal to lower value and strictly less than upper value. + *

+ * This is generally preferable over Between for date and datetime types + * as SQL Between is inclusive on the upper bound ({@code <= }) and generally + * we need the upper bound to be exclusive ({@code < }). + *

+ * + * @param lower the lower bind value ({@code >= }) + * @param upper the upper bind value ({@code < }) + * @return the root query bean instance + */ + public final R inRange(String lower, String upper) { + expr().inRange(_name, lower, upper); + return _root; + } + + /** + * Between lower and upper values. + * + * @param lower the lower bind value + * @param upper the upper bind value + * @return the root query bean instance + */ + public final R between(String lower, String upper) { + expr().between(_name, lower, upper); + return _root; + } + + /** + * Case-insensitive is equal to. * * @param value the equal to bind value * @return the root query bean instance @@ -60,7 +205,7 @@ public abstract class PBaseString extends PBaseCompareable { } /** - * Case insensitive is equal to. + * Case-insensitive is equal to. * * @param value the equal to bind value * @return the root query bean instance @@ -115,7 +260,7 @@ public abstract class PBaseString extends PBaseCompareable { } /** - * Case insensitive like. + * Case-insensitive like. * * @param value the equal to bind value * @return the root query bean instance @@ -126,7 +271,7 @@ public abstract class PBaseString extends PBaseCompareable { } /** - * Case insensitive starts with. + * Case-insensitive starts with. * * @param value the equal to bind value * @return the root query bean instance @@ -137,7 +282,7 @@ public abstract class PBaseString extends PBaseCompareable { } /** - * Case insensitive ends with. + * Case-insensitive ends with. * * @param value the equal to bind value * @return the root query bean instance @@ -148,7 +293,7 @@ public abstract class PBaseString extends PBaseCompareable { } /** - * Case insensitive contains. + * Case-insensitive contains. * * @param value the equal to bind value * @return the root query bean instance diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseTime.java new file mode 100644 index 000000000..54daaae41 --- /dev/null +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseTime.java @@ -0,0 +1,52 @@ +package io.ebean.typequery; + +import java.time.temporal.Temporal; + +/** + * Base property for time types. + * + * @param the root query bean type + * @param the number type + */ +@SuppressWarnings("rawtypes") +public abstract class PBaseTime extends PBaseCompareable { + + /** + * Construct with a property name and root instance. + * + * @param name property name + * @param root the root query bean instance + */ + public PBaseTime(String name, R root) { + super(name, root); + } + + /** + * Construct with additional path prefix. + */ + public PBaseTime(String name, R root, String prefix) { + super(name, root, prefix); + } + + /** + * Same as greater than. + * + * @param value the equal to bind value + * @return the root query bean instance + */ + public final R after(T value) { + expr().gt(_name, value); + return _root; + } + + /** + * Same as less than. + * + * @param value the equal to bind value + * @return the root query bean instance + */ + public final R before(T value) { + expr().lt(_name, value); + return _root; + } +} diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseValueEqual.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseValueEqual.java index 58474a371..049ecac26 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBaseValueEqual.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBaseValueEqual.java @@ -11,7 +11,7 @@ import java.util.Collection; * @param the root query bean type * @param the number type */ -public abstract class PBaseValueEqual extends TQPropertyBase { +public abstract class PBaseValueEqual extends TQPropertyBase { /** * Construct with a property name and root instance. @@ -89,7 +89,7 @@ public abstract class PBaseValueEqual extends TQPropertyBase { * @param other the other property to compare * @return the root query bean instance */ - public final R eq(TQProperty other) { + public final R eq(TQProperty other) { expr().raw(_name + " = " + other.propertyName()); return _root; } @@ -152,7 +152,7 @@ public abstract class PBaseValueEqual extends TQPropertyBase { * @param other the other property to compare * @return the root query bean instance */ - public final R ne(TQProperty other) { + public final R ne(TQProperty other) { expr().raw(_name + " <> " + other.propertyName()); return _root; } diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PBoolean.java b/ebean-querybean/src/main/java/io/ebean/typequery/PBoolean.java index 55707300e..370cce8a7 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PBoolean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PBoolean.java @@ -5,7 +5,7 @@ package io.ebean.typequery; * * @param the root query bean type */ -public final class PBoolean extends PBaseValueEqual { +public final class PBoolean extends PBaseValueEqual { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PByteArray.java b/ebean-querybean/src/main/java/io/ebean/typequery/PByteArray.java index d2bc50353..ce275eeda 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PByteArray.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PByteArray.java @@ -5,7 +5,7 @@ package io.ebean.typequery; * * @param the root query bean type */ -public final class PByteArray extends PBaseValueEqual { +public final class PByteArray extends PBaseValueEqual { /** * Construct with a property name and root instance. @@ -24,5 +24,4 @@ public final class PByteArray extends PBaseValueEqual { super(name, root, prefix); } - } diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PCidr.java b/ebean-querybean/src/main/java/io/ebean/typequery/PCidr.java index 645b5d37b..2ad7e4600 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PCidr.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PCidr.java @@ -7,7 +7,7 @@ import io.ebean.types.Cidr; * * @param the root query bean type */ -public final class PCidr extends PBaseValueEqual { +public final class PCidr extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PCurrency.java b/ebean-querybean/src/main/java/io/ebean/typequery/PCurrency.java index 5f2ecb65c..0d6256ae3 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PCurrency.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PCurrency.java @@ -7,7 +7,7 @@ import java.util.Currency; * * @param the root query bean type */ -public final class PCurrency extends PBaseValueEqual { +public final class PCurrency extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PEnum.java b/ebean-querybean/src/main/java/io/ebean/typequery/PEnum.java index ccd9ff7aa..124263f55 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PEnum.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PEnum.java @@ -1,12 +1,12 @@ package io.ebean.typequery; /** - * BigDecimal property. + * Enum property. * * @param the enum specific type * @param the root query bean type */ -public final class PEnum extends PBaseValueEqual { +public final class PEnum extends PBaseValueEqual { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PFile.java b/ebean-querybean/src/main/java/io/ebean/typequery/PFile.java index c1ea4c2d5..d0f5b6931 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PFile.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PFile.java @@ -9,7 +9,7 @@ package io.ebean.typequery; * * @param the root query bean type */ -public final class PFile extends TQPropertyBase { +public final class PFile extends TQPropertyBase { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PInet.java b/ebean-querybean/src/main/java/io/ebean/typequery/PInet.java index d0fd0d8ab..a87a6ae8f 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PInet.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PInet.java @@ -7,7 +7,7 @@ import io.ebean.types.Inet; * * @param the root query bean type */ -public final class PInet extends PBaseValueEqual { +public final class PInet extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PInetAddress.java b/ebean-querybean/src/main/java/io/ebean/typequery/PInetAddress.java index f4a30ca6a..527ca0938 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PInetAddress.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PInetAddress.java @@ -7,8 +7,7 @@ import java.net.InetAddress; * * @param the root query bean type */ - -public final class PInetAddress extends PBaseValueEqual { +public final class PInetAddress extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PJodaLocalTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/PJodaLocalTime.java index d92165d33..6cc01f7de 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PJodaLocalTime.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PJodaLocalTime.java @@ -8,7 +8,7 @@ import org.joda.time.LocalTime; * * @param the root query bean type */ -public final class PJodaLocalTime extends PBaseNumber { +public final class PJodaLocalTime extends PBaseTime { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PJson.java b/ebean-querybean/src/main/java/io/ebean/typequery/PJson.java index 5eddd0196..546964ed9 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PJson.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PJson.java @@ -17,7 +17,7 @@ package io.ebean.typequery; * * @param the root query bean type */ -public final class PJson extends TQPropertyBase { +public final class PJson extends TQPropertyBase { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PLocalTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/PLocalTime.java index 463365e8e..8232577fd 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PLocalTime.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PLocalTime.java @@ -8,7 +8,7 @@ import java.time.LocalTime; * * @param the root query bean type */ -public final class PLocalTime extends PBaseNumber { +public final class PLocalTime extends PBaseTime { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/POffsetDateTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/POffsetDateTime.java index 809248b86..88ef6875f 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/POffsetDateTime.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/POffsetDateTime.java @@ -7,7 +7,7 @@ import java.time.OffsetDateTime; * * @param the root query bean type */ -public final class POffsetDateTime extends PBaseNumber { +public final class POffsetDateTime extends PBaseDate { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/POffsetTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/POffsetTime.java index e6d226971..70c70704d 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/POffsetTime.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/POffsetTime.java @@ -7,7 +7,7 @@ import java.time.OffsetTime; * * @param the root query bean type */ -public final class POffsetTime extends PBaseNumber { +public final class POffsetTime extends PBaseTime { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PScalar.java b/ebean-querybean/src/main/java/io/ebean/typequery/PScalar.java index 7d109a6fd..6318a1b8a 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PScalar.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PScalar.java @@ -1,13 +1,12 @@ package io.ebean.typequery; /** - * Property for classes that are serialized/deserialized by - * ScalarType/AttributeConverter. + * Property for classes that are serialized/deserialized by ScalarType/AttributeConverter. * * @param the root query bean type * @param the scalar type */ -public final class PScalar extends PBaseValueEqual { +public final class PScalar extends PBaseValueEqual { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PScalarComparable.java b/ebean-querybean/src/main/java/io/ebean/typequery/PScalarComparable.java index 6da31acb2..a303e6530 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PScalarComparable.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PScalarComparable.java @@ -8,7 +8,7 @@ package io.ebean.typequery; * @param the root query bean type * @param the scalar type */ -public final class PScalarComparable> extends PBaseCompareable { +public final class PScalarComparable> extends PBaseCompareable { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PString.java b/ebean-querybean/src/main/java/io/ebean/typequery/PString.java index c37e6e8b2..a24cf1a9b 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PString.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PString.java @@ -5,7 +5,7 @@ package io.ebean.typequery; * * @param the root query bean type */ -public final class PString extends PBaseCompareable { +public final class PString extends PBaseCompareable { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/PTime.java index 62556f480..0052a8e00 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PTime.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PTime.java @@ -8,7 +8,7 @@ import java.sql.Time; * * @param the root query bean type */ -public final class PTime extends PBaseNumber { +public final class PTime extends PBaseTime { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PTimeZone.java b/ebean-querybean/src/main/java/io/ebean/typequery/PTimeZone.java index 8a8352fef..d7906bcbc 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PTimeZone.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PTimeZone.java @@ -7,7 +7,7 @@ import java.util.TimeZone; * * @param the root query bean type */ -public final class PTimeZone extends PBaseValueEqual { +public final class PTimeZone extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PUuid.java b/ebean-querybean/src/main/java/io/ebean/typequery/PUuid.java index 8f08053eb..ddf7366f2 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PUuid.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PUuid.java @@ -7,7 +7,7 @@ import java.util.UUID; * * @param the root query bean type */ -public final class PUuid extends PBaseValueEqual { +public final class PUuid extends PBaseValueEqual { /** * Construct with a property name and root instance. @@ -16,7 +16,7 @@ public final class PUuid extends PBaseValueEqual { * @param root the root query bean instance */ public PUuid(String name, R root) { - super(name , root); + super(name, root); } /** diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PZoneId.java b/ebean-querybean/src/main/java/io/ebean/typequery/PZoneId.java index b057840d9..1883f87b2 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PZoneId.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PZoneId.java @@ -7,7 +7,7 @@ import java.time.ZoneId; * * @param the root query bean type */ -public final class PZoneId extends PBaseValueEqual { +public final class PZoneId extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PZoneOffset.java b/ebean-querybean/src/main/java/io/ebean/typequery/PZoneOffset.java index c94a99cc2..82113780d 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PZoneOffset.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PZoneOffset.java @@ -7,7 +7,7 @@ import java.time.ZoneOffset; * * @param the root query bean type */ -public final class PZoneOffset extends PBaseValueEqual { +public final class PZoneOffset extends PBaseString { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/PZonedDateTime.java b/ebean-querybean/src/main/java/io/ebean/typequery/PZonedDateTime.java index 3aca1d178..e8d2aa072 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/PZonedDateTime.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/PZonedDateTime.java @@ -7,7 +7,7 @@ import java.time.ZonedDateTime; * * @param the root query bean type */ -public final class PZonedDateTime extends PBaseCompareable { +public final class PZonedDateTime extends PBaseDate { /** * Construct with a property name and root instance. @@ -26,25 +26,4 @@ public final class PZonedDateTime extends PBaseCompareable super(name, root, prefix); } - /** - * Same as greater than. - * - * @param value the equal to bind value - * @return the root query bean instance - */ - public R after(ZonedDateTime value) { - expr().gt(_name, value); - return _root; - } - - /** - * Same as less than. - * - * @param value the equal to bind value - * @return the root query bean instance - */ - public R before(ZonedDateTime value) { - expr().lt(_name, value); - return _root; - } } diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java index 194dcd4f4..1a7372ebc 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQAssocBean.java @@ -17,7 +17,7 @@ import java.util.Set; * @param the specific root query bean type (e.g. QCustomer) */ @SuppressWarnings("rawtypes") -public abstract class TQAssocBean extends TQProperty { +public abstract class TQAssocBean extends TQProperty { private static final FetchConfig FETCH_DEFAULT = FetchConfig.ofDefault(); private static final FetchConfig FETCH_QUERY = FetchConfig.ofQuery(); @@ -111,7 +111,7 @@ public abstract class TQAssocBean extends TQProperty { * Eagerly fetch this association fetching some of the properties. */ @SafeVarargs - protected final R fetchProperties(TQProperty... props) { + protected final R fetchProperties(TQProperty... props) { return fetchWithProperties(FETCH_DEFAULT, props); } @@ -119,7 +119,7 @@ public abstract class TQAssocBean extends TQProperty { * Eagerly fetch query this association fetching some of the properties. */ @SafeVarargs - protected final R fetchQueryProperties(TQProperty... props) { + protected final R fetchQueryProperties(TQProperty... props) { return fetchWithProperties(FETCH_QUERY, props); } @@ -127,7 +127,7 @@ public abstract class TQAssocBean extends TQProperty { * Eagerly fetch this association using L2 bean cache. */ @SafeVarargs - protected final R fetchCacheProperties(TQProperty... props) { + protected final R fetchCacheProperties(TQProperty... props) { return fetchWithProperties(FETCH_CACHE, props); } @@ -135,12 +135,12 @@ public abstract class TQAssocBean extends TQProperty { * Eagerly fetch query this association fetching some of the properties. */ @SafeVarargs - protected final R fetchLazyProperties(TQProperty... props) { + protected final R fetchLazyProperties(TQProperty... props) { return fetchWithProperties(FETCH_LAZY, props); } @SafeVarargs - private R fetchWithProperties(FetchConfig config, TQProperty... props) { + private R fetchWithProperties(FetchConfig config, TQProperty... props) { spiQuery().fetchProperties(_name, properties(props), config); return _root; } @@ -173,13 +173,13 @@ public abstract class TQAssocBean extends TQProperty { } private SpiQueryFetch spiQuery() { - return (SpiQueryFetch)((TQRootBean) _root).query(); + return (SpiQueryFetch) ((TQRootBean) _root).query(); } @SafeVarargs - private Set properties(TQProperty... props) { + private Set properties(TQProperty... props) { Set set = new LinkedHashSet<>(); - for (TQProperty prop : props) { + for (TQProperty prop : props) { set.add(prop.propertyName()); } return set; diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQProperty.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQProperty.java index 8cc0e6465..79c4a2cc5 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQProperty.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQProperty.java @@ -6,12 +6,12 @@ import io.ebean.Query; /** * A property used in type query. * - * @param The type of the owning root bean + * @param The type of the owning root bean + * @param The base type, one of String, Number, Temporal, Boolean, Object. */ -public class TQProperty implements Query.Property { +public class TQProperty implements Query.Property { protected final String _name; - protected final R _root; /** @@ -41,7 +41,7 @@ public class TQProperty implements Query.Property { * Internal method to return the underlying expression list. */ protected final ExpressionList expr() { - return ((TQRootBean) _root).peekExprList(); + return ((TQRootBean) _root).peekExprList(); } /** diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQPropertyBase.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQPropertyBase.java index 83a23e6ab..2a3937be4 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQPropertyBase.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQPropertyBase.java @@ -3,9 +3,10 @@ package io.ebean.typequery; /** * Base scalar property. * - * @param The type of the owning root bean + * @param The type of the owning root bean + * @param The base type of the property */ -public class TQPropertyBase extends TQProperty { +public abstract class TQPropertyBase extends TQProperty { /** * Construct with a property name and root instance. diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java index e9dc8d590..422110abc 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -263,14 +263,14 @@ public abstract class TQRootBean { * @param properties the list of properties to fetch */ @SafeVarargs - public final R select(TQProperty... properties) { + public final R select(TQProperty... properties) { ((SpiQueryFetch) query).selectProperties(properties(properties)); return root; } - private Set properties(Query.Property[] properties) { + private Set properties(Query.Property[] properties) { Set props = new LinkedHashSet<>(); - for (Query.Property property : properties) { + for (Query.Property property : properties) { props.add(property.toString()); } return props; diff --git a/ebean-querybean/src/test/java/org/querytest/QOrderTest.java b/ebean-querybean/src/test/java/org/querytest/QOrderTest.java index fa17ca5a5..2ed846c0a 100644 --- a/ebean-querybean/src/test/java/org/querytest/QOrderTest.java +++ b/ebean-querybean/src/test/java/org/querytest/QOrderTest.java @@ -261,7 +261,7 @@ public class QOrderTest { .add(gt(coalesce(o.customer.version, 0), 42)) .id.lt(12) .endOr() - .query(); + .query(); query.findList(); diff --git a/ebean-test/src/test/java/org/tests/query/TestStdFunctions.java b/ebean-test/src/test/java/org/tests/query/TestStdFunctions.java index 27ff61760..940af117a 100644 --- a/ebean-test/src/test/java/org/tests/query/TestStdFunctions.java +++ b/ebean-test/src/test/java/org/tests/query/TestStdFunctions.java @@ -15,8 +15,7 @@ public class TestStdFunctions { @Test void coalesceLike() { - var name = Query.Property.of("name"); - + Query.Property name = Query.Property.of("name"); var query = DB.find(Customer.class) .select(coalesce(name, "na").toString()) .where() diff --git a/kotlin-querybean-generator/pom.xml b/kotlin-querybean-generator/pom.xml index e9aaa3790..a74fe64bf 100644 --- a/kotlin-querybean-generator/pom.xml +++ b/kotlin-querybean-generator/pom.xml @@ -113,7 +113,7 @@ io.ebean kotlin-querybean-generator - 13.7.0 + 13.10.2-SNAPSHOT diff --git a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java index 03837a21a..f3da81840 100644 --- a/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java +++ b/kotlin-querybean-generator/src/main/java/io/ebean/querybean/generator/KotlinLangAdapter.java @@ -14,7 +14,6 @@ class KotlinLangAdapter implements LangAdapter { @Override public void alias(Append writer, String shortName) { - writer.append(" companion object {").eol(); writer.append(" /**").eol(); writer.append(" * shared 'Alias' instance used to provide").eol(); @@ -33,7 +32,6 @@ class KotlinLangAdapter implements LangAdapter { @Override public void assocBeanConstructor(Append writer, String shortName) { - writer.append(" constructor(name: String, root: R) : super(name, root)").eol(); writer.eol(); writer.append(" constructor(name: String, root: R, prefix: String) : super(name, root, prefix)").eol(); @@ -41,7 +39,6 @@ class KotlinLangAdapter implements LangAdapter { @Override public void fetch(Append writer, String origShortName) { - writeAssocBeanFetch(writer, origShortName, "", "Eagerly fetch this association loading the specified properties."); writeAssocBeanFetch(writer, origShortName, "Query", "Eagerly fetch this association using a 'query join' loading the specified properties."); writeAssocBeanFetch(writer, origShortName, "Cache", "Eagerly fetch this association using L2 cache."); @@ -49,26 +46,21 @@ class KotlinLangAdapter implements LangAdapter { } private void writeAssocBeanFetch(Append writer, String origShortName, String fetchType, String comment) { - -// fun fetch(vararg properties: TQProperty): R { +// fun fetch(vararg properties: TQProperty): R { // return fetchProperties(*properties) // } - writer.append(" /**").eol(); writer.append(" * ").append(comment).eol(); writer.append(" */").eol(); - writer.append(" fun fetch%s(vararg properties: TQProperty) : R {", fetchType, origShortName).eol(); + writer.append(" fun fetch%s(vararg properties: TQProperty) : R {", fetchType, origShortName).eol(); writer.append(" return fetch%sProperties(*properties)", fetchType).eol(); writer.append(" }").eol(); writer.eol(); } - @Override public void rootBeanConstructor(Append writer, String shortName, String dbName) { - String name = (dbName == null) ? "default" : dbName; - writer.append(" /**").eol(); writer.append(" * Construct using the %s Database.", name).eol(); writer.append(" */").eol(); @@ -106,7 +98,6 @@ class KotlinLangAdapter implements LangAdapter { @Override public void fieldDefn(Append writer, String propertyName, String typeDefn) { - writer.append(" lateinit var %s: ", propertyName); if (typeDefn.endsWith(",Integer>")) { typeDefn = typeDefn.replace(",Integer>", ",Int>"); diff --git a/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java b/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java index f8e965f04..75400b935 100644 --- a/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java +++ b/querybean-generator/src/main/java/io/ebean/querybean/generator/SimpleQueryBeanWriter.java @@ -275,7 +275,7 @@ class SimpleQueryBeanWriter { writer.append(" * ").append(comment).eol(); writer.append(" */").eol(); writer.append(" @SafeVarargs @SuppressWarnings(\"varargs\")").eol(); - writer.append(" public final R fetch%s(TQProperty... properties) {", fetchType, origShortName).eol(); + writer.append(" public final R fetch%s(TQProperty... properties) {", fetchType, origShortName).eol(); writer.append(" return fetch%sProperties(properties);", fetchType).eol(); writer.append(" }").eol(); writer.eol();