From e6f0ab90dc1913b69a123fb22cf0cc515c3835b9 Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Fri, 23 Oct 2020 01:25:28 +1300 Subject: [PATCH] #2094 - Refactor remove isJavaTimePresent() ... we are Java 8+ so removing effectively redundant code --- .../java/io/ebean/config/ClassLoadConfig.java | 7 ---- .../InsertTimestampFactory.java | 10 ++--- .../UpdateTimestampFactory.java | 11 +++-- .../server/type/DefaultTypeManager.java | 42 ++++++++----------- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/ebean-api/src/main/java/io/ebean/config/ClassLoadConfig.java b/ebean-api/src/main/java/io/ebean/config/ClassLoadConfig.java index 43edb4574..821905405 100644 --- a/ebean-api/src/main/java/io/ebean/config/ClassLoadConfig.java +++ b/ebean-api/src/main/java/io/ebean/config/ClassLoadConfig.java @@ -26,13 +26,6 @@ public class ClassLoadConfig { this.context = new ClassLoaderContext(classLoader); } - /** - * Return true if the Java.time types are available and should be supported. - */ - public boolean isJavaTimePresent() { - return isPresent("java.time.LocalDate"); - } - /** * Return true if the Joda types are available and should be supported. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/InsertTimestampFactory.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/InsertTimestampFactory.java index 5c1cafd6b..ee2c88a66 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/InsertTimestampFactory.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/InsertTimestampFactory.java @@ -26,12 +26,10 @@ class InsertTimestampFactory { map.put(Long.class, longTime); map.put(long.class, longTime); - if (classLoadConfig.isJavaTimePresent()) { - map.put(Instant.class, new GeneratedInsertJavaTime.InstantDT()); - map.put(LocalDateTime.class, new GeneratedInsertJavaTime.LocalDT()); - map.put(OffsetDateTime.class, new GeneratedInsertJavaTime.OffsetDT()); - map.put(ZonedDateTime.class, new GeneratedInsertJavaTime.ZonedDT()); - } + map.put(Instant.class, new GeneratedInsertJavaTime.InstantDT()); + map.put(LocalDateTime.class, new GeneratedInsertJavaTime.LocalDT()); + map.put(OffsetDateTime.class, new GeneratedInsertJavaTime.OffsetDT()); + map.put(ZonedDateTime.class, new GeneratedInsertJavaTime.ZonedDT()); if (classLoadConfig.isJodaTimePresent()) { map.put(org.joda.time.LocalDateTime.class, new GeneratedInsertJodaTime.LocalDT()); map.put(org.joda.time.DateTime.class, new GeneratedInsertJodaTime.DateTimeDT()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/UpdateTimestampFactory.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/UpdateTimestampFactory.java index 5788569a7..d405f2ec7 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/UpdateTimestampFactory.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/generatedproperty/UpdateTimestampFactory.java @@ -26,12 +26,11 @@ class UpdateTimestampFactory { map.put(Long.class, longTime); map.put(long.class, longTime); - if (classLoadConfig.isJavaTimePresent()) { - map.put(Instant.class, new GeneratedUpdateJavaTime.InstantDT()); - map.put(LocalDateTime.class, new GeneratedUpdateJavaTime.LocalDT()); - map.put(OffsetDateTime.class, new GeneratedUpdateJavaTime.OffsetDT()); - map.put(ZonedDateTime.class, new GeneratedUpdateJavaTime.ZonedDT()); - } + map.put(Instant.class, new GeneratedUpdateJavaTime.InstantDT()); + map.put(LocalDateTime.class, new GeneratedUpdateJavaTime.LocalDT()); + map.put(OffsetDateTime.class, new GeneratedUpdateJavaTime.OffsetDT()); + map.put(ZonedDateTime.class, new GeneratedUpdateJavaTime.ZonedDT()); + if (classLoadConfig.isJodaTimePresent()) { map.put(org.joda.time.LocalDateTime.class, new GeneratedUpdateJodaTime.LocalDT()); map.put(org.joda.time.DateTime.class, new GeneratedUpdateJodaTime.DateTimeDT()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java index 24bab9243..50a9b63c1 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java @@ -887,30 +887,24 @@ public final class DefaultTypeManager implements TypeManager { private void initialiseJavaTimeTypes(DatabaseConfig config) { typeMap.put(java.nio.file.Path.class, new ScalarTypePath()); - if (config.getClassLoadConfig().isJavaTimePresent()) { - logger.debug("Registering java.time data types"); - addType(java.time.Period.class, new ScalarTypePeriod()); - addType(java.time.LocalDate.class, new ScalarTypeLocalDate(jsonDate)); - addType(java.time.LocalDateTime.class, new ScalarTypeLocalDateTime(jsonDateTime)); - addType(OffsetDateTime.class, new ScalarTypeOffsetDateTime(jsonDateTime)); - addType(ZonedDateTime.class, new ScalarTypeZonedDateTime(jsonDateTime)); - addType(Instant.class, new ScalarTypeInstant(jsonDateTime)); - - addType(DayOfWeek.class, new ScalarTypeDayOfWeek()); - addType(Month.class, new ScalarTypeMonth()); - addType(Year.class, new ScalarTypeYear()); - addType(YearMonth.class, new ScalarTypeYearMonthDate(jsonDate)); - addType(MonthDay.class, new ScalarTypeMonthDay()); - addType(OffsetTime.class, new ScalarTypeOffsetTime()); - addType(ZoneId.class, new ScalarTypeZoneId()); - addType(ZoneOffset.class, new ScalarTypeZoneOffset()); - - boolean localTimeNanos = config.isLocalTimeWithNanos(); - addType(java.time.LocalTime.class, (localTimeNanos) ? new ScalarTypeLocalTimeWithNanos() : new ScalarTypeLocalTime()); - - boolean durationNanos = config.isDurationWithNanos(); - addType(Duration.class, (durationNanos) ? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration()); - } + addType(java.time.Period.class, new ScalarTypePeriod()); + addType(java.time.LocalDate.class, new ScalarTypeLocalDate(jsonDate)); + addType(java.time.LocalDateTime.class, new ScalarTypeLocalDateTime(jsonDateTime)); + addType(OffsetDateTime.class, new ScalarTypeOffsetDateTime(jsonDateTime)); + addType(ZonedDateTime.class, new ScalarTypeZonedDateTime(jsonDateTime)); + addType(Instant.class, new ScalarTypeInstant(jsonDateTime)); + addType(DayOfWeek.class, new ScalarTypeDayOfWeek()); + addType(Month.class, new ScalarTypeMonth()); + addType(Year.class, new ScalarTypeYear()); + addType(YearMonth.class, new ScalarTypeYearMonthDate(jsonDate)); + addType(MonthDay.class, new ScalarTypeMonthDay()); + addType(OffsetTime.class, new ScalarTypeOffsetTime()); + addType(ZoneId.class, new ScalarTypeZoneId()); + addType(ZoneOffset.class, new ScalarTypeZoneOffset()); + boolean localTimeNanos = config.isLocalTimeWithNanos(); + addType(java.time.LocalTime.class, (localTimeNanos) ? new ScalarTypeLocalTimeWithNanos() : new ScalarTypeLocalTime()); + boolean durationNanos = config.isDurationWithNanos(); + addType(Duration.class, (durationNanos) ? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration()); } private void addType(Class clazz, ScalarType scalarType) {