From 5be3b7717c11a811cdc14fe36ce6df78a1da7452 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Mon, 13 Jun 2022 22:38:15 +1200 Subject: [PATCH] #2716 - Refactor ScalarType interface to make use of default methods --- .../java/io/ebean/core/type/ScalarType.java | 72 ++++++++----------- .../server/type/ScalarTypeBase.java | 35 --------- .../server/type/ScalarTypeBaseVarchar.java | 10 --- .../server/type/ScalarTypeBoolean.java | 11 --- .../server/type/ScalarTypeByte.java | 10 --- .../server/type/ScalarTypeBytesBase.java | 10 --- .../server/type/ScalarTypeBytesEncrypted.java | 15 ---- .../server/type/ScalarTypeDuration.java | 10 --- .../type/ScalarTypeEncryptedWrapper.java | 5 -- .../server/type/ScalarTypeEnumStandard.java | 10 --- .../type/ScalarTypeEnumWithMapping.java | 10 --- .../server/type/ScalarTypeFile.java | 10 --- .../server/type/ScalarTypeJsonCollection.java | 10 --- .../server/type/ScalarTypeJsonMap.java | 10 --- .../server/type/ScalarTypeJsonNode.java | 10 --- .../type/ScalarTypeJsonObjectMapper.java | 30 ++------ .../server/type/ScalarTypeMonthDay.java | 10 --- .../server/type/ScalarTypeNotFound.java | 34 --------- .../server/type/ScalarTypePostgresHstore.java | 10 --- .../server/type/ScalarTypeShort.java | 10 --- .../server/type/ScalarTypeUUIDBase.java | 20 ------ .../server/type/ScalarTypeWrapper.java | 3 +- .../server/type/ScalarTypeYear.java | 10 --- .../server/type/ScalarTypeDurationTest.java | 27 +++---- .../type/ScalarTypeDurationWithNanosTest.java | 25 +++---- .../server/type/ScalarTypeYearTest.java | 23 +++--- .../io/ebean/postgis/ScalarTypePgisBase.java | 36 ---------- .../postgis/latte/ScalarTypeGeoLatteBase.java | 35 --------- 28 files changed, 65 insertions(+), 446 deletions(-) diff --git a/ebean-core-type/src/main/java/io/ebean/core/type/ScalarType.java b/ebean-core-type/src/main/java/io/ebean/core/type/ScalarType.java index 6c01811c5..af3e73493 100644 --- a/ebean-core-type/src/main/java/io/ebean/core/type/ScalarType.java +++ b/ebean-core-type/src/main/java/io/ebean/core/type/ScalarType.java @@ -16,25 +16,24 @@ import java.sql.SQLException; *

* Scalar in the sense that the types are not compound types. Scalar types only * map to a single database column. - *

*

* These types fall into two categories. Types that are mapped natively to JDBC * types and the rest. Types that map to native JDBC types do not require any * data type conversion to be persisted to the database. These are java types * that map via java.sql.Types. - *

*

* Types that are not native to JDBC require some conversion. These include some * common java types such as java.util.Date, java.util.Calendar, * java.math.BigInteger. - *

*

* Note that Booleans may be native for some databases and require conversion on * other databases. - *

