mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1775 - MySql 8 by default wants JDBC Date set and read with JVM Calendar (timezone)
This commit is contained in:
@@ -45,6 +45,7 @@ import io.ebeaninternal.server.cluster.ClusterManager;
|
||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
import io.ebeaninternal.server.core.timezone.CloneDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.DataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.LocalDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.NoDataTimeZone;
|
||||
import io.ebeaninternal.server.core.timezone.SimpleDataTimeZone;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
@@ -366,6 +367,10 @@ public class InternalConfiguration {
|
||||
return bootupClasses;
|
||||
}
|
||||
|
||||
private Platform getPlatform() {
|
||||
return getDatabasePlatform().getPlatform();
|
||||
}
|
||||
|
||||
public DatabasePlatform getDatabasePlatform() {
|
||||
return serverConfig.getDatabasePlatform();
|
||||
}
|
||||
@@ -509,9 +514,12 @@ public class InternalConfiguration {
|
||||
|
||||
String tz = serverConfig.getDataTimeZone();
|
||||
if (tz == null) {
|
||||
if (getPlatform() == Platform.MYSQL) {
|
||||
return new LocalDataTimeZone();
|
||||
}
|
||||
return new NoDataTimeZone();
|
||||
}
|
||||
if (getDatabasePlatform().getPlatform() == Platform.ORACLE) {
|
||||
if (getPlatform() == Platform.ORACLE) {
|
||||
return new CloneDataTimeZone(tz);
|
||||
} else {
|
||||
return new SimpleDataTimeZone(tz);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.ebeaninternal.server.core.timezone;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Implementation of DataTimeZone when single Calendar instance is used with local timezone.
|
||||
*/
|
||||
public class LocalDataTimeZone implements DataTimeZone {
|
||||
|
||||
protected final Calendar zone;
|
||||
|
||||
public LocalDataTimeZone() {
|
||||
this.zone = Calendar.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Calendar getTimeZone() {
|
||||
return zone;
|
||||
}
|
||||
}
|
||||
@@ -141,7 +141,12 @@ public class DataBind {
|
||||
}
|
||||
|
||||
public void setDate(java.sql.Date v) throws SQLException {
|
||||
pstmt.setDate(++pos, v);
|
||||
Calendar timeZone = dataTimeZone.getTimeZone();
|
||||
if (timeZone != null) {
|
||||
pstmt.setDate(++pos, v, timeZone);
|
||||
} else {
|
||||
pstmt.setDate(++pos, v);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTimestamp(Timestamp v) throws SQLException {
|
||||
|
||||
@@ -106,7 +106,12 @@ public class RsetDataReader implements DataReader {
|
||||
|
||||
@Override
|
||||
public Date getDate() throws SQLException {
|
||||
return rset.getDate(pos());
|
||||
Calendar cal = dataTimeZone.getTimeZone();
|
||||
if (cal != null) {
|
||||
return rset.getDate(pos(), cal);
|
||||
} else {
|
||||
return rset.getDate(pos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,7 @@ public abstract class ScalarTypeBaseDate<T> extends ScalarTypeBase<T> {
|
||||
|
||||
protected final JsonConfig.Date mode;
|
||||
|
||||
public ScalarTypeBaseDate(JsonConfig.Date mode, Class<T> type, boolean jdbcNative, int jdbcType) {
|
||||
ScalarTypeBaseDate(JsonConfig.Date mode, Class<T> type, boolean jdbcNative, int jdbcType) {
|
||||
super(type, jdbcNative, jdbcType);
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user