Skip to content
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

Merged
merged 1 commit into from
Dec 6, 2021
Merged

Upgrade to support H2 2.0. #204

merged 1 commit into from
Dec 6, 2021

Conversation

gregturn
Copy link
Contributor

@gregturn gregturn commented Dec 6, 2021

[resolves #203]

[resolves #203]

Signed-off-by: Greg L. Turnquist <[email protected]>
@@ -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();
Copy link

Choose a reason for hiding this comment

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

  1. (int) result.getUpdateCount() does exactly the same, but without allocation of java.lang.Long.
  2. H2 actually can return values larger than Integer.MAX_VALUE from some operations, for example, from TRUNCATE TABLE, so it would be better to handle it in some better way.

Copy link
Contributor Author

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);
Copy link

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.

Copy link
Contributor Author

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")});
Copy link

Choose a reason for hiding this comment

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

ValueTinyint.get().

Copy link
Contributor Author

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;
Copy link

Choose a reason for hiding this comment

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

|| Value.CHAR == dataType.

Copy link
Contributor Author

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;
Copy link

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.

Copy link
Contributor Author

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>
Copy link

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.

Copy link
Contributor Author

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"));
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Jan 7, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants