Skip to content

Add a couple missing java.time types to StatementCreatorUtils#30123

Merged
simonbasle merged 2 commits intospring-projects:mainfrom
simonbasle:moreJavaTimeTypes
Apr 4, 2023
Merged

Add a couple missing java.time types to StatementCreatorUtils#30123
simonbasle merged 2 commits intospring-projects:mainfrom
simonbasle:moreJavaTimeTypes

Conversation

@simonbasle
Copy link
Copy Markdown
Contributor

This commit adds mapping for two types from the java.time package,
complementing the types that are already translatable to Sql types
TIME, DATE and TIMESTAMP:

  • OffsetTime maps to a TIME_WITH_TIMEZONE
  • OffsetDateTime maps to a TIMESTAMP_WITH_TIMEZONE

This is in accordance with the B.4 table provided in the JDBC 4.2
specification.

When preparing statements, these java.time types use the setObject
method. Tests covering the 5 java.time classes have also been added.

See gh-28778
See gh-28527

This commit adds mapping for two types from the `java.time` package,
complementing the types that are already translatable to Sql types
TIME, DATE and TIMESTAMP:
 - `OffsetTime` maps to a `TIME_WITH_TIMEZONE`
 - `OffsetDateTime` maps to a `TIMESTAMP_WITH_TIMEZONE`

This is in accordance with the B.4 table provided in the JDBC 4.2
specification.

When preparing statements, these `java.time` types use the `setObject`
method. Tests covering the 5 `java.time` classes have also been added.

See spring-projectsgh-28778
See spring-projectsgh-28527
@simonbasle simonbasle added this to the 6.0.8 milestone Mar 15, 2023
@simonbasle simonbasle added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Mar 15, 2023
@simonbasle simonbasle self-assigned this Mar 15, 2023
@simonbasle simonbasle requested a review from a team March 15, 2023 16:44
@simonbasle
Copy link
Copy Markdown
Contributor Author

for reference, here's an excerpt of Table B.4 in the JDBC 4.2 specification:

PreparedStatement.setObject, PreparedStatement.setNull, RowSet.setNull and
RowSet.setObject use the mapping shown TABLE B-4 when no parameter specifying a
target JDBC type is provided.

Java Type SQL Type
java.sql.Date
DATE
java.sql.Time
TIME
java.sql.Timestamp
TIMESTAMP
java.util.Calendar
TIMESTAMP
java.util.Date
TIMESTAMP
java.time.LocalDate
DATE
java.time.LocalTime
TIME
java.time.LocalDateTime
TIMESTAMP
java.time.OffsetTime
TIME_WITH_TIMEZONE
java.time.OffsetDatetime
TIMESTAMP_WITH_TIMEZONE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant