Merge pull request #2806 from ebean-orm/feature/refactor-scalarType-convertFromMillis

Refactor ScalarType, remove convertFromMillis() method (no longer needed)
This commit is contained in:
Rob Bygrave
2022-08-25 22:49:03 +12:00
committed by GitHub
27 changed files with 4 additions and 139 deletions
@@ -39,12 +39,6 @@ public interface ExpressionPath {
*/
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.
*/
@@ -166,15 +166,6 @@ public interface ScalarType<T> extends StringParser, StringFormatter, ScalarData
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.
*/
@@ -190,11 +190,6 @@ public final class BeanFkeyProperty implements ElPropertyValue {
return null;
}
@Override
public Object parseDateTime(long systemTimeMillis) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}
@Override
public StringParser stringParser() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
@@ -945,11 +945,6 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
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).
*/
@@ -232,11 +232,6 @@ public final class ElPropertyChain implements ElPropertyValue {
return scalarType == null ? 0 : scalarType.jdbcType();
}
@Override
public Object parseDateTime(long systemTimeMillis) {
return scalarType.convertFromMillis(systemTimeMillis);
}
@Override
public StringParser stringParser() {
return scalarType;
@@ -77,7 +77,6 @@ abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
}
}
@Override
public T convertFromMillis(long systemTimeMillis) {
Date ts = new Date(systemTimeMillis);
return convertFromDate(ts);
@@ -54,7 +54,6 @@ abstract class ScalarTypeBaseDateTime<T> extends ScalarTypeBase<T> {
/**
* Convert from epoch millis to the value.
*/
@Override
public abstract T convertFromMillis(long systemTimeMillis);
/**
@@ -58,11 +58,6 @@ class ScalarTypeBigDecimal extends ScalarTypeBase<BigDecimal> {
return new BigDecimal(value);
}
@Override
public BigDecimal convertFromMillis(long systemTimeMillis) {
return BigDecimal.valueOf(systemTimeMillis);
}
@Override
public BigDecimal readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) {
@@ -84,11 +84,6 @@ public final class ScalarTypeBytesEncrypted implements ScalarType<byte[]> {
return baseType.parse(value);
}
@Override
public byte[] convertFromMillis(long systemTimeMillis) {
return baseType.convertFromMillis(systemTimeMillis);
}
@Override
public byte[] read(DataReader reader) throws SQLException {
byte[] data = baseType.read(reader);
@@ -57,11 +57,6 @@ final class ScalarTypeDouble extends ScalarTypeBase<Double> {
return Double.valueOf(value);
}
@Override
public Double convertFromMillis(long systemTimeMillis) {
return (double) systemTimeMillis;
}
@Override
public Double readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) {
@@ -109,11 +109,6 @@ public final class ScalarTypeEncryptedWrapper<T> implements ScalarType<T>, Local
return wrapped.parse(value);
}
@Override
public T convertFromMillis(long systemTimeMillis) {
return wrapped.convertFromMillis(systemTimeMillis);
}
@Override
public T toBeanType(Object value) {
return wrapped.toBeanType(value);
@@ -57,11 +57,6 @@ final class ScalarTypeFloat extends ScalarTypeBase<Float> {
return Float.valueOf(value);
}
@Override
public Float convertFromMillis(long systemTimeMillis) {
return (float) systemTimeMillis;
}
@Override
public Float readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) {
@@ -6,7 +6,6 @@ import io.ebean.core.type.DataBinder;
import io.ebean.core.type.DataReader;
import io.ebean.core.type.DocPropertyType;
import io.ebean.core.type.ScalarTypeBase;
import io.ebean.text.TextException;
import io.ebeaninternal.server.core.BasicTypeConverter;
import java.io.DataInput;
@@ -87,11 +86,6 @@ final class ScalarTypeInteger extends ScalarTypeBase<Integer> {
return Integer.valueOf(value);
}
@Override
public Integer convertFromMillis(long systemTimeMillis) {
throw new TextException("Not Supported");
}
@Override
public Integer jsonRead(JsonParser parser) throws IOException {
return parser.getIntValue();
@@ -73,7 +73,6 @@ class ScalarTypeJodaLocalTime extends ScalarTypeBase<LocalTime> {
return new LocalTime(value);
}
@Override
public LocalTime convertFromMillis(long systemTimeMillis) {
return new LocalTime(systemTimeMillis, DateTimeZone.getDefault());
}
@@ -87,11 +87,6 @@ class ScalarTypeLocalTime extends ScalarTypeBase<LocalTime> {
return LocalTime.parse(value);
}
@Override
public LocalTime convertFromMillis(long systemTimeMillis) {
throw new TextException("Not Supported");
}
@Override
public LocalTime jsonRead(JsonParser parser) throws IOException {
return LocalTime.parse(parser.getValueAsString());
@@ -67,11 +67,6 @@ final class ScalarTypeLong extends ScalarTypeBase<Long> {
return value;
}
@Override
public Long convertFromMillis(long systemTimeMillis) {
return systemTimeMillis;
}
@Override
public Long readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) {
@@ -62,11 +62,6 @@ final class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
return new BigInteger(value);
}
@Override
public BigInteger convertFromMillis(long systemTimeMillis) {
return BigInteger.valueOf(systemTimeMillis);
}
@Override
public BigInteger readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) {
@@ -57,11 +57,6 @@ abstract class ScalarTypeStringBase extends ScalarTypeBase<String> {
return value;
}
@Override
public String convertFromMillis(long systemTimeMillis) {
return String.valueOf(systemTimeMillis);
}
@Override
public String readData(DataInput dataInput) throws IOException {
if (!dataInput.readBoolean()) {
@@ -58,7 +58,6 @@ final class ScalarTypeTime extends ScalarTypeBase<Time> {
return Time.valueOf(value);
}
@Override
public Time convertFromMillis(long systemTimeMillis) {
return new Time(systemTimeMillis);
}
@@ -119,15 +119,6 @@ public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
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
public B read(DataReader reader) throws SQLException {
S sv = scalarType.read(reader);
@@ -75,11 +75,6 @@ class ScalarTypeDurationTest {
assertEquals(Duration.ofSeconds(1234), duration);
}
@Test
void testConvertFromMillis() {
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
}
@Test
void testJsonRead() throws Exception {
Duration duration = Duration.ofSeconds(1234);
@@ -75,11 +75,6 @@ class ScalarTypeDurationWithNanosTest {
assertEquals(duration, val1);
}
@Test
void testConvertFromMillis() {
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
}
@Test
void testJsonRead() throws Exception {
Duration duration = Duration.ofSeconds(323, 1500000);
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.type;
import io.ebean.text.TextException;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -10,7 +9,8 @@ import java.io.ObjectOutputStream;
import java.sql.Time;
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 {
@@ -77,11 +77,6 @@ public class ScalarTypeLocalTimeTest {
assertEquals(localTime, val1);
}
@Test
public void testConvertFromMillis() {
assertThrows(TextException.class, () -> type.convertFromMillis(1234));
}
@Test
public void testJsonRead() throws Exception {
LocalTime localTime = LocalTime.of(9, 23, 45);
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.type;
import io.ebean.text.TextException;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -9,7 +8,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
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 {
@@ -74,11 +74,6 @@ public class ScalarTypeLocalTimeWithNanosTest {
assertEquals(localTime, val1);
}
@Test
public void testConvertFromMillis() {
assertThrows(TextException.class, () -> type.convertFromMillis(1234));
}
@Test
public void testJsonRead() throws Exception {
LocalTime localTime = LocalTime.of(9, 23, 45);
@@ -7,7 +7,6 @@ import java.time.LocalDate;
import java.time.MonthDay;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ScalarTypeMonthDayTest {
@@ -49,11 +48,6 @@ public class ScalarTypeMonthDayTest {
assertEquals(value, monthDay);
}
@Test
public void testConvertFromMillis() {
assertThrows(RuntimeException.class, () -> type.convertFromMillis(1203));
}
@Test
public void testJson() throws Exception {
MonthDay value = MonthDay.of(4, 29);
@@ -45,16 +45,6 @@ public class ScalarTypePostgresHstoreTest {
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
public void testJsonWrite() throws Exception {
Map<String, Object> map = new LinkedHashMap<>();
@@ -70,11 +70,6 @@ class ScalarTypeYearTest {
assertEquals(Year.of(2013), year);
}
@Test
void testConvertFromMillis() {
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
}
@Test
void testJson() throws Exception {
JsonTester<Year> jsonTester = new JsonTester<>(type);