Skip to content

Commit 0bfcee0

Browse files
committed
[#1558] Fix convertion to Timestamp in ResultSetAdaptor
1 parent 787896f commit 0bfcee0

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.time.LocalDate;
2828
import java.time.LocalDateTime;
2929
import java.time.LocalTime;
30-
import java.time.OffsetDateTime;
3130
import java.util.Calendar;
3231
import java.util.Map;
3332
import java.util.function.Function;
@@ -291,38 +290,18 @@ public Time getTime(String columnLabel, Calendar cal) {
291290

292291
@Override
293292
public Timestamp getTimestamp(String columnLabel) {
294-
Object rawValue = row.getValue( columnLabel );
295-
return ( wasNull = rawValue == null ) ? null : Timestamp.valueOf( toLocalDateTime( rawValue ) );
293+
LocalDateTime rawValue = row.getLocalDateTime( columnLabel );
294+
return ( wasNull = rawValue == null ) ? null : Timestamp.valueOf( rawValue );
296295
}
297296

298297
@Override
299298
public Timestamp getTimestamp(String columnLabel, Calendar cal) {
300-
Object rawValue = row.getValue( columnLabel );
301-
return ( wasNull = rawValue == null ) ? null : Timestamp.from( toOffsetDateTime( rawValue, cal ).toInstant() );
299+
LocalDateTime localDateTime = row.getLocalDateTime( columnLabel );
300+
return ( wasNull = localDateTime == null ) ? null : toTimestamp( localDateTime, cal );
302301
}
303302

304-
private static LocalDateTime toLocalDateTime(Object rawValue) {
305-
if ( rawValue instanceof OffsetDateTime ) {
306-
return LocalDateTime.from( (OffsetDateTime) rawValue );
307-
}
308-
else if ( rawValue instanceof LocalDateTime ) {
309-
return (LocalDateTime) rawValue;
310-
}
311-
else {
312-
throw new IllegalArgumentException( "Unexpected type: " + rawValue.getClass() );
313-
}
314-
}
315-
316-
private static OffsetDateTime toOffsetDateTime(Object rawValue, Calendar cal) {
317-
if ( rawValue instanceof OffsetDateTime ) {
318-
return (OffsetDateTime) rawValue;
319-
}
320-
else if ( rawValue instanceof LocalDateTime ) {
321-
return ( (LocalDateTime) rawValue ).atZone( cal.getTimeZone().toZoneId() ).toOffsetDateTime();
322-
}
323-
else {
324-
throw new IllegalArgumentException( "Unexpected type: " + rawValue.getClass() );
325-
}
303+
private static Timestamp toTimestamp(LocalDateTime localDateTime, Calendar cal) {
304+
return Timestamp.from( localDateTime.atZone( cal.getTimeZone().toZoneId() ).toInstant() );
326305
}
327306

328307
@Override
@@ -800,8 +779,8 @@ public Timestamp getTimestamp(int columnIndex) {
800779

801780
@Override
802781
public Timestamp getTimestamp(int columnIndex, Calendar cal) {
803-
Object rawValue = row.getValue( columnIndex - 1 );
804-
return ( wasNull = rawValue == null ) ? null : Timestamp.from( toOffsetDateTime( rawValue, cal ).toInstant() );
782+
LocalDateTime localDateTime = row.getLocalDateTime( columnIndex - 1 );
783+
return ( wasNull = localDateTime == null ) ? null : toTimestamp( localDateTime, cal );
805784
}
806785

807786
@Override

0 commit comments

Comments
 (0)