-
Notifications
You must be signed in to change notification settings - Fork 356
Support for Dialect specific custom conversions and OffsetDateTime. #981
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
Conversation
Dialects may now register a list of converters to take into consideration when reading or writing properties. See `JdbcSqlServerDialect` for an example. By default `OffsetDateTime` does not get converted anymore. If a database needs a conversion it can register it by implementing `Dialect.getConverters()` as described above. Closes #935
Removes superfluous method.
@@ -96,8 +101,22 @@ public JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, NamedParam | |||
* @return will never be {@literal null}. | |||
*/ | |||
@Bean | |||
public JdbcCustomConversions jdbcCustomConversions() { | |||
return new JdbcCustomConversions(); | |||
public JdbcCustomConversions jdbcCustomConversions(Dialect dialect) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potential way out could be injecting ApplicationContext
into this class making it ApplicationContextAware
and handle the lookup through context.getBean(…)
.
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Something's off with formatting here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly? I double checked my configuration, and don't see the mistake.
* | ||
* @return a collection of converters for this dialect. | ||
*/ | ||
default Collection<Object> getConverters() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few comments, mostly about style. It would be a good idea to document that some dialects use driver-specific API and that these classes need to be present.
* @since 2.3 | ||
*/ | ||
@ReadingConverter | ||
enum Timestamp2OffsetDateTimeConverter implements Converter<Timestamp, OffsetDateTime> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about TimestampAtUtcToOffsetDateTimeConverter
to make it more descriptive than Timestamp2
.
* @since 2.3 | ||
*/ | ||
@WritingConverter | ||
enum OffsetDateTime2TimestampConverter implements Converter<OffsetDateTime, Timestamp> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OffsetDateTimeToTimestampConverter
import org.springframework.data.relational.core.dialect.SqlServerDialect; | ||
|
||
/** | ||
* {@link Db2Dialect} that registers JDBC specific converters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: SQL Server
} | ||
|
||
@ReadingConverter | ||
enum DateTimeOffset2OffsetDateTimeConverter implements Converter<DateTimeOffset, OffsetDateTime> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTimeOffsetToOffsetDateTimeConverter
} | ||
|
||
@WritingConverter | ||
enum OffsetDateTime2TimestampJdbcValueConverter implements Converter<OffsetDateTime, JdbcValue> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OffsetDateTimeToJdbcValueConverter
} | ||
|
||
@ReadingConverter | ||
enum TimestampWithTimeZone2OffsetDateTimeConverter implements Converter<TimestampWithTimeZone, OffsetDateTime> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TimestampWithTimeZoneToOffsetDateTimeConverter
@Override | ||
public Collection<Object> getConverters() { | ||
|
||
ArrayList<Object> converters = new ArrayList<>(super.getConverters()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: List<Object>
instead of ArrayList
import static org.assertj.core.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Formatting
Dialects now can define a set of known simple types the driver can handle without further interaction. This is done to avoid warnings during converter registration for types known in one environment but not the other. Also move types around a bit, change visibility and make sure jdbc specific dialects inherit converters from their parents.
Dialects may now register a list of converters to take into consideration when reading or writing properties. See `JdbcSqlServerDialect` for an example. By default `OffsetDateTime` does not get converted anymore. If a database needs a conversion it can register it by implementing `Dialect.getConverters()` as described above. Closes #935 Original pull request #981
Dialects now can define a set of known simple types the driver can handle without further interaction. This is done to avoid warnings during converter registration for types known in one environment but not the other. Also move types around a bit, change visibility and make sure jdbc specific dialects inherit converters from their parents. Original pull request #981 See #935
That's merged into main. |
Dialects may now register a list of converters to take into consideration when reading or writing properties.
See
JdbcSqlServerDialect
for an example.By default
OffsetDateTime
does not get converted anymore.If a database needs a conversion it can register it by implementing
Dialect.getConverters()
as described above.Closes #935