-
Notifications
You must be signed in to change notification settings - Fork 361
DATAJDBC-327 - Adds support for conversion to JdbcTypeAware and storing byte[] as binary. #123
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
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. Looks pretty decent and I think we should add some more Javadoc along with some assertions.
@@ -292,15 +288,18 @@ public long count(Class<?> domainType) { | |||
return result; | |||
} | |||
|
|||
private <S, T> MapSqlParameterSource getPropertyMap(S instance, RelationalPersistentEntity<S> persistentEntity, | |||
String prefix) { | |||
private <S, T> MapSqlParameterSource getParameterSource(S instance, RelationalPersistentEntity<S> persistentEntity, |
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: How about Predicate< RelationalPersistentProperty>
instead of skipId
?
* @since 1.1 | ||
*/ | ||
@Value(staticConstructor = "of") | ||
public class JdbcTypeAware { |
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 naming this type JdbcValue
?
* needs to be provided anyway, mostly for providing backward compatibility. Calling it will result in an exception. | ||
* The features normally supported by a {@link JdbcTypeFactory} will not work. | ||
*/ | ||
JdbcTypeFactory DUMMY_JDBC_TYPE_FACTORY = value -> { |
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 naming this one SIMPLE
? From a design perspective, we could turn the field into a static interface method to align with our API style.
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 don't like SIMPLE
because it is kind of less than simple: Not really working. How about UNSUPPORTED
?
* @param value the value to be converted. Must not be {@literal null}. | ||
* @return an {@link Array}. Guaranteed to be not {@literal null}. | ||
*/ | ||
Array createArray(Object[] value); |
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.
This is very nice that we do not declare SQLException
👍
@@ -0,0 +1,7 @@ | |||
/** |
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: Package declarations do not get author tags.
/** | ||
* In PostrgreSQL this fails if a simple converter like the following is used. | ||
* | ||
* <pre> |
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: How about <pre class="code">
? This makes formatting a bit simpler.
@@ -193,6 +193,30 @@ public Object writeValue(@Nullable Object value, TypeInformation<?> type) { | |||
return conversionService.convert(value, rawType); | |||
} | |||
|
|||
|
|||
@Override | |||
public boolean canWriteValue(Object value, TypeInformation<?> type) { |
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.
Let's keep this method on JDBC level. The underlying assumption is that a module using the converter is able to persist entities as values.
From how the method is used, I would even suggest to keep it private and consider public
exposure at a later time.
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.
The main implementation is in the BasicRelationalConverter
based on the conversions service.
If we don't want to expose it there we could drop it completely and rely on exception handling, possibly even caching failures.
Not sure that is a good way to do it though.
I'm also not sure I understood your comment about the underlying assumption.
} | ||
|
||
if (componentType == Byte.class) { | ||
Byte[] boxedBytes = (Byte[]) convertedValue; |
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.
Let's extract the code into a package-private utility (ArrayUtil.toPrimitive(…)
) or something like that.
|
||
private final JdbcOperations operations; | ||
|
||
public DefaultJdbcTypeFactory(JdbcOperations operations) { |
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: Assertion for Non-null.
…ng byte[] as binary. Some JDBC drivers depend on correct explicit type information in order to pass on parameters to the database. So far CustomConversion had no way to provide that information. With this change one can use @WritingConverter that converts to JdbcTypeAware in order to provide that information. byte[] now also get stored as BINARY. See also: DATAJDBC-239.
4afac46
to
9054265
Compare
Removed author tag for package-info.java
9054265
to
c6871ca
Compare
I fixed all the mentioned issues. |
…[] as binary. Some JDBC drivers depend on correct explicit type information in order to pass on parameters to the database. So far CustomConversion had no way to provide that information. With this change one can use @WritingConverter that converts to JdbcTypeAware in order to provide that information. byte[] now also get stored as BINARY. Original pull request: #123.
Removed author tag for package-info.java Original pull request: #123.
Extend Javadoc. Reorder constructors in the order of their parameter number. Add missing assertions. Introduce utility to create predicates. Remove unused fields. Add since tags. Reformat. Original pull request: #123.
That's merged and polished now. |
…[] as binary. Some JDBC drivers depend on correct explicit type information in order to pass on parameters to the database. So far CustomConversion had no way to provide that information. With this change one can use @WritingConverter that converts to JdbcTypeAware in order to provide that information. byte[] now also get stored as BINARY. Original pull request: spring-projects#123.
Removed author tag for package-info.java Original pull request: spring-projects#123.
Extend Javadoc. Reorder constructors in the order of their parameter number. Add missing assertions. Introduce utility to create predicates. Remove unused fields. Add since tags. Reformat. Original pull request: spring-projects#123.
Add extension for UpdateTableSpec.table. Add tests. Formatting. Original pull request: #123.
Some JDBC drivers depend on correct explicit type information in order to pass on parameters to the database.
So far CustomConversion had no way to provide that information.
With this change one can use @WritingConverter that converts to JdbcTypeAware in order to provide that information.
byte[] now also get stored as BINARY.
See also: DATAJDBC-239.