Skip to content

Commit

Permalink
#758 Remove RawDateTimeStruct instead of deprecating it
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Jul 26, 2023
1 parent f19dc6e commit 0e82a18
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 504 deletions.
11 changes: 5 additions & 6 deletions src/docs/asciidoc/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ Though it can parse it, the resulting value will not include fractional seconds.
Below list of removals may look daunting, but if you use Jaybird only as a JDBC driver, through the JDBC API, you're likely unaffected.
Although we list them as removed without deprecation, some were marked as deprecated retroactively in Jaybird 5.0.3 or later.

This section does not include all changes to packages or classes considered internal API.

[#removal-of-packages-without-deprecation]
==== Removal of packages without deprecation

Expand Down Expand Up @@ -996,7 +998,9 @@ The following methods had their visibility reduced:

The following classes have been removed in Jaybird 6 without deprecation:

* `FbLocalDatabaseFactory` -- unused since removal of LOCAL protocol implementation in Jaybird 5.
* `FbLocalDatabaseFactory` -- unused since removal of LOCAL protocol implementation in Jaybird 5
* `DatatypeCoder.RawDateTimeStruct` (semi-internal API) -- use one of the `java.time` types (`LocalDateTime`, `LocalDate` or `LocalTime`).
Though this class is publicly accessible through `ResultSet.getObject/updateObject` and `PreparedStatement.setObject`, it is internal API, and we expect it is unlikely to be actually used in user code.

The following classes are no longer accessible in Jaybird 6:

Expand Down Expand Up @@ -1314,9 +1318,6 @@ The following methods will be removed in Jaybird 7:
It may get removed in Jaybird 7 or later.
** `getSupportedProtocols` -- use `getSupportedProtocolList()`.
It may get removed in Jaybird 7 or later.
* `FBField` (internal API)
** `getRawDateTimeStruct()` -- use `getLocalDateTime()`/`getLocalDate()`/`getLocalTime()`
** `setRawDateTimeStruct(DatatypeCoder.RawDateTimeStruct)` ` -- use `setLocalDateTime(LocalDateTime)`/`setLocalDate(LocalDate)`/`setLocalTime(LocalTime)`

[#removal-of-deprecated-classes-7]
===== Removal of deprecated classes
Expand All @@ -1327,8 +1328,6 @@ The following classes have been deprecated and will be removed in Jaybird 7:
Previous versions of `GDSFactoryPlugin` declared `throws GDSException` for some methods, but now `throws SQLException`.
To retain some semblance of backwards-compatibility, this class was retrofitted to extend `SQLException`.
It may get removed in Jaybird 7 or later.
* `DatatypeCoder.RawDateTimeStruct` -- use one of the `java.time` types (`LocalDateTime`, `LocalDate` or `LocalTime`).
Though this class is publicly accessible through `ResultSet.getObject/updateObject` and `PreparedStatement.setObject`, it is internal API, and we expect it is unlikely to be actually used in user code.

[#removal-of-deprecated-constants-7]
==== Removal of deprecated constants
Expand Down
201 changes: 0 additions & 201 deletions src/main/org/firebirdsql/gds/ng/DatatypeCoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,205 +520,4 @@ public interface DatatypeCoder {
@Override
int hashCode();

/**
* Raw date/time value.
* <p>
* Fractions are sub-second precision in 100 microseconds.
* </p>
* <p>
* We cannot simply pass millis to the database, because Firebird stores timestamp in format (citing Ann W.
* Harrison):
* </p>
* <p>
* "[timestamp is] stored a two long words, one representing the number of days since 17 Nov 1858 and one
* representing number of 100 nano-seconds since midnight" (NOTE: It is actually 100 microseconds!)
* </p>
* @deprecated use a suitable {@code java.time} type; will be removed in Jaybird 7
*/
@Deprecated(forRemoval = true, since = "6")
final class RawDateTimeStruct {
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
public int fractions; // Sub-second precision in 100 microseconds

public RawDateTimeStruct() {
}

/**
* Initializes a raw date/time value from encoded time and/or date integers.
*
* @param encodedDate
* encoded date (Modified Julian Date)
* @param hasDate
* if date should be decoded (set {@code false} for a time-only value)
* @param encodedTime
* encoded time (fractions in day)
* @param hasTime
* if time should be decoded (set {@code false} for a date-only value)
* @since 4
*/
public RawDateTimeStruct(int encodedDate, boolean hasDate, int encodedTime, boolean hasTime) {
if (hasDate) {
decodeDate(encodedDate);
}
if (hasTime) {
decodeTime(encodedTime);
}
}

public RawDateTimeStruct(RawDateTimeStruct raw) {
this.year = raw.year;
this.month = raw.month;
this.day = raw.day;
this.hour = raw.hour;
this.minute = raw.minute;
this.second = raw.second;
this.fractions = raw.fractions;
}

public int getFractionsAsNanos() {
return fractions * NANOSECONDS_PER_FRACTION;
}

/**
* Sets the sub-second fraction (100 microseconds) from a nanosecond value.
*
* @param nanos
* Sub-second nanoseconds
* @since 4
*/
public void setFractionsFromNanos(long nanos) {
fractions = (int) ((nanos / NANOSECONDS_PER_FRACTION) % FRACTIONS_PER_SECOND);
}

/**
* Encodes the date as used by Firebird (Modified Julian Date, or number of days since 17 November 1858).
*
* @return Encoded date
* @since 4.0
*/
public int getEncodedDate() {
return FbDatetimeConversion.toModifiedJulianDate(toLocalDate());
}

private void decodeDate(int encodedDate) {
updateDate(FbDatetimeConversion.fromModifiedJulianDate(encodedDate));
}

/**
* Encodes the time as used by Firebird (fractions (100 milliseconds) in a day).
*
* @return Encoded time
* @since 4.0
*/
public int getEncodedTime() {
return FbDatetimeConversion.toFbTimeUnits(toLocalTime());
}

private void decodeTime(int encodedTime) {
updateTime(FbDatetimeConversion.fromFbTimeUnits(encodedTime));
}

/**
* Update the date fields from a calendar.
*
* @param c
* calendar
*/
void updateDate(Calendar c) {
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH) + 1;
day = c.get(Calendar.DAY_OF_MONTH);
}

/**
* Updates the date fields from a local date.
*
* @param localDate
* local date
*/
public void updateDate(LocalDate localDate) {
year = localDate.getYear();
month = localDate.getMonthValue();
day = localDate.getDayOfMonth();
}

/**
* Updates the time field from a calendar and (optional) nanoseconds component.
* <p>
* When a non-negative {@code nanos} is provided, the {@code MILLISECOND} component of {@code c} is ignored.
* </p>
*
* @param c
* calendar
* @param nanos
* nanosecond component (ignored if {@code < 0})
*/
void updateTime(Calendar c, long nanos) {
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
second = c.get(Calendar.SECOND);
if (nanos < 0) {
fractions = c.get(Calendar.MILLISECOND) * FRACTIONS_PER_MILLISECOND;
} else {
setFractionsFromNanos(nanos);
}
}

/**
* Updates the time fields from a local time.
*
* @param localTime
* local time
*/
public void updateTime(LocalTime localTime) {
hour = localTime.getHour();
minute = localTime.getMinute();
second = localTime.getSecond();
setFractionsFromNanos(localTime.getNano());
}

/**
* Updates the date and time fields from a local datetime.
*
* @param localDateTime
* local datetime
*/
public void updateDateTime(LocalDateTime localDateTime) {
updateDate(localDateTime.toLocalDate());
updateTime(localDateTime.toLocalTime());
}

/**
* Converts the current date field values to a local date.
*
* @return local date
*/
public LocalDate toLocalDate() {
return LocalDate.of(year, month, day);
}

/**
* Converts the current time field values to a local time.
*
* @return local time
*/
public LocalTime toLocalTime() {
return LocalTime.of(hour, minute, second, getFractionsAsNanos());
}

/**
* Converts the current date and time field values to a local datetime
*
* @return local datetime
*/
public LocalDateTime toLocalDateTime() {
return LocalDateTime.of(toLocalDate(), toLocalTime());
}

}
}
2 changes: 0 additions & 2 deletions src/main/org/firebirdsql/jdbc/JavaTypeNameConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public final class JavaTypeNameConstants {
public static final String OFFSET_TIME_CLASS_NAME = "java.time.OffsetTime";
public static final String SQL_DATE_CLASS_NAME = "java.sql.Date";
public static final String LOCAL_DATE_CLASS_NAME = "java.time.LocalDate";
public static final String RAW_DATE_TIME_STRUCT_CLASS_NAME =
"org.firebirdsql.gds.ng.DatatypeCoder$RawDateTimeStruct";
public static final String ARRAY_CLASS_NAME = "java.sql.Array";
public static final String ROW_ID_CLASS_NAME = "java.sql.RowId";
public static final String FB_ROW_ID_CLASS_NAME = "org.firebirdsql.jdbc.FBRowId";
Expand Down
20 changes: 0 additions & 20 deletions src/main/org/firebirdsql/jdbc/field/FBDateField.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.firebirdsql.jdbc.field;

import org.firebirdsql.gds.ng.DatatypeCoder;
import org.firebirdsql.gds.ng.fields.FieldDescriptor;
import org.firebirdsql.jaybird.util.FbDatetimeConversion;

Expand Down Expand Up @@ -74,23 +73,4 @@ void setLocalDate(LocalDate value) throws SQLException {
setFieldData(getDatatypeCoder().encodeLocalDate(value));
}

@SuppressWarnings("removal")
@Override
public DatatypeCoder.RawDateTimeStruct getRawDateTimeStruct() throws SQLException {
return convertForGet(getLocalDate(),
v -> {
var raw = new DatatypeCoder.RawDateTimeStruct();
raw.updateDate(v);
return raw;
},
DatatypeCoder.RawDateTimeStruct.class);
}

@SuppressWarnings("removal")
@Override
public void setRawDateTimeStruct(DatatypeCoder.RawDateTimeStruct raw) throws SQLException {
setLocalDate(convertForSet(raw, DatatypeCoder.RawDateTimeStruct::toLocalDate,
DatatypeCoder.RawDateTimeStruct.class));
}

}
23 changes: 0 additions & 23 deletions src/main/org/firebirdsql/jdbc/field/FBField.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ public <T> T getObject(Class<T> type) throws SQLException {
case INPUT_STREAM_CLASS_NAME -> getBinaryStream();
case READER_CLASS_NAME -> getCharacterStream();
case ROW_ID_CLASS_NAME, FB_ROW_ID_CLASS_NAME -> getRowId();
case RAW_DATE_TIME_STRUCT_CLASS_NAME -> getRawDateTimeStruct();
case DECIMAL_CLASS_NAME -> getDecimal();
case DECIMAL32_CLASS_NAME -> getDecimal(Decimal32.class);
case DECIMAL64_CLASS_NAME -> getDecimal(Decimal64.class);
Expand Down Expand Up @@ -460,7 +459,6 @@ public void setBigInteger(BigInteger value) throws SQLException {
throw invalidSetConversion(BigInteger.class);
}

@SuppressWarnings("removal")
public void setObject(Object value) throws SQLException {
if (setWhenNull(value)) return;
// As a form of optimization, we switch on the class name.
Expand Down Expand Up @@ -488,7 +486,6 @@ public void setObject(Object value) throws SQLException {
case OFFSET_DATE_TIME_CLASS_NAME -> setOffsetDateTime((OffsetDateTime) value);
case ZONED_DATE_TIME_CLASS_NAME -> setZonedDateTime((ZonedDateTime) value);
case UTIL_DATE_CLASS_NAME -> setTimestamp(new Timestamp(((java.util.Date) value).getTime()));
case RAW_DATE_TIME_STRUCT_CLASS_NAME -> setRawDateTimeStruct((DatatypeCoder.RawDateTimeStruct) value);
case BIG_INTEGER_CLASS_NAME -> setBigInteger((BigInteger) value);
case FB_ROW_ID_CLASS_NAME -> setRowId((RowId) value);
case DECIMAL32_CLASS_NAME, DECIMAL64_CLASS_NAME, DECIMAL128_CLASS_NAME -> setDecimal((Decimal<?>) value);
Expand Down Expand Up @@ -650,26 +647,6 @@ public void setRowId(RowId rowId) throws SQLException {
throw invalidSetConversion(RowId.class);
}

/**
* @deprecated use {@link #getLocalDateTime()}, {@link #getLocalTime()} or {@link #getLocalDate()}; will be removed
* in Jaybird 7
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true, since = "6")
public DatatypeCoder.RawDateTimeStruct getRawDateTimeStruct() throws SQLException {
throw invalidGetConversion(DatatypeCoder.RawDateTimeStruct.class);
}

/**
* @deprecated use {@link #setLocalDateTime(LocalDateTime)}, {@link #setLocalTime(LocalTime)} or
* {@link #setLocalDate(LocalDate)}; will be removed in Jaybird 7
*/
@SuppressWarnings("removal")
@Deprecated(forRemoval = true, since = "6")
public void setRawDateTimeStruct(DatatypeCoder.RawDateTimeStruct raw) throws SQLException {
throw invalidSetConversion(DatatypeCoder.RawDateTimeStruct.class);
}

/**
* Sets the field to {@code NULL}, when {@code value} is {@code null}.
*
Expand Down
19 changes: 0 additions & 19 deletions src/main/org/firebirdsql/jdbc/field/FBTimeField.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.firebirdsql.jdbc.field;

import org.firebirdsql.gds.ng.DatatypeCoder;
import org.firebirdsql.gds.ng.fields.FieldDescriptor;
import org.firebirdsql.jaybird.util.FbDatetimeConversion;

Expand Down Expand Up @@ -80,22 +79,4 @@ void setLocalTime(LocalTime value) throws SQLException {
setFieldData(getDatatypeCoder().encodeLocalTime(value));
}

@SuppressWarnings("removal")
@Override
public DatatypeCoder.RawDateTimeStruct getRawDateTimeStruct() throws SQLException {
return convertForGet(getLocalTime(),
v -> {
var raw = new DatatypeCoder.RawDateTimeStruct();
raw.updateTime(v);
return raw;
}, DatatypeCoder.RawDateTimeStruct.class);
}

@SuppressWarnings("removal")
@Override
public void setRawDateTimeStruct(DatatypeCoder.RawDateTimeStruct raw) throws SQLException {
setLocalTime(convertForSet(raw, DatatypeCoder.RawDateTimeStruct::toLocalTime,
DatatypeCoder.RawDateTimeStruct.class));
}

}
20 changes: 0 additions & 20 deletions src/main/org/firebirdsql/jdbc/field/FBTimestampField.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.firebirdsql.jdbc.field;

import org.firebirdsql.gds.ng.DatatypeCoder;
import org.firebirdsql.gds.ng.fields.FieldDescriptor;
import org.firebirdsql.jaybird.util.FbDatetimeConversion;

Expand Down Expand Up @@ -88,23 +87,4 @@ void setLocalDateTime(LocalDateTime value) throws SQLException {
setFieldData(getDatatypeCoder().encodeLocalDateTime(value));
}

@SuppressWarnings("removal")
@Override
public DatatypeCoder.RawDateTimeStruct getRawDateTimeStruct() throws SQLException {
return convertForGet(getLocalDateTime(),
v -> {
var raw = new DatatypeCoder.RawDateTimeStruct();
raw.updateDateTime(v);
return raw;
},
DatatypeCoder.RawDateTimeStruct.class);
}

@SuppressWarnings("removal")
@Override
public void setRawDateTimeStruct(DatatypeCoder.RawDateTimeStruct raw) throws SQLException {
setLocalDateTime(convertForSet(raw, DatatypeCoder.RawDateTimeStruct::toLocalDateTime,
DatatypeCoder.RawDateTimeStruct.class));
}

}
Loading

0 comments on commit 0e82a18

Please sign in to comment.