mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-21 06:41:12 +00:00
#2716 - Refactor ScalarType interface to make use of default methods
This commit is contained in:
@@ -16,25 +16,24 @@ import java.sql.SQLException;
|
||||
* <p>
|
||||
* Scalar in the sense that the types are not compound types. Scalar types only
|
||||
* map to a single database column.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that Booleans may be native for some databases and require conversion on
|
||||
* other databases.
|
||||
* </p>
|
||||
*/
|
||||
public interface ScalarType<T> extends StringParser, StringFormatter, ScalarDataReader<T> {
|
||||
|
||||
/**
|
||||
* Return true for types that do mutation detection based on json content.
|
||||
*/
|
||||
default boolean isJsonMapper() {
|
||||
return false;
|
||||
}
|
||||
@@ -43,38 +42,40 @@ public interface ScalarType<T> 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.
|
||||
* <p>
|
||||
* If a BeanProperty has no explicit length defined then this length should
|
||||
* be assigned.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is primarily to support defining a length on Enum types (to
|
||||
* supplement defining the length on the BeanProperty directly).
|
||||
* </p>
|
||||
*/
|
||||
int getLength();
|
||||
default int getLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the type is native to JDBC.
|
||||
* <p>
|
||||
* If it is native to JDBC then its values/instances do not need to be
|
||||
* converted to and from an associated JDBC type.
|
||||
* </p>
|
||||
*/
|
||||
boolean isJdbcNative();
|
||||
|
||||
@@ -83,16 +84,13 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
* <p>
|
||||
* This type should be consistent with the toJdbcType() method in converting
|
||||
* the type to the appropriate type for binding to preparedStatements.
|
||||
* </p>
|
||||
*/
|
||||
int getJdbcType();
|
||||
|
||||
/**
|
||||
* Return the type that matches the bean property type.
|
||||
* <p>
|
||||
* This represents the 'logical' type rather than the JDBC type this maps
|
||||
* to.
|
||||
* </p>
|
||||
* This represents the 'logical' type rather than the JDBC type this maps to.
|
||||
*/
|
||||
Class<T> getType();
|
||||
|
||||
@@ -104,7 +102,7 @@ public interface ScalarType<T> 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<T> extends StringParser, StringFormatter, ScalarData
|
||||
* <p>
|
||||
* value may need to be converted from the logical bean property type to the
|
||||
* JDBC type.
|
||||
* </p>
|
||||
*/
|
||||
void bind(DataBinder binder, T value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Convert the value as necessary to the JDBC type.
|
||||
* <p>
|
||||
* Note that this should also match the type as per the getJdbcType()
|
||||
* method.
|
||||
* </p>
|
||||
* Note that this should also match the type as per the getJdbcType() method.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
Object toJdbcType(Object value);
|
||||
|
||||
@@ -135,19 +129,14 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
* Convert the value as necessary to the logical Bean type.
|
||||
* <p>
|
||||
* The type as per the bean property.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is used to automatically convert id values (typically from a string
|
||||
* to a int, long or UUID).
|
||||
* </p>
|
||||
*/
|
||||
T toBeanType(Object value);
|
||||
|
||||
/**
|
||||
* Convert the type into a string representation.
|
||||
* <p>
|
||||
* Reciprocal of parse().
|
||||
* </p>
|
||||
*/
|
||||
String formatValue(T value);
|
||||
|
||||
@@ -155,10 +144,8 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
* Convert the type into a string representation.
|
||||
* <p>
|
||||
* This assumes the value is of the correct type.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is so that ScalarType also implements the StringFormatter interface.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
String format(Object value);
|
||||
@@ -167,10 +154,6 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
* Convert the string value to the appropriate java object.
|
||||
* <p>
|
||||
* Mostly used to support CSV, JSON and XML parsing.
|
||||
* </p>
|
||||
* <p>
|
||||
* Reciprocal of formatValue().
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
T parse(String value);
|
||||
@@ -183,29 +166,32 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
|
||||
/**
|
||||
* Return true if the type can accept long systemTimeMillis input.
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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).
|
||||
* </p>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* For non dateTime types this will throw an exception.
|
||||
* </p>
|
||||
*/
|
||||
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<T> 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.
|
||||
|
||||
@@ -18,41 +18,6 @@ abstract class ScalarTypeBase<T> implements ScalarType<T> {
|
||||
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;
|
||||
|
||||
@@ -88,16 +88,6 @@ abstract class ScalarTypeBaseVarchar<T> extends ScalarTypeBase<T> {
|
||||
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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -85,16 +85,6 @@ final class ScalarTypeByte extends ScalarTypeBase<Byte> {
|
||||
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()) {
|
||||
|
||||
@@ -59,16 +59,6 @@ public abstract class ScalarTypeBytesBase extends ScalarTypeBase<byte[]> {
|
||||
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()) {
|
||||
|
||||
@@ -26,26 +26,11 @@ public final class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
|
||||
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);
|
||||
|
||||
@@ -93,16 +93,6 @@ class ScalarTypeDuration extends ScalarTypeBase<Duration> {
|
||||
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());
|
||||
|
||||
@@ -30,11 +30,6 @@ public final class ScalarTypeEncryptedWrapper<T> implements ScalarType<T>, Local
|
||||
return dataEncryptSupport.encryptObject(formatValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asVersion(T value) {
|
||||
throw new RuntimeException("not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBinaryType() {
|
||||
return wrapped.isBinaryType();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -129,16 +129,6 @@ final class ScalarTypeFile extends ScalarTypeBase<File> {
|
||||
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
|
||||
|
||||
@@ -80,16 +80,6 @@ abstract class ScalarTypeJsonCollection<T> extends ScalarTypeBase<T> 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()) {
|
||||
|
||||
@@ -215,16 +215,6 @@ abstract class ScalarTypeJsonMap extends ScalarTypeBase<Map> {
|
||||
}
|
||||
}
|
||||
|
||||
@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()) {
|
||||
|
||||
@@ -167,16 +167,6 @@ abstract class ScalarTypeJsonNode extends ScalarTypeBase<JsonNode> {
|
||||
}
|
||||
}
|
||||
|
||||
@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()) {
|
||||
|
||||
+5
-25
@@ -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);
|
||||
|
||||
@@ -78,16 +78,6 @@ final class ScalarTypeMonthDay extends ScalarTypeBase<MonthDay> {
|
||||
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()) {
|
||||
|
||||
@@ -22,25 +22,6 @@ class ScalarTypeNotFound implements ScalarType<Void> {
|
||||
|
||||
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<Void> {
|
||||
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();
|
||||
|
||||
@@ -82,16 +82,6 @@ final class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
|
||||
}
|
||||
}
|
||||
|
||||
@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()) {
|
||||
|
||||
@@ -57,16 +57,6 @@ final class ScalarTypeShort extends ScalarTypeBase<Short> {
|
||||
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()) {
|
||||
|
||||
@@ -25,16 +25,6 @@ abstract class ScalarTypeUUIDBase extends ScalarTypeBase<UUID> 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<UUID> 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);
|
||||
|
||||
@@ -44,8 +44,7 @@ public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
|
||||
|
||||
@Override
|
||||
public long asVersion(B value) {
|
||||
S unwrapValue = converter.unwrapValue(value);
|
||||
return scalarType.asVersion(unwrapValue);
|
||||
return scalarType.asVersion(converter.unwrapValue(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,16 +81,6 @@ final class ScalarTypeYear extends ScalarTypeBase<Year> {
|
||||
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());
|
||||
|
||||
@@ -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<Duration> jsonTester = new JsonTester<>(type);
|
||||
jsonTester.test(duration);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-15
@@ -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<Duration> jsonTester = new JsonTester<>(type);
|
||||
|
||||
@@ -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<Year> jsonTester = new JsonTester<>(type);
|
||||
jsonTester.test(Year.of(2013));
|
||||
}
|
||||
|
||||
@@ -86,26 +86,6 @@ abstract class ScalarTypePgisBase<T extends Geometry> implements ScalarType<T> {
|
||||
|
||||
}
|
||||
|
||||
@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<T extends Geometry> implements ScalarType<T> {
|
||||
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;
|
||||
|
||||
@@ -77,26 +77,6 @@ abstract class ScalarTypeGeoLatteBase<T extends Geometry> 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<T extends Geometry> 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;
|
||||
|
||||
Reference in New Issue
Block a user