From 95e1857ccd044cb4a85e5b2cdb37c986937bf623 Mon Sep 17 00:00:00 2001 From: Mark Rotteveel Date: Sat, 30 Mar 2019 14:46:34 +0100 Subject: [PATCH] JDBC-540 Apply session time zone for DATE as well --- .../field/AbstractWithoutTimeZoneField.java | 29 +++++++-------- .../firebirdsql/jdbc/field/FBDateField.java | 35 ++++--------------- .../jdbc/field/FBTimestampField.java | 17 --------- 3 files changed, 19 insertions(+), 62 deletions(-) diff --git a/src/main/org/firebirdsql/jdbc/field/AbstractWithoutTimeZoneField.java b/src/main/org/firebirdsql/jdbc/field/AbstractWithoutTimeZoneField.java index 2dc6c7905c..bb2d44767a 100644 --- a/src/main/org/firebirdsql/jdbc/field/AbstractWithoutTimeZoneField.java +++ b/src/main/org/firebirdsql/jdbc/field/AbstractWithoutTimeZoneField.java @@ -20,6 +20,7 @@ import org.firebirdsql.gds.ng.fields.FieldDescriptor; +import java.sql.Date; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; @@ -27,7 +28,7 @@ import java.util.TimeZone; /** - * Common superclass for {@link FBTimeField} and {@link FBTimestampField} to handle session time zone. + * Superclass for {@link FBTimeField}, {@link FBTimestampField} and {@link FBDateField} to handle session time zone. * * @author Mark Rotteveel */ @@ -42,39 +43,35 @@ abstract class AbstractWithoutTimeZoneField extends FBField { @Override public final Time getTime() throws SQLException { - if (isNull()) return null; - return getTime(getCalendar()); } @Override public final Timestamp getTimestamp() throws SQLException { - if (isNull()) return null; - return getTimestamp(getCalendar()); } @Override - public final void setTime(Time value) throws SQLException { - if (value == null) { - setNull(); - return; - } + public final Date getDate() throws SQLException { + return getDate(getCalendar()); + } + @Override + public final void setTime(Time value) throws SQLException { setTime(value, getCalendar()); } @Override public final void setTimestamp(Timestamp value) throws SQLException { - if (value == null) { - setNull(); - return; - } - setTimestamp(value, getCalendar()); } - Calendar getCalendar() { + @Override + public final void setDate(Date value) throws SQLException { + setDate(value, getCalendar()); + } + + final Calendar getCalendar() { if (calendar == null) { return initCalendar(); } diff --git a/src/main/org/firebirdsql/jdbc/field/FBDateField.java b/src/main/org/firebirdsql/jdbc/field/FBDateField.java index c95f6c0837..d5ab2ccefe 100644 --- a/src/main/org/firebirdsql/jdbc/field/FBDateField.java +++ b/src/main/org/firebirdsql/jdbc/field/FBDateField.java @@ -32,37 +32,30 @@ * @author Roman Rokytskyy * @author Mark Rotteveel */ -final class FBDateField extends FBField { +final class FBDateField extends AbstractWithoutTimeZoneField { FBDateField(FieldDescriptor fieldDescriptor, FieldDataProvider dataProvider, int requiredType) throws SQLException { super(fieldDescriptor, dataProvider, requiredType); } + @Override public Timestamp getTimestamp(Calendar cal) throws SQLException { if (isNull()) return null; return new java.sql.Timestamp(getDatatypeCoder().decodeDateCalendar(getFieldData(), cal).getTime()); } - public Timestamp getTimestamp() throws SQLException { - if (isNull()) return null; - return new Timestamp(getDate().getTime()); - } - + @Override public Date getDate(Calendar cal) throws SQLException { if (isNull()) return null; return getDatatypeCoder().decodeDateCalendar(getFieldData(), cal); } - public Date getDate() throws SQLException { - if (isNull()) return null; - return getDatatypeCoder().decodeDate(getFieldData()); - } - public String getString() throws SQLException { if (isNull()) return null; return getDatatypeCoder().decodeDate(getFieldData()).toString(); } + @Override public void setString(String value) throws SQLException { if (value == null) { setNull(); @@ -72,6 +65,7 @@ public void setString(String value) throws SQLException { setDate(Date.valueOf(value)); } + @Override public void setTimestamp(Timestamp value, Calendar cal) throws SQLException { if (value == null) { setNull(); @@ -81,15 +75,7 @@ public void setTimestamp(Timestamp value, Calendar cal) throws SQLException { setFieldData(getDatatypeCoder().encodeDateCalendar(new java.sql.Date(value.getTime()), cal)); } - public void setTimestamp(Timestamp value) throws SQLException { - if (value == null) { - setNull(); - return; - } - - setDate(new Date(value.getTime())); - } - + @Override public void setDate(Date value, Calendar cal) throws SQLException { if (value == null) { setNull(); @@ -99,15 +85,6 @@ public void setDate(Date value, Calendar cal) throws SQLException { setFieldData(getDatatypeCoder().encodeDateCalendar(value, cal)); } - public void setDate(Date value) throws SQLException { - if (value == null) { - setNull(); - return; - } - - setFieldData(getDatatypeCoder().encodeDate(value)); - } - @Override public DatatypeCoder.RawDateTimeStruct getRawDateTimeStruct() throws SQLException { if (isNull()) return null; diff --git a/src/main/org/firebirdsql/jdbc/field/FBTimestampField.java b/src/main/org/firebirdsql/jdbc/field/FBTimestampField.java index 83f7ecb737..54c92e1deb 100644 --- a/src/main/org/firebirdsql/jdbc/field/FBTimestampField.java +++ b/src/main/org/firebirdsql/jdbc/field/FBTimestampField.java @@ -52,13 +52,6 @@ public Date getDate(Calendar cal) throws SQLException { return new java.sql.Date(getDatatypeCoder().decodeTimestampCalendar(getFieldData(), cal).getTime()); } - @Override - public Date getDate() throws SQLException { - if (isNull()) return null; - - return getDate(getCalendar()); - } - public Time getTime(Calendar cal) throws SQLException { if (isNull()) return null; @@ -89,16 +82,6 @@ public void setDate(Date value, Calendar cal) throws SQLException { setFieldData(getDatatypeCoder().encodeTimestampCalendar(new java.sql.Timestamp(value.getTime()), cal)); } - @Override - public final void setDate(Date value) throws SQLException { - if (value == null) { - setNull(); - return; - } - - setDate(value, getCalendar()); - } - public void setTime(Time value, Calendar cal) throws SQLException { if (value == null) { setNull();