Skip to content

Commit

Permalink
style: import java.time types in more classes (#2382)
Browse files Browse the repository at this point in the history
Use imports for java.time types in all remaining classes.

Follow up for #2380
  • Loading branch information
marschall committed Dec 31, 2021
1 parent f06a332 commit 54e5598
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
44 changes: 24 additions & 20 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgPreparedStatement.java
Expand Up @@ -65,6 +65,10 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Map;
Expand Down Expand Up @@ -591,8 +595,8 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
java.sql.Date tmpd;
if (in instanceof java.util.Date) {
tmpd = new java.sql.Date(((java.util.Date) in).getTime());
} else if (in instanceof java.time.LocalDate) {
setDate(parameterIndex, (java.time.LocalDate) in);
} else if (in instanceof LocalDate) {
setDate(parameterIndex, (LocalDate) in);
break;
} else {
tmpd = getTimestampUtils().toDate(getDefaultCalendar(), in.toString());
Expand All @@ -607,8 +611,8 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
java.sql.Time tmpt;
if (in instanceof java.util.Date) {
tmpt = new java.sql.Time(((java.util.Date) in).getTime());
} else if (in instanceof java.time.LocalTime) {
setTime(parameterIndex, (java.time.LocalTime) in);
} else if (in instanceof LocalTime) {
setTime(parameterIndex, (LocalTime) in);
break;
} else {
tmpt = getTimestampUtils().toTime(getDefaultCalendar(), in.toString());
Expand All @@ -625,8 +629,8 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
java.sql.Timestamp tmpts;
if (in instanceof java.util.Date) {
tmpts = new java.sql.Timestamp(((java.util.Date) in).getTime());
} else if (in instanceof java.time.LocalDateTime) {
setTimestamp(parameterIndex, (java.time.LocalDateTime) in);
} else if (in instanceof LocalDateTime) {
setTimestamp(parameterIndex, (LocalDateTime) in);
break;
} else {
tmpts = getTimestampUtils().toTimestamp(getDefaultCalendar(), in.toString());
Expand All @@ -635,8 +639,8 @@ public void setObject(@Positive int parameterIndex, @Nullable Object in,
}
break;
case Types.TIMESTAMP_WITH_TIMEZONE:
if (in instanceof java.time.OffsetDateTime) {
setTimestamp(parameterIndex, (java.time.OffsetDateTime) in);
if (in instanceof OffsetDateTime) {
setTimestamp(parameterIndex, (OffsetDateTime) in);
} else if (in instanceof PGTimestamp) {
setObject(parameterIndex, in);
} else {
Expand Down Expand Up @@ -980,14 +984,14 @@ public void setObject(@Positive int parameterIndex, @Nullable Object x) throws S
setPGobject(parameterIndex, (PGobject) x);
} else if (x instanceof Character) {
setString(parameterIndex, ((Character) x).toString());
} else if (x instanceof java.time.LocalDate) {
setDate(parameterIndex, (java.time.LocalDate) x);
} else if (x instanceof java.time.LocalTime) {
setTime(parameterIndex, (java.time.LocalTime) x);
} else if (x instanceof java.time.LocalDateTime) {
setTimestamp(parameterIndex, (java.time.LocalDateTime) x);
} else if (x instanceof java.time.OffsetDateTime) {
setTimestamp(parameterIndex, (java.time.OffsetDateTime) x);
} else if (x instanceof LocalDate) {
setDate(parameterIndex, (LocalDate) x);
} else if (x instanceof LocalTime) {
setTime(parameterIndex, (LocalTime) x);
} else if (x instanceof LocalDateTime) {
setTimestamp(parameterIndex, (LocalDateTime) x);
} else if (x instanceof OffsetDateTime) {
setTimestamp(parameterIndex, (OffsetDateTime) x);
} else if (x instanceof Map) {
setMap(parameterIndex, (Map<?, ?>) x);
} else if (x instanceof Number) {
Expand Down Expand Up @@ -1425,23 +1429,23 @@ public void setTimestamp(@Positive int i, @Nullable Timestamp t,
bindString(i, getTimestampUtils().toString(cal, t), oid);
}

private void setDate(@Positive int i, java.time.LocalDate localDate) throws SQLException {
private void setDate(@Positive int i, LocalDate localDate) throws SQLException {
int oid = Oid.DATE;
bindString(i, getTimestampUtils().toString(localDate), oid);
}

private void setTime(@Positive int i, java.time.LocalTime localTime) throws SQLException {
private void setTime(@Positive int i, LocalTime localTime) throws SQLException {
int oid = Oid.TIME;
bindString(i, getTimestampUtils().toString(localTime), oid);
}

private void setTimestamp(@Positive int i, java.time.LocalDateTime localDateTime)
private void setTimestamp(@Positive int i, LocalDateTime localDateTime)
throws SQLException {
int oid = Oid.TIMESTAMP;
bindString(i, getTimestampUtils().toString(localDateTime), oid);
}

private void setTimestamp(@Positive int i, java.time.OffsetDateTime offsetDateTime)
private void setTimestamp(@Positive int i, OffsetDateTime offsetDateTime)
throws SQLException {
int oid = Oid.TIMESTAMPTZ;
bindString(i, getTimestampUtils().toString(offsetDateTime), oid);
Expand Down
26 changes: 15 additions & 11 deletions pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java
Expand Up @@ -70,6 +70,10 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -582,7 +586,7 @@ public int getConcurrency() throws SQLException {
return getTimestampUtils().toTime(cal, string);
}

private java.time.@Nullable LocalTime getLocalTime(int i) throws SQLException {
private @Nullable LocalTime getLocalTime(int i) throws SQLException {
byte[] value = getRawValue(i);
if (value == null) {
return null;
Expand Down Expand Up @@ -668,7 +672,7 @@ public int getConcurrency() throws SQLException {

}

private java.time.@Nullable OffsetDateTime getOffsetDateTime(int i) throws SQLException {
private @Nullable OffsetDateTime getOffsetDateTime(int i) throws SQLException {
byte[] value = getRawValue(i);
if (value == null) {
return null;
Expand Down Expand Up @@ -708,7 +712,7 @@ public int getConcurrency() throws SQLException {
return getTimestampUtils().toOffsetDateTime(string);
}

private java.time.@Nullable LocalDateTime getLocalDateTime(int i) throws SQLException {
private @Nullable LocalDateTime getLocalDateTime(int i) throws SQLException {
byte[] value = getRawValue(i);
if (value == null) {
return null;
Expand Down Expand Up @@ -3691,22 +3695,22 @@ public void updateArray(String columnName, @Nullable Array x) throws SQLExceptio
throw new PSQLException(GT.tr("Invalid Inet data."), PSQLState.INVALID_PARAMETER_VALUE, ex);
}
// JSR-310 support
} else if (type == java.time.LocalDate.class) {
} else if (type == LocalDate.class) {
if (sqlType == Types.DATE) {
Date dateValue = getDate(columnIndex);
if (dateValue == null) {
return null;
}
long time = dateValue.getTime();
if (time == PGStatement.DATE_POSITIVE_INFINITY) {
return type.cast(java.time.LocalDate.MAX);
return type.cast(LocalDate.MAX);
}
if (time == PGStatement.DATE_NEGATIVE_INFINITY) {
return type.cast(java.time.LocalDate.MIN);
return type.cast(LocalDate.MIN);
}
return type.cast(dateValue.toLocalDate());
} else if (sqlType == Types.TIMESTAMP) {
java.time.LocalDateTime localDateTimeValue = getLocalDateTime(columnIndex);
LocalDateTime localDateTimeValue = getLocalDateTime(columnIndex);
if (localDateTimeValue == null) {
return null;
}
Expand All @@ -3715,23 +3719,23 @@ public void updateArray(String columnName, @Nullable Array x) throws SQLExceptio
throw new PSQLException(GT.tr("conversion to {0} from {1} not supported", type, getPGType(columnIndex)),
PSQLState.INVALID_PARAMETER_VALUE);
}
} else if (type == java.time.LocalTime.class) {
} else if (type == LocalTime.class) {
if (sqlType == Types.TIME) {
return type.cast(getLocalTime(columnIndex));
} else {
throw new PSQLException(GT.tr("conversion to {0} from {1} not supported", type, getPGType(columnIndex)),
PSQLState.INVALID_PARAMETER_VALUE);
}
} else if (type == java.time.LocalDateTime.class) {
} else if (type == LocalDateTime.class) {
if (sqlType == Types.TIMESTAMP) {
return type.cast(getLocalDateTime(columnIndex));
} else {
throw new PSQLException(GT.tr("conversion to {0} from {1} not supported", type, getPGType(columnIndex)),
PSQLState.INVALID_PARAMETER_VALUE);
}
} else if (type == java.time.OffsetDateTime.class) {
} else if (type == OffsetDateTime.class) {
if (sqlType == Types.TIMESTAMP_WITH_TIMEZONE || sqlType == Types.TIMESTAMP) {
java.time.OffsetDateTime offsetDateTime = getOffsetDateTime(columnIndex);
OffsetDateTime offsetDateTime = getOffsetDateTime(columnIndex);
return type.cast(offsetDateTime);
} else {
throw new PSQLException(GT.tr("conversion to {0} from {1} not supported", type, getPGType(columnIndex)),
Expand Down

0 comments on commit 54e5598

Please sign in to comment.