Skip to content

Commit

Permalink
Revert "WIP speed up getDate (#3108)" (#3125)
Browse files Browse the repository at this point in the history
This reverts commit f5d6e3f.
  • Loading branch information
davecramer committed Feb 16, 2024
1 parent f5d6e3f commit a408946
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 160 deletions.
6 changes: 3 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/jdbc/ArrayDecoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Object parseValue(String stringVal, BaseConnection connection) throws SQLExcepti

@Override
Object parseValue(String stringVal, BaseConnection connection) throws SQLException {
return connection.getTimestampUtils().toDate(null, stringVal.getBytes());
return connection.getTimestampUtils().toDate(null, stringVal);
}
};

Expand All @@ -345,7 +345,7 @@ Object parseValue(String stringVal, BaseConnection connection) throws SQLExcepti

@Override
Object parseValue(String stringVal, BaseConnection connection) throws SQLException {
return connection.getTimestampUtils().toTime(null, stringVal.getBytes());
return connection.getTimestampUtils().toTime(null, stringVal);
}
};

Expand All @@ -354,7 +354,7 @@ Object parseValue(String stringVal, BaseConnection connection) throws SQLExcepti

@Override
Object parseValue(String stringVal, BaseConnection connection) throws SQLException {
return connection.getTimestampUtils().toTimestamp(null, stringVal.getBytes());
return connection.getTimestampUtils().toTimestamp(null, stringVal);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ protected BatchResultHandler createBatchHandler(Query[] queries,
}

String value = result.toString();
return getTimestampUtils().toDate(cal, value.getBytes());
return getTimestampUtils().toDate(cal, value);
}

@Override
Expand All @@ -491,7 +491,7 @@ protected BatchResultHandler createBatchHandler(Query[] queries,
}

String value = result.toString();
return getTimestampUtils().toTime(cal, value.getBytes());
return getTimestampUtils().toTime(cal, value);
}

@Override
Expand All @@ -503,7 +503,7 @@ protected BatchResultHandler createBatchHandler(Query[] queries,
}

String value = result.toString();
return getTimestampUtils().toTimestamp(cal, value.getBytes());
return getTimestampUtils().toTimestamp(cal, value);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
setDate(parameterIndex, (LocalDate) in);
break;
} else {
tmpd = getTimestampUtils().toDate(getDefaultCalendar(), in.toString().getBytes());
tmpd = getTimestampUtils().toDate(getDefaultCalendar(), in.toString());
}
setDate(parameterIndex, tmpd);
}
Expand All @@ -665,7 +665,7 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
setTime(parameterIndex, (OffsetTime) in);
break;
} else {
tmpt = getTimestampUtils().toTime(getDefaultCalendar(), in.toString().getBytes());
tmpt = getTimestampUtils().toTime(getDefaultCalendar(), in.toString());
}
setTime(parameterIndex, tmpt);
}
Expand All @@ -683,7 +683,7 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
setTimestamp(parameterIndex, (LocalDateTime) in);
break;
} else {
tmpts = getTimestampUtils().toTimestamp(getDefaultCalendar(), in.toString().getBytes());
tmpts = getTimestampUtils().toTimestamp(getDefaultCalendar(), in.toString());
}
setTimestamp(parameterIndex, tmpts);
}
Expand Down
23 changes: 11 additions & 12 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public int getConcurrency() throws SQLException {
}
}

return getTimestampUtils().toDate(cal, castNonNull(value));
return getTimestampUtils().toDate(cal, castNonNull(getString(i)));
}

@Override
Expand Down Expand Up @@ -589,7 +589,8 @@ public int getConcurrency() throws SQLException {
}
}

return getTimestampUtils().toTime(cal, value);
String string = getString(i);
return getTimestampUtils().toTime(cal, string);
}

@Pure
Expand Down Expand Up @@ -630,7 +631,7 @@ public int getConcurrency() throws SQLException {
tsUnixEpochDate.setNanos(tsWithMicros.getNanos());
return tsUnixEpochDate;
} else if (oid == Oid.DATE) {
return new Timestamp(castNonNull(getDate(i, cal)).getTime());
new Timestamp(castNonNull(getDate(i, cal)).getTime());
} else {
throw new PSQLException(
GT.tr("Cannot convert the column of type {0} to requested type {1}.",
Expand All @@ -642,15 +643,16 @@ public int getConcurrency() throws SQLException {
// If this is actually a timestamptz, the server-provided timezone will override
// the one we pass in, which is the desired behaviour. Otherwise, we'll
// interpret the timezone-less value in the provided timezone.
String string = castNonNull(getString(i));
if (oid == Oid.TIME || oid == Oid.TIMETZ) {
// If server sends us a TIME, we ensure java counterpart has date of 1970-01-01
Timestamp tsWithMicros = getTimestampUtils().toTimestamp(cal, value);
Timestamp tsUnixEpochDate = new Timestamp(getTimestampUtils().toTime(cal, value).getTime());
Timestamp tsWithMicros = getTimestampUtils().toTimestamp(cal, string);
Timestamp tsUnixEpochDate = new Timestamp(getTimestampUtils().toTime(cal, string).getTime());
tsUnixEpochDate.setNanos(tsWithMicros.getNanos());
return tsUnixEpochDate;
}

return getTimestampUtils().toTimestamp(cal, value);
return getTimestampUtils().toTimestamp(cal, string);

}

Expand Down Expand Up @@ -679,7 +681,7 @@ public int getConcurrency() throws SQLException {

if (oid == Oid.TIMESTAMPTZ || oid == Oid.TIMESTAMP ) {

OffsetDateTime offsetDateTime = getTimestampUtils().toOffsetDateTime(value);
OffsetDateTime offsetDateTime = getTimestampUtils().toOffsetDateTime(castNonNull(getString(i)));
if ( offsetDateTime != OffsetDateTime.MAX && offsetDateTime != OffsetDateTime.MIN ) {
return offsetDateTime.withOffsetSameInstant(ZoneOffset.UTC);
} else {
Expand All @@ -688,7 +690,7 @@ public int getConcurrency() throws SQLException {

}
if ( oid == Oid.TIMETZ ) {
return getTimestampUtils().toOffsetDateTime(value);
return getTimestampUtils().toOffsetDateTime(castNonNull(getString(i)));
}
}

Expand Down Expand Up @@ -761,10 +763,7 @@ public int getConcurrency() throws SQLException {
}
} else {
// string
if (oid == Oid.DATE ) {
return getTimestampUtils().toLocalDate(value);
}
if (oid == Oid.TIMESTAMP) {
if (oid == Oid.DATE || oid == Oid.TIMESTAMP) {
return getTimestampUtils().toLocalDateTime(castNonNull(getString(i))).toLocalDate();
}
}
Expand Down
Loading

0 comments on commit a408946

Please sign in to comment.