-
Notifications
You must be signed in to change notification settings - Fork 45
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
Upgrade to support H2 2.0. #204
Conversation
[resolves #203] Signed-off-by: Greg L. Turnquist <[email protected]>
0860b24
to
dd279a6
Compare
@@ -146,9 +149,11 @@ private H2Statement addIndex(int index, Object value) { | |||
ResultWithGeneratedKeys result = client.update(command, generatedColumns); | |||
CommandUtil.clearForReuse(command); | |||
if (GeneratedKeysMode.valueOf(generatedColumns) == GeneratedKeysMode.NONE) { | |||
return H2Result.toResult(codecs, result.getUpdateCount()); | |||
int updatedCountInt = Long.valueOf(result.getUpdateCount()).intValue(); |
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.
(int) result.getUpdateCount()
does exactly the same, but without allocation ofjava.lang.Long
.- H2 actually can return values larger than
Integer.MAX_VALUE
from some operations, for example, fromTRUNCATE TABLE
, so it would be better to handle it in some better way.
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.
Thanks @katzyn. I have applied (1), however (2) is governed by our current SPI requiring a Mono<Integer>
. This topic is being tracked via r2dbc/r2dbc-spi#255.
@@ -47,6 +47,6 @@ boolean doCanDecode(int dataType) { | |||
Value doEncode(Object[] value) { | |||
return ValueArray.get(Arrays.stream(Assert.requireNonNull(value, "value must not be null")) | |||
.map(codecs::encode) | |||
.toArray(Value[]::new)); | |||
.toArray(Value[]::new), null); |
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.
H2 2.0 has only standard-compliant typed arrays.
CastDataProvider
shouldn't be null
here. If objects of different types are passed within the same array, they need to be converted to the same higher type and some conversions need to know properties of the session.
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've opened #208 to track this.
@@ -38,6 +38,6 @@ Byte doDecode(Value value, Class<? extends Byte> type) { | |||
|
|||
@Override | |||
Value doEncode(Byte value) { | |||
return ValueByte.get(Assert.requireNonNull(value, "value must not be null")); | |||
return ValueBinary.get(new byte[]{Assert.requireNonNull(value, "value must not be null")}); |
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.
ValueTinyint.get()
.
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.
👍
return Value.STRING == dataType || | ||
Value.STRING_FIXED == dataType || | ||
Value.STRING_IGNORECASE == dataType; | ||
return Value.VARCHAR == dataType || Value.VARCHAR_IGNORECASE == dataType; |
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.
|| Value.CHAR == dataType
.
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.
👍
@@ -30,7 +30,7 @@ | |||
|
|||
@Override | |||
boolean doCanDecode(int dataType) { | |||
return dataType == Value.DECIMAL; | |||
return dataType == Value.NUMERIC; |
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.
|| dataType == Value.DECFLOAT
may be needed too. But DECFLOAT
has three special values (NaN
, Inf
, and -Inf
) not compatible with BigDecimal
, so situation is complicated.
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 opened #209 to track this.
@@ -34,6 +34,7 @@ | |||
<properties> | |||
<assertj.version>3.20.2</assertj.version> | |||
<h2.version>1.4.200</h2.version> | |||
<h2.version>2.0.202</h2.version> |
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 guess 1.4.200 needs to be removed.
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.
👍
return ValueBytes.get(Assert.requireNonNull(value, "value must not be null")); | ||
return ValueBinary.get(Assert.requireNonNull(value, "value must not be null")); |
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.
When a binary string literal is specified, its data type BINARY
or BINARY VARYING
is implementation-defined in the SQL Standard. H2 uses BINARY VARYING
and usage of BINARY
may cause various unexpected effects.
So here ValueVarbinary.get()
should be used for consistency.
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.
👍
Commit ed4e228 introduced support for H2 2.0.x but did not upgrade the H2 dependency. This commit upgrades the H2 dependency to version 2.0.206 but also adds an explicit test dependency on version 1.4.200 in spring-r2dbc, since r2dbc-h2 does not yet support H2 2.0.x. Once r2dbc/r2dbc-h2#204 has been included in a released version of r2dbc-h2 we will be able to upgrade spring-r2dbc's test dependency on the H2 database to 2.0.x as well. See spring-projectsgh-27870 See spring-projectsgh-27902
[resolves #203]