Refactor ScalarType, remove convertFromMillis() method (no longer needed)

Due to the move and change of CsvReader using StringParser ScalarType no longer
needs that general convertFromMillis() method. Note that date and dateTime ScalarTypes
still retain this conversion method.
This commit is contained in:
Rob Bygrave committed 2022-08-25 22:37:47 +12:00
1 parent f98b6b0e2a
commit c5e8b217e3
27 files changed
+4 -139

No files matched your search

@@ -39,12 +39,6 @@ public interface ExpressionPath {
*/ */
StringParser stringParser(); StringParser stringParser();
/**
* For DateTime capable scalar types convert the long systemTimeMillis into
* an appropriate java time (Date,Timestamp,Time,Calendar, JODA type etc).
*/
Object parseDateTime(long systemTimeMillis);
/** /**
* Return the underlying JDBC type or 0 if this is not a scalar type. * Return the underlying JDBC type or 0 if this is not a scalar type.
*/ */
@@ -166,15 +166,6 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
/**
* Convert the systemTimeMillis into the appropriate java object.
* <p>
* For non dateTime types this will throw an exception.
*/
default T convertFromMillis(long dateTime) {
throw new UnsupportedOperationException();
}
/** /**
* Read the value from binary input. * Read the value from binary input.
*/ */
@@ -190,11 +190,6 @@ public final class BeanFkeyProperty implements ElPropertyValue {
return null; return null;
} }
@Override
public Object parseDateTime(long systemTimeMillis) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}
@Override @Override
public StringParser stringParser() { public StringParser stringParser() {
throw new RuntimeException("ElPropertyDeploy only - not implemented"); throw new RuntimeException("ElPropertyDeploy only - not implemented");
@@ -945,11 +945,6 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
return scalarType == null ? 0 : scalarType.jdbcType(); return scalarType == null ? 0 : scalarType.jdbcType();
} }
@Override
public Object parseDateTime(long systemTimeMillis) {
return scalarType.convertFromMillis(systemTimeMillis);
}
/** /**
* Return the DB max length (varchar) or precision (decimal). * Return the DB max length (varchar) or precision (decimal).
*/ */
@@ -232,11 +232,6 @@ public final class ElPropertyChain implements ElPropertyValue {
return scalarType == null ? 0 : scalarType.jdbcType(); return scalarType == null ? 0 : scalarType.jdbcType();
} }
@Override
public Object parseDateTime(long systemTimeMillis) {
return scalarType.convertFromMillis(systemTimeMillis);
}
@Override @Override
public StringParser stringParser() { public StringParser stringParser() {
return scalarType; return scalarType;
@@ -77,7 +77,6 @@ abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
} }
} }
@Override
public T convertFromMillis(long systemTimeMillis) { public T convertFromMillis(long systemTimeMillis) {
Date ts = new Date(systemTimeMillis); Date ts = new Date(systemTimeMillis);
return convertFromDate(ts); return convertFromDate(ts);
@@ -54,7 +54,6 @@ abstract class ScalarTypeBaseDateTime<T> extends ScalarTypeBase<T> {
/** /**
* Convert from epoch millis to the value. * Convert from epoch millis to the value.
*/ */
@Override
public abstract T convertFromMillis(long systemTimeMillis); public abstract T convertFromMillis(long systemTimeMillis);
/** /**
@@ -58,11 +58,6 @@ class ScalarTypeBigDecimal extends ScalarTypeBase<BigDecimal> {
return new BigDecimal(value); return new BigDecimal(value);
} }
@Override
public BigDecimal convertFromMillis(long systemTimeMillis) {
return BigDecimal.valueOf(systemTimeMillis);
}
@Override @Override
public BigDecimal readData(DataInput dataInput) throws IOException { public BigDecimal readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) { if (!dataInput.readBoolean()) {
@@ -84,11 +84,6 @@ public final class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
return baseType.parse(value); return baseType.parse(value);
} }
@Override
public byte[] convertFromMillis(long systemTimeMillis) {
return baseType.convertFromMillis(systemTimeMillis);
}
@Override @Override
public byte[] read(DataReader reader) throws SQLException { public byte[] read(DataReader reader) throws SQLException {
byte[] data = baseType.read(reader); byte[] data = baseType.read(reader);
@@ -57,11 +57,6 @@ final class ScalarTypeDouble extends ScalarTypeBase<Double> {
return Double.valueOf(value); return Double.valueOf(value);
} }
@Override
public Double convertFromMillis(long systemTimeMillis) {
return (double) systemTimeMillis;
}
@Override @Override
public Double readData(DataInput dataInput) throws IOException { public Double readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) { if (!dataInput.readBoolean()) {
@@ -109,11 +109,6 @@ public final class ScalarTypeEncryptedWrapper<T> implements ScalarType<T>, Local
return wrapped.parse(value); return wrapped.parse(value);
} }
@Override
public T convertFromMillis(long systemTimeMillis) {
return wrapped.convertFromMillis(systemTimeMillis);
}
@Override @Override
public T toBeanType(Object value) { public T toBeanType(Object value) {
return wrapped.toBeanType(value); return wrapped.toBeanType(value);
@@ -57,11 +57,6 @@ final class ScalarTypeFloat extends ScalarTypeBase<Float> {
return Float.valueOf(value); return Float.valueOf(value);
} }
@Override
public Float convertFromMillis(long systemTimeMillis) {
return (float) systemTimeMillis;
}
@Override @Override
public Float readData(DataInput dataInput) throws IOException { public Float readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) { if (!dataInput.readBoolean()) {
@@ -6,7 +6,6 @@ import io.ebean.core.type.DataBinder;
import io.ebean.core.type.DataReader; import io.ebean.core.type.DataReader;
import io.ebean.core.type.DocPropertyType; import io.ebean.core.type.DocPropertyType;
import io.ebean.core.type.ScalarTypeBase; import io.ebean.core.type.ScalarTypeBase;
import io.ebean.text.TextException;
import io.ebeaninternal.server.core.BasicTypeConverter; import io.ebeaninternal.server.core.BasicTypeConverter;
import java.io.DataInput; import java.io.DataInput;
@@ -87,11 +86,6 @@ final class ScalarTypeInteger extends ScalarTypeBase<Integer> {
return Integer.valueOf(value); return Integer.valueOf(value);
} }
@Override
public Integer convertFromMillis(long systemTimeMillis) {
throw new TextException("Not Supported");
}
@Override @Override
public Integer jsonRead(JsonParser parser) throws IOException { public Integer jsonRead(JsonParser parser) throws IOException {
return parser.getIntValue(); return parser.getIntValue();
@@ -73,7 +73,6 @@ class ScalarTypeJodaLocalTime extends ScalarTypeBase<LocalTime> {
return new LocalTime(value); return new LocalTime(value);
} }
@Override
public LocalTime convertFromMillis(long systemTimeMillis) { public LocalTime convertFromMillis(long systemTimeMillis) {
return new LocalTime(systemTimeMillis, DateTimeZone.getDefault()); return new LocalTime(systemTimeMillis, DateTimeZone.getDefault());
} }
@@ -87,11 +87,6 @@ class ScalarTypeLocalTime extends ScalarTypeBase<LocalTime> {
return LocalTime.parse(value); return LocalTime.parse(value);
} }
@Override
public LocalTime convertFromMillis(long systemTimeMillis) {
throw new TextException("Not Supported");
}
@Override @Override
public LocalTime jsonRead(JsonParser parser) throws IOException { public LocalTime jsonRead(JsonParser parser) throws IOException {
return LocalTime.parse(parser.getValueAsString()); return LocalTime.parse(parser.getValueAsString());
@@ -67,11 +67,6 @@ final class ScalarTypeLong extends ScalarTypeBase<Long> {
return value; return value;
} }
@Override
public Long convertFromMillis(long systemTimeMillis) {
return systemTimeMillis;
}
@Override @Override
public Long readData(DataInput dataInput) throws IOException { public Long readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) { if (!dataInput.readBoolean()) {
@@ -62,11 +62,6 @@ final class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
return new BigInteger(value); return new BigInteger(value);
} }
@Override
public BigInteger convertFromMillis(long systemTimeMillis) {
return BigInteger.valueOf(systemTimeMillis);
}
@Override @Override
public BigInteger readData(DataInput dataInput) throws IOException { public BigInteger readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) { if (!dataInput.readBoolean()) {
@@ -57,11 +57,6 @@ abstract class ScalarTypeStringBase extends ScalarTypeBase<String> {
return value; return value;
} }
@Override
public String convertFromMillis(long systemTimeMillis) {
return String.valueOf(systemTimeMillis);
}
@Override @Override
public String readData(DataInput dataInput) throws IOException { public String readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) { if (!dataInput.readBoolean()) {
@@ -58,7 +58,6 @@ final class ScalarTypeTime extends ScalarTypeBase<Time> {
return Time.valueOf(value); return Time.valueOf(value);
} }
@Override
public Time convertFromMillis(long systemTimeMillis) { public Time convertFromMillis(long systemTimeMillis) {
return new Time(systemTimeMillis); return new Time(systemTimeMillis);
} }
@@ -119,15 +119,6 @@ public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
return converter.wrapValue(sv); return converter.wrapValue(sv);
} }
@Override
public B convertFromMillis(long systemTimeMillis) {
S sv = scalarType.convertFromMillis(systemTimeMillis);
if (sv == null) {
return nullValue;
}
return converter.wrapValue(sv);
}
@Override @Override
public B read(DataReader reader) throws SQLException { public B read(DataReader reader) throws SQLException {
S sv = scalarType.read(reader); S sv = scalarType.read(reader);
@@ -75,11 +75,6 @@ class ScalarTypeDurationTest {
assertEquals(Duration.ofSeconds(1234), duration); assertEquals(Duration.ofSeconds(1234), duration);
} }
@Test
void testConvertFromMillis() {
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
}
@Test @Test
void testJsonRead() throws Exception { void testJsonRead() throws Exception {
Duration duration = Duration.ofSeconds(1234); Duration duration = Duration.ofSeconds(1234);
@@ -75,11 +75,6 @@ class ScalarTypeDurationWithNanosTest {
assertEquals(duration, val1); assertEquals(duration, val1);
} }
@Test
void testConvertFromMillis() {
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
}
@Test @Test
void testJsonRead() throws Exception { void testJsonRead() throws Exception {
Duration duration = Duration.ofSeconds(323, 1500000); Duration duration = Duration.ofSeconds(323, 1500000);
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.type; package io.ebeaninternal.server.type;
import io.ebean.text.TextException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@@ -10,7 +9,8 @@ import java.io.ObjectOutputStream;
import java.sql.Time; import java.sql.Time;
import java.time.LocalTime; import java.time.LocalTime;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class ScalarTypeLocalTimeTest { public class ScalarTypeLocalTimeTest {
@@ -77,11 +77,6 @@ public class ScalarTypeLocalTimeTest {
assertEquals(localTime, val1); assertEquals(localTime, val1);
} }
@Test
public void testConvertFromMillis() {
assertThrows(TextException.class, () -> type.convertFromMillis(1234));
}
@Test @Test
public void testJsonRead() throws Exception { public void testJsonRead() throws Exception {
LocalTime localTime = LocalTime.of(9, 23, 45); LocalTime localTime = LocalTime.of(9, 23, 45);
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.type; package io.ebeaninternal.server.type;
import io.ebean.text.TextException;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@@ -9,7 +8,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.time.LocalTime; import java.time.LocalTime;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class ScalarTypeLocalTimeWithNanosTest { public class ScalarTypeLocalTimeWithNanosTest {
@@ -74,11 +74,6 @@ public class ScalarTypeLocalTimeWithNanosTest {
assertEquals(localTime, val1); assertEquals(localTime, val1);
} }
@Test
public void testConvertFromMillis() {
assertThrows(TextException.class, () -> type.convertFromMillis(1234));
}
@Test @Test
public void testJsonRead() throws Exception { public void testJsonRead() throws Exception {
LocalTime localTime = LocalTime.of(9, 23, 45); LocalTime localTime = LocalTime.of(9, 23, 45);
@@ -7,7 +7,6 @@ import java.time.LocalDate;
import java.time.MonthDay; import java.time.MonthDay;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ScalarTypeMonthDayTest { public class ScalarTypeMonthDayTest {
@@ -49,11 +48,6 @@ public class ScalarTypeMonthDayTest {
assertEquals(value, monthDay); assertEquals(value, monthDay);
} }
@Test
public void testConvertFromMillis() {
assertThrows(RuntimeException.class, () -> type.convertFromMillis(1203));
}
@Test @Test
public void testJson() throws Exception { public void testJson() throws Exception {
MonthDay value = MonthDay.of(4, 29); MonthDay value = MonthDay.of(4, 29);
@@ -45,16 +45,6 @@ public class ScalarTypePostgresHstoreTest {
assertEquals("rob", map.get("name")); assertEquals("rob", map.get("name"));
} }
@Test
@SuppressWarnings("unchecked")
public void testParseDateTime() {
assertThrows(RuntimeException.class, () -> {
Map<String, Object> map = (Map<String, Object>) hstore.convertFromMillis(1234L);
assertEquals(1, map.size());
assertEquals("rob", map.get("name"));
});
}
@Test @Test
public void testJsonWrite() throws Exception { public void testJsonWrite() throws Exception {
Map<String, Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
@@ -70,11 +70,6 @@ class ScalarTypeYearTest {
assertEquals(Year.of(2013), year); assertEquals(Year.of(2013), year);
} }
@Test
void testConvertFromMillis() {
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
}
@Test @Test
void testJson() throws Exception { void testJson() throws Exception {
JsonTester<Year> jsonTester = new JsonTester<>(type); JsonTester<Year> jsonTester = new JsonTester<>(type);