mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
Merge pull request #2506 from FOCONIS/fix-localdate-databind
DB2: Fix: DataBind/Read of native LocalDates
This commit is contained in:
7 files changed
+104
-47
No files matched your search
@@ -755,7 +755,11 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
|
||||
typeMap.put(java.nio.file.Path.class, new ScalarTypePath());
|
||||
addType(java.time.Period.class, new ScalarTypePeriod());
|
||||
addType(java.time.LocalDate.class, new ScalarTypeLocalDate(jsonDate));
|
||||
if (config.getDatabasePlatform().supportsNativeJavaTime()) {
|
||||
addType(java.time.LocalDate.class, new ScalarTypeLocalDateNative(jsonDate));
|
||||
} else {
|
||||
addType(java.time.LocalDate.class, new ScalarTypeLocalDate(jsonDate));
|
||||
}
|
||||
addType(java.time.LocalDateTime.class, new ScalarTypeLocalDateTime(jsonDateTime));
|
||||
addType(OffsetDateTime.class, new ScalarTypeOffsetDateTime(jsonDateTime, zoneId));
|
||||
addType(ZonedDateTime.class, new ScalarTypeZonedDateTime(jsonDateTime, zoneId));
|
||||
@@ -795,7 +799,11 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
log.debug("Registering Joda data types");
|
||||
addType(LocalDateTime.class, new ScalarTypeJodaLocalDateTime(jsonDateTime));
|
||||
addType(DateTime.class, new ScalarTypeJodaDateTime(jsonDateTime));
|
||||
addType(LocalDate.class, new ScalarTypeJodaLocalDate(jsonDate));
|
||||
if (config.getDatabasePlatform().supportsNativeJavaTime()) {
|
||||
addType(LocalDate.class, new ScalarTypeJodaLocalDateNative(jsonDate));
|
||||
} else {
|
||||
addType(LocalDate.class, new ScalarTypeJodaLocalDate(jsonDate));
|
||||
}
|
||||
addType(org.joda.time.DateMidnight.class, new ScalarTypeJodaDateMidnight(jsonDate));
|
||||
addType(org.joda.time.Period.class, new ScalarTypeJodaPeriod());
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.DataBinder;
|
||||
import io.ebean.core.type.DataReader;
|
||||
import io.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import java.sql.Date;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for Joda LocalDate. This maps to a JDBC Date.
|
||||
*/
|
||||
final class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
|
||||
ScalarTypeJodaLocalDate(JsonConfig.Date mode) {
|
||||
super(mode, LocalDate.class, false, Types.DATE);
|
||||
@@ -61,19 +59,4 @@ final class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
}
|
||||
return (LocalDate) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBinder binder, LocalDate value) throws SQLException {
|
||||
if (value == null) {
|
||||
binder.setNull(Types.DATE);
|
||||
} else {
|
||||
binder.setObject(java.time.LocalDate.of(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate read(DataReader reader) throws SQLException {
|
||||
java.time.LocalDate jtDate = reader.getObject(java.time.LocalDate.class);
|
||||
return jtDate == null ? null : new org.joda.time.LocalDate(jtDate.getYear(), jtDate.getMonthValue(), jtDate.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.DataBinder;
|
||||
import io.ebean.core.type.DataReader;
|
||||
|
||||
/**
|
||||
* ScalarType for Joda LocalDate. This maps to a LocalDate. Not all drivers/platforms may support this.
|
||||
*/
|
||||
final class ScalarTypeJodaLocalDateNative extends ScalarTypeJodaLocalDate{
|
||||
|
||||
ScalarTypeJodaLocalDateNative(JsonConfig.Date mode) {
|
||||
super(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBinder binder, LocalDate value) throws SQLException {
|
||||
if (value == null) {
|
||||
binder.setNull(Types.DATE);
|
||||
} else {
|
||||
binder.setObject(java.time.LocalDate.of(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate read(DataReader reader) throws SQLException {
|
||||
java.time.LocalDate jtDate = reader.getObject(java.time.LocalDate.class);
|
||||
return jtDate == null ? null : new org.joda.time.LocalDate(jtDate.getYear(), jtDate.getMonthValue(), jtDate.getDayOfMonth());
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,19 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.DataBinder;
|
||||
import io.ebean.core.type.DataReader;
|
||||
import io.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.LocalDate. This maps to a JDBC Date.
|
||||
*/
|
||||
final class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
|
||||
ScalarTypeLocalDate(JsonConfig.Date mode) {
|
||||
super(mode, LocalDate.class, false, Types.DATE);
|
||||
@@ -63,19 +60,4 @@ final class ScalarTypeLocalDate extends ScalarTypeBaseDate<LocalDate> {
|
||||
}
|
||||
return (LocalDate) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBinder binder, LocalDate value) throws SQLException {
|
||||
if (value == null) {
|
||||
binder.setNull(Types.DATE);
|
||||
} else {
|
||||
binder.setObject(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate read(DataReader reader) throws SQLException {
|
||||
return reader.getObject(LocalDate.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.core.type.DataBinder;
|
||||
import io.ebean.core.type.DataReader;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.LocalDate. This maps to a LocalDate. Not all drivers/platforms may support this.
|
||||
*/
|
||||
final class ScalarTypeLocalDateNative extends ScalarTypeLocalDate {
|
||||
|
||||
ScalarTypeLocalDateNative(JsonConfig.Date mode) {
|
||||
super(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBinder binder, LocalDate value) throws SQLException {
|
||||
if (value == null) {
|
||||
binder.setNull(Types.DATE);
|
||||
} else {
|
||||
binder.setObject(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate read(DataReader reader) throws SQLException {
|
||||
return reader.getObject(LocalDate.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user