Refactor ScalarTypeBaseDateTime, merge into ScalarTypeUtils both IsoJsonDateTimeParser and DecimalUtils

That is, merge the static util methods into ScalarTypeUtils
This commit is contained in:
Rob Bygrave committed 2022-08-26 13:15:55 +12:00
1 parent f319ee66ad
commit a13f581a65
16 files changed
+69 -74

No files matched your search

@@ -12,7 +12,7 @@ import java.sql.Types;
import java.time.Instant;
import java.util.Calendar;
import static io.ebean.core.type.IsoJsonDateTimeParser.formatIso;
import static io.ebean.core.type.ScalarTypeUtils.formatInstant;
/**
* ScalarType for java.util.Calendar.
@@ -66,7 +66,7 @@ final class ScalarTypeCalendar extends ScalarTypeBaseDateTime<Calendar> {
@Override
protected String toJsonISO8601(Calendar value) {
return formatIso(value.toInstant());
return formatInstant(value.toInstant());
}
@Override
@@ -27,11 +27,11 @@ class ScalarTypeDuration extends ScalarTypeBase<Duration> {
}
BigDecimal convertToBigDecimal(Duration value) {
return (value == null) ? null : DecimalUtils.toDecimal(value);
return (value == null) ? null : ScalarTypeUtils.toDecimal(value);
}
Duration convertFromBigDecimal(BigDecimal value) {
return (value == null) ? null : DecimalUtils.toDuration(value);
return (value == null) ? null : ScalarTypeUtils.toDuration(value);
}
@Override
@@ -9,7 +9,7 @@ import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import static io.ebean.core.type.IsoJsonDateTimeParser.formatIso;
import static io.ebean.core.type.ScalarTypeUtils.formatInstant;
/**
* ScalarType for java.sql.Timestamp.
@@ -30,7 +30,7 @@ final class ScalarTypeOffsetDateTime extends ScalarTypeBaseDateTime<OffsetDateTi
@Override
protected String toJsonISO8601(OffsetDateTime value) {
return formatIso(value.toInstant());
return formatInstant(value.toInstant());
}
@Override
@@ -11,7 +11,7 @@ import java.sql.Timestamp;
import java.sql.Types;
import java.time.Instant;
import static io.ebean.core.type.IsoJsonDateTimeParser.formatIso;
import static io.ebean.core.type.ScalarTypeUtils.formatInstant;
/**
* ScalarType for java.sql.Timestamp.
@@ -29,7 +29,7 @@ final class ScalarTypeTimestamp extends ScalarTypeBaseDateTime<Timestamp> {
@Override
protected String toJsonISO8601(Timestamp value) {
return formatIso(value.toInstant());
return formatInstant(value.toInstant());
}
@Override
@@ -13,7 +13,7 @@ import java.sql.Types;
import java.time.Instant;
import java.util.Date;
import static io.ebean.core.type.IsoJsonDateTimeParser.formatIso;
import static io.ebean.core.type.ScalarTypeUtils.formatInstant;
/**
* ScalarType for java.util.Date.
@@ -33,7 +33,7 @@ final class ScalarTypeUtilDate {
@Override
protected String toJsonISO8601(Date value) {
return formatIso(value.toInstant());
return formatInstant(value.toInstant());
}
@Override
@@ -1,7 +1,7 @@
package io.ebeaninternal.server.type;
import io.ebean.config.JsonConfig;
import io.ebean.core.type.IsoJsonDateTimeParser;
import io.ebean.core.type.ScalarTypeUtils;
import org.junit.jupiter.api.Test;
import java.sql.Types;
@@ -18,7 +18,7 @@ public class ScalarTypeCalendarTest {
Calendar instance = Calendar.getInstance();
String asUtc = type.toJsonISO8601(instance);
Calendar calendar = type.convertFromInstant(IsoJsonDateTimeParser.parseIso(asUtc)); //type.fromJsonISO8601(asUtc);
Calendar calendar = type.convertFromInstant(ScalarTypeUtils.parseInstant(asUtc)); //type.fromJsonISO8601(asUtc);
assertThat(instance).isEqualTo(calendar);
}
@@ -1,6 +1,6 @@
package io.ebeaninternal.server.type;
import io.ebean.core.type.DecimalUtils;
import io.ebean.core.type.ScalarTypeUtils;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -41,7 +41,7 @@ class ScalarTypeDurationWithNanosTest {
@Test
void testToJdbcType() throws Exception {
Duration duration = Duration.ofSeconds(323, 1500000);
BigDecimal bigDecimal = DecimalUtils.toDecimal(duration);
BigDecimal bigDecimal = ScalarTypeUtils.toDecimal(duration);
Object val1 = type.toJdbcType(duration);
Object val2 = type.toJdbcType(bigDecimal);
@@ -53,7 +53,7 @@ class ScalarTypeDurationWithNanosTest {
@Test
void testToBeanType() throws Exception {
Duration duration = Duration.ofSeconds(323, 1500000);
BigDecimal bigDecimal = DecimalUtils.toDecimal(duration);
BigDecimal bigDecimal = ScalarTypeUtils.toDecimal(duration);
Duration val1 = type.toBeanType(duration);
Duration val2 = type.toBeanType(bigDecimal);
@@ -1,7 +1,7 @@
package io.ebeaninternal.server.type;
import io.ebean.config.JsonConfig;
import io.ebean.core.type.IsoJsonDateTimeParser;
import io.ebean.core.type.ScalarTypeUtils;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
@@ -123,7 +123,7 @@ public class ScalarTypeOffsetDateTimeTest {
OffsetDateTime now = OffsetDateTime.now();
String asJson = typeIso.toJsonISO8601(now);
OffsetDateTime value = typeIso.convertFromInstant(IsoJsonDateTimeParser.parseIso(asJson)); //typeIso.fromJsonISO8601(asJson);
OffsetDateTime value = typeIso.convertFromInstant(ScalarTypeUtils.parseInstant(asJson)); //typeIso.fromJsonISO8601(asJson);
assertThat(now).isEqualToIgnoringNanos(value);
}
}
@@ -1,7 +1,7 @@
package io.ebeaninternal.server.type;
import io.ebean.config.JsonConfig;
import io.ebean.core.type.IsoJsonDateTimeParser;
import io.ebean.core.type.ScalarTypeUtils;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
@@ -18,7 +18,7 @@ public class ScalarTypeTimestampTest {
Timestamp now = new Timestamp(System.currentTimeMillis());
String asJson = typeIso.toJsonISO8601(now);
Timestamp value = typeIso.convertFromInstant(IsoJsonDateTimeParser.parseIso(asJson)); //typeIso.fromJsonISO8601(asJson);
Timestamp value = typeIso.convertFromInstant(ScalarTypeUtils.parseInstant(asJson)); //typeIso.fromJsonISO8601(asJson);
assertThat(now).isEqualTo(value);
}
}
@@ -1,7 +1,7 @@
package io.ebeaninternal.server.type;
import io.ebean.config.JsonConfig;
import io.ebean.core.type.IsoJsonDateTimeParser;
import io.ebean.core.type.ScalarTypeUtils;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -35,7 +35,7 @@ public class ScalarTypeUtilDateTest {
Date now = new Date();
String asJson = typeIso.toJsonISO8601(now);
Instant instant = IsoJsonDateTimeParser.parseIso(asJson);
Instant instant = ScalarTypeUtils.parseInstant(asJson);
Date value = new java.util.Date(instant.toEpochMilli()); // typeIso.fromJsonISO8601(asJson);
assertThat(now).isEqualTo(value);
}
@@ -1,7 +1,7 @@
package io.ebeaninternal.server.type;
import io.ebean.config.JsonConfig;
import io.ebean.core.type.IsoJsonDateTimeParser;
import io.ebean.core.type.ScalarTypeUtils;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
@@ -125,7 +125,7 @@ public class ScalarTypeZonedDateTimeTest {
ZonedDateTime now = ZonedDateTime.now();
String asJson = typeIso.toJsonISO8601(now);
ZonedDateTime value = type.convertFromInstant(IsoJsonDateTimeParser.parseIso(asJson)); //typeIso.fromJsonISO8601(asJson);
ZonedDateTime value = type.convertFromInstant(ScalarTypeUtils.parseInstant(asJson)); //typeIso.fromJsonISO8601(asJson);
assertThat(now).isEqualTo(value);
}
}