Skip to content

Commit

Permalink
JDBC-540 Apply session time zone for DATE as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Mar 30, 2019
1 parent 8cd0e91 commit 95e1857
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 62 deletions.
Expand Up @@ -20,14 +20,15 @@

import org.firebirdsql.gds.ng.fields.FieldDescriptor;

import java.sql.Date;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
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 <a href="mailto:mrotteveel@users.sourceforge.net">Mark Rotteveel</a>
*/
Expand All @@ -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();
}
Expand Down
35 changes: 6 additions & 29 deletions src/main/org/firebirdsql/jdbc/field/FBDateField.java
Expand Up @@ -32,37 +32,30 @@
* @author <a href="mailto:rrokytskyy@users.sourceforge.net">Roman Rokytskyy</a>
* @author <a href="mailto:mrotteveel@users.sourceforge.net">Mark Rotteveel</a>
*/
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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand Down
17 changes: 0 additions & 17 deletions src/main/org/firebirdsql/jdbc/field/FBTimestampField.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 95e1857

Please sign in to comment.