Skip to content

Handle null values in IntervalConverter and TimestampConverter in jOOQ #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ private static class IntervalConverter implements Converter<ULong, Duration> {

@Override
public Duration from(ULong databaseObject) {
return Duration.of(databaseObject.longValue(), ChronoUnit.MICROS);
return databaseObject == null ? null : Duration.of(databaseObject.longValue(), ChronoUnit.MICROS);
}

@Override
public ULong to(Duration userObject) {
return ULong.valueOf(TimeUnit.NANOSECONDS.toMicros(userObject.toNanos()));
return userObject == null ? null : ULong.valueOf(TimeUnit.NANOSECONDS.toMicros(userObject.toNanos()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public void get(BindingGetResultSetContext<Duration> ctx) throws SQLException {
private static class IntervalConverter implements Converter<YearToSecond, Duration> {
@Override
public Duration from(YearToSecond databaseObject) {
return databaseObject.toDuration();
return databaseObject == null ? null : databaseObject.toDuration();
}

@Override
public YearToSecond to(Duration userObject) {
return YearToSecond.valueOf(userObject);
return userObject == null ? null : YearToSecond.valueOf(userObject);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public void get(BindingGetResultSetContext<Instant> ctx) throws SQLException {
private static class TimestampConverter implements Converter<LocalDateTime, Instant> {
@Override
public Instant from(LocalDateTime databaseObject) {
return databaseObject.toInstant(ZoneOffset.UTC);
return databaseObject == null ? null : databaseObject.toInstant(ZoneOffset.UTC);
}

@Override
public LocalDateTime to(Instant userObject) {
return LocalDateTime.ofInstant(userObject, ZoneOffset.UTC);
return userObject == null ? null : LocalDateTime.ofInstant(userObject, ZoneOffset.UTC);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void get(BindingGetResultSetContext<YSON> ctx) throws SQLException {
private static class YsonConverter implements Converter<Object, YSON> {
@Override
public YSON from(Object databaseObject) {
return (YSON) databaseObject;
return databaseObject == null ? null : (YSON) databaseObject;
}

@Override
Expand Down