*/ public interface ScalarType extends StringParser, StringFormatter, ScalarDataReader { + /** + * Return true for types that do mutation detection based on json content. + */ default boolean isJsonMapper() { return false; } @@ -43,38 +42,40 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData * Return true if this is a binary type and can not support parse() and format() from/to string. * This allows Ebean to optimise marshalling types to string. */ - boolean isBinaryType(); + default boolean isBinaryType() { + return false; + } /** * Return true if this is a mutable scalar type (like hstore). */ - boolean isMutable(); + default boolean isMutable() { + return false; + } /** * For mutable scalarType's return true if the value is dirty. * Non-dirty properties may be excluded from updates. */ - boolean isDirty(Object value); + default boolean isDirty(Object value) { + return false; + } /** * Return the default DB column length for this type. *

* If a BeanProperty has no explicit length defined then this length should * be assigned. - *

- *

- * This is primarily to support defining a length on Enum types (to - * supplement defining the length on the BeanProperty directly). - *

*/ - int getLength(); + default int getLength() { + return 0; + } /** * Return true if the type is native to JDBC. *

* If it is native to JDBC then its values/instances do not need to be * converted to and from an associated JDBC type. - *

*/ boolean isJdbcNative(); @@ -83,16 +84,13 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData *

* This type should be consistent with the toJdbcType() method in converting * the type to the appropriate type for binding to preparedStatements. - *

*/ int getJdbcType(); /** * Return the type that matches the bean property type. *

- * This represents the 'logical' type rather than the JDBC type this maps - * to. - *

+ * This represents the 'logical' type rather than the JDBC type this maps to. */ Class getType(); @@ -104,7 +102,7 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData T read(DataReader reader) throws SQLException; /** - * Ignore the reading of this value. Typically this means moving the index + * Ignore the reading of this value. Typically, this means moving the index * position in the ResultSet. */ void loadIgnore(DataReader reader); @@ -114,20 +112,16 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData *

* value may need to be converted from the logical bean property type to the * JDBC type. - *

*/ void bind(DataBinder binder, T value) throws SQLException; /** * Convert the value as necessary to the JDBC type. *

- * Note that this should also match the type as per the getJdbcType() - * method. - *

+ * Note that this should also match the type as per the getJdbcType() method. *

* This is typically used when the matching type is used in a where clause * and we use this to ensure it is an appropriate jdbc type. - *

*/ Object toJdbcType(Object value); @@ -135,19 +129,14 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData * Convert the value as necessary to the logical Bean type. *

* The type as per the bean property. - *

*

* This is used to automatically convert id values (typically from a string * to a int, long or UUID). - *

*/ T toBeanType(Object value); /** * Convert the type into a string representation. - *

- * Reciprocal of parse(). - *

*/ String formatValue(T value); @@ -155,10 +144,8 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData * Convert the type into a string representation. *

* This assumes the value is of the correct type. - *

*

* This is so that ScalarType also implements the StringFormatter interface. - *

*/ @Override String format(Object value); @@ -167,10 +154,6 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData * Convert the string value to the appropriate java object. *

* Mostly used to support CSV, JSON and XML parsing. - *

- *

- * Reciprocal of formatValue(). - *

*/ @Override T parse(String value); @@ -183,29 +166,32 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData /** * Return true if the type can accept long systemTimeMillis input. *

- * This is used to determine if is is sensible to use the + * This is used to determine if it is sensible to use the * {@link #convertFromMillis(long)} method. - *

*

* This includes the Date, Calendar, sql Date, Time, Timestamp, JODA types * as well as Long, BigDecimal and String (although it generally is not * expected to parse systemTimeMillis to a String or BigDecimal). - *

*/ - boolean isDateTimeCapable(); + default boolean isDateTimeCapable() { + return false; + } /** * Convert the value into a long version value. */ - long asVersion(T value); + default long asVersion(T value) { + throw new UnsupportedOperationException(); + } /** * Convert the systemTimeMillis into the appropriate java object. *

* For non dateTime types this will throw an exception. - *

*/ - T convertFromMillis(long dateTime); + default T convertFromMillis(long dateTime) { + throw new UnsupportedOperationException(); + } /** * Read the value from binary input. @@ -215,7 +201,7 @@ public interface ScalarType extends StringParser, StringFormatter, ScalarData /** * Write the value to binary output. */ - void writeData(DataOutput dataOutput, T v) throws IOException; + void writeData(DataOutput dataOutput, T value) throws IOException; /** * Read the value from JsonParser. diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBase.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBase.java index 5d2bb45e9..93ab0a6a6 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBase.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBase.java @@ -18,41 +18,6 @@ abstract class ScalarTypeBase implements ScalarType { this.jdbcType = jdbcType; } - @Override - public long asVersion(T value) { - throw new RuntimeException("not supported"); - } - - @Override - public boolean isBinaryType() { - // override for binary/byte based types - return false; - } - - /** - * Default implementation of mutable false. - */ - @Override - public boolean isMutable() { - return false; - } - - /** - * Default to true. - */ - @Override - public boolean isDirty(Object value) { - return true; - } - - /** - * Just return 0. - */ - @Override - public int getLength() { - return 0; - } - @Override public boolean isJdbcNative() { return jdbcNative; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBaseVarchar.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBaseVarchar.java index 7fd7d974e..75eaa17b5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBaseVarchar.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBaseVarchar.java @@ -88,16 +88,6 @@ abstract class ScalarTypeBaseVarchar extends ScalarTypeBase { return format(value); } - @Override - public T convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override @SuppressWarnings("unchecked") public String format(Object value) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBoolean.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBoolean.java index 56bc180a9..848b0fc2a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBoolean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBoolean.java @@ -234,7 +234,6 @@ public final class ScalarTypeBoolean { @Override public int getLength() { - // typically this will return 1 return Math.max(trueValue.length(), falseValue.length()); } @@ -329,16 +328,6 @@ public final class ScalarTypeBoolean { return Boolean.valueOf(value); } - @Override - public Boolean convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public Boolean readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeByte.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeByte.java index 250bb1006..5437ecb77 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeByte.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeByte.java @@ -85,16 +85,6 @@ final class ScalarTypeByte extends ScalarTypeBase { throw new TextException("Not supported"); } - @Override - public Byte convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public Byte readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesBase.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesBase.java index 437c626f8..51f811ede 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesBase.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesBase.java @@ -59,16 +59,6 @@ public abstract class ScalarTypeBytesBase extends ScalarTypeBase { throw new TextException("Not supported"); } - @Override - public byte[] convertFromMillis(long systemTimeMillis) { - throw new TextException("Not supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public byte[] readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java index df8b32ba9..ec753b307 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java @@ -26,26 +26,11 @@ public final class ScalarTypeBytesEncrypted implements ScalarType { this.dataEncryptSupport = dataEncryptSupport; } - @Override - public long asVersion(byte[] value) { - throw new RuntimeException("not supported"); - } - @Override public boolean isBinaryType() { return true; } - @Override - public boolean isMutable() { - return false; - } - - @Override - public boolean isDirty(Object value) { - return false; - } - @Override public void bind(DataBinder binder, byte[] value) throws SQLException { value = dataEncryptSupport.encrypt(value); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeDuration.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeDuration.java index 8e34afe27..5daff6f4c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeDuration.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeDuration.java @@ -93,16 +93,6 @@ class ScalarTypeDuration extends ScalarTypeBase { return Duration.parse(value); } - @Override - public boolean isDateTimeCapable() { - return false; - } - - @Override - public Duration convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - @Override public Duration jsonRead(JsonParser parser) throws IOException { return Duration.parse(parser.getValueAsString()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java index 1a552d11a..392fc1b86 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java @@ -30,11 +30,6 @@ public final class ScalarTypeEncryptedWrapper implements ScalarType, Local return dataEncryptSupport.encryptObject(formatValue); } - @Override - public long asVersion(T value) { - throw new RuntimeException("not supported"); - } - @Override public boolean isBinaryType() { return wrapped.isBinaryType(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumStandard.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumStandard.java index 969bfd016..d33b06af4 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumStandard.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumStandard.java @@ -229,16 +229,6 @@ final class ScalarTypeEnumStandard { return Enum.valueOf(enumType, value); } - @Override - public Object convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public Object jsonRead(JsonParser parser) throws IOException { if (parser.getCodec() != null) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java index cafee64f7..287c11f60 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java @@ -39,16 +39,6 @@ class ScalarTypeEnumWithMapping extends ScalarTypeEnumStandard.EnumBase implemen return enumType == null; } - @Override - public long asVersion(Object value) { - throw new RuntimeException("not supported"); - } - - @Override - public boolean isBinaryType() { - return false; - } - /** * Return the IN values for DB constraint construction. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java index d5f500d78..be712b659 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java @@ -129,16 +129,6 @@ final class ScalarTypeFile extends ScalarTypeBase { throw new TextException("Not supported"); } - @Override - public File convertFromMillis(long systemTimeMillis) { - throw new TextException("Not supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public File readData(DataInput dataInput) throws IOException { // skip reading large file diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java index e40e1a9ae..e78f6b02d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java @@ -80,16 +80,6 @@ abstract class ScalarTypeJsonCollection extends ScalarTypeBase implements return docPropertyType; } - @Override - public boolean isDateTimeCapable() { - return false; - } - - @Override - public T convertFromMillis(long dateTime) { - return null; - } - @Override public T readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java index b5942289e..96030c23f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java @@ -215,16 +215,6 @@ abstract class ScalarTypeJsonMap extends ScalarTypeBase { } } - @Override - public final Map convertFromMillis(long dateTime) { - throw new RuntimeException("Should never be called"); - } - - @Override - public final boolean isDateTimeCapable() { - return false; - } - @Override public final Map readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonNode.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonNode.java index 8d2501f04..5efcb2c7b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonNode.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonNode.java @@ -167,16 +167,6 @@ abstract class ScalarTypeJsonNode extends ScalarTypeBase { } } - @Override - public JsonNode convertFromMillis(long dateTime) { - throw new RuntimeException("Should never be called"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public JsonNode readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java index 3a863df1e..94bfd4c88 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonObjectMapper.java @@ -55,16 +55,6 @@ final class ScalarTypeJsonObjectMapper { NoMutationDetection(TypeJsonManager jsonManager, AnnotatedField field, int dbType, DocPropertyType docType) { super(Object.class, jsonManager, field, dbType, docType); } - - @Override - public boolean isMutable() { - return false; - } - - @Override - public boolean isDirty(Object value) { - return false; - } } /** @@ -79,6 +69,11 @@ final class ScalarTypeJsonObjectMapper { this.jsonb = "jsonb".equals(pgType); } + @Override + public boolean isMutable() { + return true; + } + @Override public boolean isJsonMapper() { return true; @@ -144,11 +139,6 @@ final class ScalarTypeJsonObjectMapper { this.objectWriter = helper.objectWriter(); } - @Override - public boolean isMutable() { - return true; - } - @Override public T read(DataReader reader) throws SQLException { String json = reader.getString(); @@ -212,16 +202,6 @@ final class ScalarTypeJsonObjectMapper { return docType; } - @Override - public final boolean isDateTimeCapable() { - return false; - } - - @Override - public final T convertFromMillis(long dateTime) { - throw new IllegalStateException("Not supported"); - } - @Override public final T jsonRead(JsonParser parser) throws IOException { return objectReader.readValue(parser, deserType); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeMonthDay.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeMonthDay.java index eb26a84b9..f655894ee 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeMonthDay.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeMonthDay.java @@ -78,16 +78,6 @@ final class ScalarTypeMonthDay extends ScalarTypeBase { return MonthDay.parse(value); } - @Override - public boolean isDateTimeCapable() { - return false; - } - - @Override - public MonthDay convertFromMillis(long dateTime) { - throw new RuntimeException("Not supported on this type"); - } - @Override public MonthDay readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeNotFound.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeNotFound.java index 7fbb5b5e9..ef0495296 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeNotFound.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeNotFound.java @@ -22,25 +22,6 @@ class ScalarTypeNotFound implements ScalarType { public static final ScalarTypeNotFound INSTANCE = new ScalarTypeNotFound(); private ScalarTypeNotFound() { } - @Override - public boolean isBinaryType() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isMutable() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean isDirty(Object value) { - throw new UnsupportedOperationException(); - } - - @Override - public int getLength() { - throw new UnsupportedOperationException(); - } @Override public boolean isJdbcNative() { @@ -102,21 +83,6 @@ class ScalarTypeNotFound implements ScalarType { throw new UnsupportedOperationException(); } - @Override - public boolean isDateTimeCapable() { - throw new UnsupportedOperationException(); - } - - @Override - public long asVersion(Void value) { - throw new UnsupportedOperationException(); - } - - @Override - public Void convertFromMillis(long dateTime) { - throw new UnsupportedOperationException(); - } - @Override public Void readData(DataInput dataInput) throws IOException { throw new UnsupportedOperationException(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java index 69b3d8a5b..2f33dc929 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypePostgresHstore.java @@ -82,16 +82,6 @@ final class ScalarTypePostgresHstore extends ScalarTypeBase { } } - @Override - public Map convertFromMillis(long dateTime) { - throw new RuntimeException("Should never be called"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public Map readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeShort.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeShort.java index b3205b747..11bfa7b22 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeShort.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeShort.java @@ -57,16 +57,6 @@ final class ScalarTypeShort extends ScalarTypeBase { return Short.valueOf(value); } - @Override - public Short convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public Short readData(DataInput dataInput) throws IOException { if (!dataInput.readBoolean()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDBase.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDBase.java index 7da989b82..db003d526 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDBase.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDBase.java @@ -25,16 +25,6 @@ abstract class ScalarTypeUUIDBase extends ScalarTypeBase implements Scalar return DbPlatformType.UUID; } - @Override - public boolean isMutable() { - return false; - } - - @Override - public boolean isDirty(Object value) { - return true; - } - @Override public String format(Object value) { return String.valueOf(value); @@ -50,16 +40,6 @@ abstract class ScalarTypeUUIDBase extends ScalarTypeBase implements Scalar return UUID.fromString(value); } - @Override - public UUID convertFromMillis(long dateTime) { - throw new RuntimeException("Should never be called"); - } - - @Override - public boolean isDateTimeCapable() { - return false; - } - @Override public UUID toBeanType(Object value) { return BasicTypeConverter.toUUID(value, false); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeWrapper.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeWrapper.java index 1ce79bec0..f0e83bed3 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeWrapper.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeWrapper.java @@ -44,8 +44,7 @@ public class ScalarTypeWrapper implements ScalarType { @Override public long asVersion(B value) { - S unwrapValue = converter.unwrapValue(value); - return scalarType.asVersion(unwrapValue); + return scalarType.asVersion(converter.unwrapValue(value)); } @Override diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeYear.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeYear.java index c515de0e3..7d19c248c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeYear.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeYear.java @@ -81,16 +81,6 @@ final class ScalarTypeYear extends ScalarTypeBase { return Year.parse(value); } - @Override - public boolean isDateTimeCapable() { - return false; - } - - @Override - public Year convertFromMillis(long systemTimeMillis) { - throw new TextException("Not Supported"); - } - @Override public Year jsonRead(JsonParser parser) throws IOException { return Year.of(parser.getIntValue()); diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationTest.java index 1a57f6080..1a8fb3218 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationTest.java @@ -1,6 +1,5 @@ package io.ebeaninternal.server.type; -import io.ebean.text.TextException; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; @@ -11,13 +10,12 @@ import java.time.Duration; import static org.junit.jupiter.api.Assertions.*; -public class ScalarTypeDurationTest { +class ScalarTypeDurationTest { ScalarTypeDuration type = new ScalarTypeDuration(); @Test - public void testReadData() throws Exception { - + void testReadData() throws Exception { Duration duration = Duration.ofSeconds(1234); ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -39,8 +37,7 @@ public class ScalarTypeDurationTest { } @Test - public void testToJdbcType() throws Exception { - + void testToJdbcType() throws Exception { Duration duration = Duration.ofSeconds(1234); long seconds = duration.getSeconds(); @@ -52,8 +49,7 @@ public class ScalarTypeDurationTest { } @Test - public void testToBeanType() throws Exception { - + void testToBeanType() throws Exception { Duration duration = Duration.ofSeconds(1234); long seconds = duration.getSeconds(); @@ -67,37 +63,34 @@ public class ScalarTypeDurationTest { } @Test - public void testFormatValue() throws Exception { - + void testFormatValue() { Duration duration = Duration.ofSeconds(1234); String formatValue = type.formatValue(duration); assertEquals("PT20M34S", formatValue); } @Test - public void testParse() { + void testParse() { Duration duration = type.parse("PT20M34S"); assertEquals(Duration.ofSeconds(1234), duration); } @Test - public void testIsDateTimeCapable() { + void testIsDateTimeCapable() { assertFalse(type.isDateTimeCapable()); } @Test - public void testConvertFromMillis() { - assertThrows(TextException.class, () -> type.convertFromMillis(1000)); + void testConvertFromMillis() { + assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000)); } @Test - public void testJsonRead() throws Exception { - + void testJsonRead() throws Exception { Duration duration = Duration.ofSeconds(1234); JsonTester jsonTester = new JsonTester<>(type); jsonTester.test(duration); - } } diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationWithNanosTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationWithNanosTest.java index 60e4ffe29..aca406df5 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationWithNanosTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeDurationWithNanosTest.java @@ -1,6 +1,5 @@ package io.ebeaninternal.server.type; -import io.ebean.text.TextException; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; @@ -12,13 +11,12 @@ import java.time.Duration; import static org.junit.jupiter.api.Assertions.*; -public class ScalarTypeDurationWithNanosTest { +class ScalarTypeDurationWithNanosTest { ScalarTypeDurationWithNanos type = new ScalarTypeDurationWithNanos(); @Test - public void testReadData() throws Exception { - + void testReadData() throws Exception { Duration duration = Duration.ofSeconds(323, 1500000); ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -40,8 +38,7 @@ public class ScalarTypeDurationWithNanosTest { } @Test - public void testToJdbcType() throws Exception { - + void testToJdbcType() throws Exception { Duration duration = Duration.ofSeconds(323, 1500000); BigDecimal bigDecimal = DecimalUtils.toDecimal(duration); @@ -53,8 +50,7 @@ public class ScalarTypeDurationWithNanosTest { } @Test - public void testToBeanType() throws Exception { - + void testToBeanType() throws Exception { Duration duration = Duration.ofSeconds(323, 1500000); BigDecimal bigDecimal = DecimalUtils.toDecimal(duration); @@ -66,32 +62,31 @@ public class ScalarTypeDurationWithNanosTest { } @Test - public void testFormatValue() throws Exception { - + void testFormatValue() { Duration duration = Duration.ofSeconds(323, 1500000); String formatValue = type.formatValue(duration); assertEquals("PT5M23.0015S", formatValue); } @Test - public void testParse() { + void testParse() { Duration duration = Duration.ofSeconds(323, 1500000); Duration val1 = type.parse("PT5M23.0015S"); assertEquals(duration, val1); } @Test - public void testIsDateTimeCapable() { + void testIsDateTimeCapable() { assertFalse(type.isDateTimeCapable()); } @Test - public void testConvertFromMillis() { - assertThrows(TextException.class, () -> type.convertFromMillis(1000)); + void testConvertFromMillis() { + assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000)); } @Test - public void testJsonRead() throws Exception { + void testJsonRead() throws Exception { Duration duration = Duration.ofSeconds(323, 1500000); JsonTester jsonTester = new JsonTester<>(type); diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeYearTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeYearTest.java index c37282744..9a0440b67 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeYearTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/type/ScalarTypeYearTest.java @@ -11,13 +11,12 @@ import java.time.Year; import static org.junit.jupiter.api.Assertions.*; -public class ScalarTypeYearTest { +class ScalarTypeYearTest { ScalarTypeYear type = new ScalarTypeYear(); @Test - public void testReadData() throws Exception { - + void testReadData() throws Exception { ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(os); @@ -37,8 +36,7 @@ public class ScalarTypeYearTest { } @Test - public void testToJdbcType() throws Exception { - + void testToJdbcType() throws Exception { Integer year = 2013; Object val1 = type.toJdbcType(Year.of(2013)); Object val2 = type.toJdbcType(2013); @@ -50,8 +48,7 @@ public class ScalarTypeYearTest { } @Test - public void testToBeanType() throws Exception { - + void testToBeanType() throws Exception { Year year = Year.of(2013); Year val1 = type.toBeanType(year); Year val2 = type.toBeanType(2013); @@ -63,29 +60,29 @@ public class ScalarTypeYearTest { } @Test - public void testFormatValue() throws Exception { + void testFormatValue() { String formatted = type.formatValue(Year.of(2013)); assertEquals("2013", formatted); } @Test - public void testParse() { + void testParse() { Year year = type.parse("2013"); assertEquals(Year.of(2013), year); } @Test - public void testIsDateTimeCapable() { + void testIsDateTimeCapable() { assertFalse(type.isDateTimeCapable()); } @Test - public void testConvertFromMillis() { - assertThrows(TextException.class, () -> type.convertFromMillis(1000)); + void testConvertFromMillis() { + assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000)); } @Test - public void testJson() throws Exception { + void testJson() throws Exception { JsonTester jsonTester = new JsonTester<>(type); jsonTester.test(Year.of(2013)); } diff --git a/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java b/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java index adc3bbd98..d96f45476 100644 --- a/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java +++ b/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java @@ -86,26 +86,6 @@ abstract class ScalarTypePgisBase implements ScalarType { } - @Override - public boolean isBinaryType() { - return false; - } - - @Override - public boolean isMutable() { - return false; - } - - @Override - public boolean isDirty(Object value) { - return false; - } - - @Override - public int getLength() { - return 0; - } - @Override public void loadIgnore(DataReader reader) { reader.incrementPos(1); @@ -141,22 +121,6 @@ abstract class ScalarTypePgisBase implements ScalarType { return null; } - @Override - public boolean isDateTimeCapable() { - return false; - } - - @Override - public long asVersion(T value) { - return 0; - } - - @Override - public T convertFromMillis(long dateTime) { - return null; - } - - @Override public T jsonRead(JsonParser parser) { return null; diff --git a/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java b/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java index 2dd779c38..c90b887f5 100644 --- a/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java +++ b/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java @@ -77,26 +77,6 @@ abstract class ScalarTypeGeoLatteBase implements ScalarType< } - @Override - public boolean isBinaryType() { - return false; - } - - @Override - public boolean isMutable() { - return false; - } - - @Override - public boolean isDirty(Object value) { - return false; - } - - @Override - public int getLength() { - return 0; - } - @Override public void loadIgnore(DataReader reader) { reader.incrementPos(1); @@ -132,21 +112,6 @@ abstract class ScalarTypeGeoLatteBase implements ScalarType< return null; } - @Override - public boolean isDateTimeCapable() { - return false; - } - - @Override - public long asVersion(T value) { - return 0; - } - - @Override - public T convertFromMillis(long dateTime) { - return null; - } - @Override public T jsonRead(JsonParser parser) { return null;