Skip to content

Avoid exception when using sqlDate#7565

Merged
gmethvin merged 2 commits intoplayframework:masterfrom
marcospereira:issue-7522-forms-sqlFormat
Jul 6, 2017
Merged

Avoid exception when using sqlDate#7565
gmethvin merged 2 commits intoplayframework:masterfrom
marcospereira:issue-7522-forms-sqlFormat

Conversation

@marcospereira
Copy link
Member

Fixes

Fixes #7522.

Purpose

This is using the LocalDate format to bind/unbind java.sql.Date since the conversion between these two types is straightforward and supported.

@@ -225,15 +223,15 @@ object Formats {
*/
def sqlDateFormat(pattern: String, timeZone: TimeZone = TimeZone.getDefault): Formatter[java.sql.Date] = new Formatter[java.sql.Date] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you're ignoring the timeZone parameter now. I think that's correct behaviour, since the JDBC driver should be using the JRE's default timezone and we should just use the default too. But I just want to check that it's intentional to ignore this parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts, we may want to allow the user to set this parameter if their JDBC driver has different behaviour and expects, e.g. a UTC timezone.

Copy link
Member Author

@marcospereira marcospereira Jul 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional since we are converting to a LocalDate, which does not have a timezone. From the docs:

A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-03.

And from java.sql.Date.valueOf:

The conversion creates a LocalDate that represents the same date value as this Date in local time zone.

I think the problem here is that we are missing a sqlTimestampFormat to support java.sql.Timestamp (which can be converted to/from LocalDateTime).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the timeZone parameter is not used it seems like it should be removed, deprecated or have a comment about it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Maybe the best option here is to have two methods instead of just one:

  1. One without the timezone
  2. Another with the timezone, but deprecated.

We won't have binary compatibility, but we can have code compatibility and then warn users about the deprecation.

WDTY?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we deprecate the one with the timezone doesn't that still give us binary compatibility?

It seems reasonable to deprecate if the code never actually used the timezone, since it's a confusing/useless API with an obvious replacement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR is closed I created an issue to track this: #7590

@gmethvin gmethvin merged commit 639a745 into playframework:master Jul 6, 2017
@marcospereira marcospereira deleted the issue-7522-forms-sqlFormat branch July 6, 2017 22:21
gmethvin pushed a commit that referenced this pull request Jul 6, 2017
* Avoid exception when using sqlDate

Fix #7522.

* Add form support for java.sql.Timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants