From 7213d73d3878fd688aaf0fe627b9b7d2aedc440f Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Fri, 21 Mar 2025 15:56:21 +0000
Subject: [PATCH 01/15] chore(main): release 2.28.1-SNAPSHOT (#1966)
:robot: I have created a release *beep* *boop*
---
### Updating meta-information for bleeding-edge SNAPSHOT release.
---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
---
pom.xml | 2 +-
samples/snapshot/pom.xml | 2 +-
versions.txt | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/pom.xml b/pom.xml
index 16a221b07..999527f09 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0google-cloud-spanner-jdbc
- 2.28.0
+ 2.28.1-SNAPSHOTjarGoogle Cloud Spanner JDBChttps://github.com/googleapis/java-spanner-jdbc
diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml
index f5f01ee07..ca21dc659 100644
--- a/samples/snapshot/pom.xml
+++ b/samples/snapshot/pom.xml
@@ -29,7 +29,7 @@
com.google.cloudgoogle-cloud-spanner-jdbc
- 2.28.0
+ 2.28.1-SNAPSHOT
diff --git a/versions.txt b/versions.txt
index 3fd7810ad..fc40cb452 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,4 +1,4 @@
# Format:
# module:released-version:current-version
-google-cloud-spanner-jdbc:2.28.0:2.28.0
+google-cloud-spanner-jdbc:2.28.0:2.28.1-SNAPSHOT
From 9f5805958f7f159e3a250e7b2705bc268c9abc13 Mon Sep 17 00:00:00 2001
From: Mend Renovate
Date: Fri, 21 Mar 2025 19:24:54 +0100
Subject: [PATCH 02/15] chore(deps): update dependency
com.google.cloud:google-cloud-spanner-jdbc to v2.28.0 (#1967)
---
samples/install-without-bom/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml
index 8be01f537..86d3c5fb4 100644
--- a/samples/install-without-bom/pom.xml
+++ b/samples/install-without-bom/pom.xml
@@ -29,7 +29,7 @@
com.google.cloudgoogle-cloud-spanner-jdbc
- 2.27.1
+ 2.28.0
From 7e1cf950b1849caa3ec15ec72323a7d6879efd41 Mon Sep 17 00:00:00 2001
From: Mend Renovate
Date: Fri, 21 Mar 2025 19:25:05 +0100
Subject: [PATCH 03/15] chore(deps): update dependency
com.google.cloud:libraries-bom to v26.57.0 (#1968)
---
samples/quickperf/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
samples/spring-data-jdbc/pom.xml | 2 +-
samples/spring-data-mybatis/pom.xml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/samples/quickperf/pom.xml b/samples/quickperf/pom.xml
index f39aa299c..eb3eb8fdb 100644
--- a/samples/quickperf/pom.xml
+++ b/samples/quickperf/pom.xml
@@ -27,7 +27,7 @@
com.google.cloudlibraries-bom
- 26.56.0
+ 26.57.0pomimport
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 6224f029f..4000fe786 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -26,7 +26,7 @@
com.google.cloudlibraries-bom
- 26.56.0
+ 26.57.0pomimport
diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml
index 6e2cbdf7e..fb7d2f39a 100644
--- a/samples/spring-data-jdbc/pom.xml
+++ b/samples/spring-data-jdbc/pom.xml
@@ -37,7 +37,7 @@
com.google.cloudlibraries-bom
- 26.56.0
+ 26.57.0importpom
diff --git a/samples/spring-data-mybatis/pom.xml b/samples/spring-data-mybatis/pom.xml
index 03b732041..681e6f2bf 100644
--- a/samples/spring-data-mybatis/pom.xml
+++ b/samples/spring-data-mybatis/pom.xml
@@ -35,7 +35,7 @@
com.google.cloudlibraries-bom
- 26.56.0
+ 26.57.0importpom
From a68656a41851ceb229ebf52615f658590ce5a16b Mon Sep 17 00:00:00 2001
From: Mend Renovate
Date: Sun, 30 Mar 2025 16:55:24 +0200
Subject: [PATCH 04/15] chore(deps): update dependency
com.google.cloud:libraries-bom to v26.58.0 (#1969)
---
samples/quickperf/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
samples/spring-data-jdbc/pom.xml | 2 +-
samples/spring-data-mybatis/pom.xml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/samples/quickperf/pom.xml b/samples/quickperf/pom.xml
index eb3eb8fdb..744ca4f20 100644
--- a/samples/quickperf/pom.xml
+++ b/samples/quickperf/pom.xml
@@ -27,7 +27,7 @@
com.google.cloudlibraries-bom
- 26.57.0
+ 26.58.0pomimport
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 4000fe786..2d716bdb5 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -26,7 +26,7 @@
com.google.cloudlibraries-bom
- 26.57.0
+ 26.58.0pomimport
diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml
index fb7d2f39a..4bf54fdb3 100644
--- a/samples/spring-data-jdbc/pom.xml
+++ b/samples/spring-data-jdbc/pom.xml
@@ -37,7 +37,7 @@
com.google.cloudlibraries-bom
- 26.57.0
+ 26.58.0importpom
diff --git a/samples/spring-data-mybatis/pom.xml b/samples/spring-data-mybatis/pom.xml
index 681e6f2bf..d402998a0 100644
--- a/samples/spring-data-mybatis/pom.xml
+++ b/samples/spring-data-mybatis/pom.xml
@@ -35,7 +35,7 @@
com.google.cloudlibraries-bom
- 26.57.0
+ 26.58.0importpom
From 7153c39464fd9b83609bb7cc2ada5c0f9aab3af8 Mon Sep 17 00:00:00 2001
From: Mend Renovate
Date: Tue, 1 Apr 2025 07:05:30 +0200
Subject: [PATCH 05/15] deps: update dependency
com.google.cloud:google-cloud-spanner-bom to v6.90.0 (#1970)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* deps: update dependency com.google.cloud:google-cloud-spanner-bom to v6.90.0
* chore: regenerate properties and fix a NullPointerException
* chore: skip test for graalvm
* chore: use `--strict-image-heap` on native tests
This follows from the recent configuration adjustments from bringing GraalVM for JDK 23, which enabled
this option by default.
This commit uses such option for the JDK 21 GraalVM tests to consume the configuration in the same way.
---------
Co-authored-by: Knut Olav Løite
Co-authored-by: diegomarquezp
---
documentation/connection_properties.md | 5 +++--
pom.xml | 2 +-
samples/spring-data-jdbc/pom.xml | 2 +-
.../spanner/connection/ConnectionPropertiesHelper.java | 3 ++-
.../connection/ConnectionPropertiesFileGenerator.java | 3 ++-
.../cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java | 6 ++++--
.../google-cloud-spanner-jdbc/native-image.properties | 1 +
7 files changed, 14 insertions(+), 8 deletions(-)
create mode 100644 src/test/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties
diff --git a/documentation/connection_properties.md b/documentation/connection_properties.md
index abc908842..cedb01d04 100644
--- a/documentation/connection_properties.md
+++ b/documentation/connection_properties.md
@@ -10,7 +10,7 @@ The 'Context' value indicates whether the property can only be set when a connec
| auto_batch_dml_update_count | DML statements that are executed when auto_batch_dml is set to true, are not directly sent to Spanner, but are buffered in the client until the batch is flushed. This property determines the update count that is returned for these DML statements. The default is 1, as that is the update count that is expected by most ORMs (e.g. Hibernate). | 1 | | USER |
| auto_batch_dml_update_count_verification | The update count that is returned for DML statements that are buffered during an automatic DML batch is by default 1. This value can be changed by setting the connection variable auto_batch_dml_update_count. The update counts that are returned by Spanner when the DML statements are actually executed are verified against the update counts that were returned when they were buffered. If these do not match, a com.google.cloud.spanner.DmlBatchUpdateCountVerificationFailedException will be thrown. You can disable this verification by setting auto_batch_dml_update_count_verification to false. | true | true, false | USER |
| autocommit | Should the connection start in autocommit (true/false) | true | true, false | USER |
-| autocommit_dml_mode | Determines the transaction type that is used to execute DML statements when the connection is in auto-commit mode. | TRANSACTIONAL | TRANSACTIONAL, PARTITIONED_NON_ATOMIC, TRANSACTIONAL_WITH_FALLBACK_TO_PARTITIONED_NON_ATOMIC | USER |
+| autocommit_dml_mode | Determines the transaction type that is used to execute DML statements when the connection is in auto-commit mode. | TRANSACTIONAL | TRANSACTIONAL, PARTITIONED_NON_ATOMIC, TRANSACTIONAL_WITH_FALLBACK_TO_PARTITIONED_NON_ATOMIC, null | USER |
| autoconfigemulator | Automatically configure the connection to try to connect to the Cloud Spanner emulator (true/false). The instance and database in the connection string will automatically be created if these do not yet exist on the emulator. Add dialect=postgresql to the connection string to make sure that the database that is created uses the PostgreSQL dialect. | false | true, false | STARTUP |
| autopartitionmode | Execute all queries on this connection as partitioned queries. Executing a query that cannot be partitioned will fail. Executing a query in a read/write transaction will also fail. | false | true, false | USER |
| channelprovider | The name of the channel provider class. The name must reference an implementation of ExternalChannelProvider. If this property is not set, the connection will use the default grpc channel provider. | | | STARTUP |
@@ -22,6 +22,7 @@ The 'Context' value indicates whether the property can only be set when a connec
| databaserole | Sets the database role to use for this connection. The default is privileges assigned to IAM role | | | STARTUP |
| databoostenabled | Enable data boost for all partitioned queries that are executed by this connection. This setting is only used for partitioned queries and is ignored by all other statements. | false | true, false | USER |
| ddlintransactionmode | Determines how the connection should handle DDL statements in a read/write transaction. | ALLOW_IN_EMPTY_TRANSACTION | FAIL, ALLOW_IN_EMPTY_TRANSACTION, AUTO_COMMIT_TRANSACTION | USER |
+| default_isolation_level | The transaction isolation level that is used by default for read/write transactions. The default is isolation_level_unspecified, which means that the connection will use the default isolation level of the database that it is connected to. | ISOLATION_LEVEL_UNSPECIFIED | ISOLATION_LEVEL_UNSPECIFIED, SERIALIZABLE, REPEATABLE_READ | USER |
| defaultsequencekind | The default sequence kind that should be used for the database. This property is only used when a DDL statement that requires a default sequence kind is executed on this connection. | | | USER |
| delaytransactionstartuntilfirstwrite | Enabling this option will delay the actual start of a read/write transaction until the first write operation is seen in that transaction. All reads that happen before the first write in a transaction will instead be executed as if the connection was in auto-commit mode. Enabling this option will make read/write transactions lose their SERIALIZABLE isolation level. Read operations that are executed after the first write operation in a read/write transaction will be executed using the read/write transaction. Enabling this mode can reduce locking and improve performance for applications that can handle the lower transaction isolation semantics. | false | true, false | USER |
| dialect | Sets the dialect to use for new databases that are created by this connection. | GOOGLE_STANDARD_SQL | GOOGLE_STANDARD_SQL, POSTGRESQL | STARTUP |
@@ -48,7 +49,7 @@ The 'Context' value indicates whether the property can only be set when a connec
| retryabortsinternally | Should the connection automatically retry Aborted errors (true/false) | true | true, false | USER |
| returncommitstats | Request that Spanner returns commit statistics for read/write transactions (true/false) | false | true, false | USER |
| routetoleader | Should read/write transactions and partitioned DML be routed to leader region (true/false) | true | true, false | STARTUP |
-| rpcpriority | Sets the priority for all RPC invocations from this connection (HIGH/MEDIUM/LOW). The default is HIGH. | | LOW, MEDIUM, HIGH, UNSPECIFIED | USER |
+| rpcpriority | Sets the priority for all RPC invocations from this connection (HIGH/MEDIUM/LOW). The default is HIGH. | | LOW, MEDIUM, HIGH, UNSPECIFIED, null | USER |
| savepoint_support | Determines the behavior of the connection when savepoints are used. | FAIL_AFTER_ROLLBACK | ENABLED, FAIL_AFTER_ROLLBACK, DISABLED | USER |
| tracing_prefix | The prefix that will be prepended to all OpenTelemetry traces that are generated by a Connection. | CloudSpanner | | STARTUP |
| trackconnectionleaks | Capture the call stack of the thread that created a connection. This will pre-create a LeakedConnectionException already when a connection is created. This can be disabled, for example if a monitoring system logs the pre-created exception. If disabled, the LeakedConnectionException will only be created when an actual connection leak is detected. The stack trace of the exception will in that case not contain the call stack of when the connection was created. | true | true, false | STARTUP |
diff --git a/pom.xml b/pom.xml
index 999527f09..66429c409 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,7 +61,7 @@
com.google.cloudgoogle-cloud-spanner-bom
- 6.89.0
+ 6.90.0pomimport
diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml
index 4bf54fdb3..2a29fa1c0 100644
--- a/samples/spring-data-jdbc/pom.xml
+++ b/samples/spring-data-jdbc/pom.xml
@@ -30,7 +30,7 @@
com.google.cloudgoogle-cloud-spanner-bom
- 6.89.0
+ 6.90.0importpom
diff --git a/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java b/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java
index 7e64b8f11..cde651e02 100644
--- a/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java
+++ b/src/main/java/com/google/cloud/spanner/connection/ConnectionPropertiesHelper.java
@@ -21,6 +21,7 @@
import java.sql.DriverPropertyInfo;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -50,7 +51,7 @@ public static DriverPropertyInfo toDriverPropertyInfo(
connectionProperty.getValidValues() == null
? null
: Arrays.stream(connectionProperty.getValidValues())
- .map(Object::toString)
+ .map(Objects::toString)
.toArray(String[]::new);
return result;
}
diff --git a/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java b/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java
index fe8dd9c96..4307fbcb0 100644
--- a/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java
+++ b/src/test/java/com/google/cloud/spanner/connection/ConnectionPropertiesFileGenerator.java
@@ -20,6 +20,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Objects;
import java.util.stream.Collectors;
/** Generator for the documentation/connection_properties.md file. */
@@ -65,7 +66,7 @@ static String getValidValues(ConnectionProperty connectionProperty) {
return connectionProperty.getValidValues() == null
? ""
: Arrays.stream(connectionProperty.getValidValues())
- .map(Object::toString)
+ .map(Objects::toString)
.collect(Collectors.joining(", "));
}
}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java b/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java
index 60698799f..99ee00165 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPreparedStatementTest.java
@@ -745,7 +745,8 @@ public void test04_Timestamps() throws SQLException {
// Then get it in the test timezone.
if (testCalendar != null
&& !System.getProperty("java.vm.name", "").toLowerCase().contains("graalvm")
- && !System.getProperty("java.vendor", "").toLowerCase().contains("graalvm")) {
+ && !System.getProperty("java.vendor", "").toLowerCase().contains("graalvm")
+ && !System.getProperty("java.vendor", "").toLowerCase().contains("oracle")) {
Timestamp inOtherTZ = rs.getTimestamp(4, testCalendar);
assertEquals(
"Timezone: "
@@ -768,7 +769,8 @@ public void test04_Timestamps() throws SQLException {
if (testCalendar == null) {
assertEquals(testTimestamp.getTime(), inDefaultTZ.getTime());
} else if (!System.getProperty("java.vm.name", "").toLowerCase().contains("graalvm")
- && !System.getProperty("java.vendor", "").toLowerCase().contains("graalvm")) {
+ && !System.getProperty("java.vendor", "").toLowerCase().contains("graalvm")
+ && !System.getProperty("java.vendor", "").toLowerCase().contains("oracle")) {
assertEquals(
"Timezone: "
+ testCalendar
diff --git a/src/test/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties b/src/test/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties
new file mode 100644
index 000000000..714d90fb1
--- /dev/null
+++ b/src/test/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties
@@ -0,0 +1 @@
+Args=--strict-image-heap
From 091612be3c3ed5488551262349373736415c45a0 Mon Sep 17 00:00:00 2001
From: Mend Renovate
Date: Tue, 1 Apr 2025 07:12:46 +0200
Subject: [PATCH 06/15] chore(deps): update dependency
com.google.cloud:libraries-bom to v26.59.0 (#1971)
---
samples/quickperf/pom.xml | 2 +-
samples/snippets/pom.xml | 2 +-
samples/spring-data-jdbc/pom.xml | 2 +-
samples/spring-data-mybatis/pom.xml | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/samples/quickperf/pom.xml b/samples/quickperf/pom.xml
index 744ca4f20..5e35b6317 100644
--- a/samples/quickperf/pom.xml
+++ b/samples/quickperf/pom.xml
@@ -27,7 +27,7 @@
com.google.cloudlibraries-bom
- 26.58.0
+ 26.59.0pomimport
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 2d716bdb5..e1919e95b 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -26,7 +26,7 @@
com.google.cloudlibraries-bom
- 26.58.0
+ 26.59.0pomimport
diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml
index 2a29fa1c0..380e4fad7 100644
--- a/samples/spring-data-jdbc/pom.xml
+++ b/samples/spring-data-jdbc/pom.xml
@@ -37,7 +37,7 @@
com.google.cloudlibraries-bom
- 26.58.0
+ 26.59.0importpom
diff --git a/samples/spring-data-mybatis/pom.xml b/samples/spring-data-mybatis/pom.xml
index d402998a0..1042f6340 100644
--- a/samples/spring-data-mybatis/pom.xml
+++ b/samples/spring-data-mybatis/pom.xml
@@ -35,7 +35,7 @@
com.google.cloudlibraries-bom
- 26.58.0
+ 26.59.0importpom
From 010a502310db88f8c676960c641a7e9a6581bf11 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?=
Date: Thu, 3 Apr 2025 09:09:02 +0200
Subject: [PATCH 07/15] feat: support isolation level repeatable read (#1973)
Adds support for setting the transaction isolation level to repeatable read.
---
.../spanner/jdbc/AbstractJdbcConnection.java | 10 +--
.../spanner/jdbc/IsolationLevelConverter.java | 54 ++++++++++++++
.../spanner/jdbc/JdbcDatabaseMetaData.java | 7 +-
.../jdbc/IsolationLevelConverterTest.java | 67 ++++++++++++++++++
.../spanner/jdbc/JdbcConnectionTest.java | 40 +++++------
.../jdbc/JdbcDatabaseMetaDataTest.java | 2 +-
.../jdbc/TransactionMockServerTest.java | 70 ++++++++++++++++++-
7 files changed, 219 insertions(+), 31 deletions(-)
create mode 100644 src/main/java/com/google/cloud/spanner/jdbc/IsolationLevelConverter.java
create mode 100644 src/test/java/com/google/cloud/spanner/jdbc/IsolationLevelConverterTest.java
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java
index 38430cf12..00d0823f0 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/AbstractJdbcConnection.java
@@ -41,8 +41,8 @@ abstract class AbstractJdbcConnection extends AbstractJdbcWrapper
implements CloudSpannerJdbcConnection {
private static final String CALLABLE_STATEMENTS_UNSUPPORTED =
"Callable statements are not supported";
- private static final String ONLY_SERIALIZABLE =
- "Only isolation level TRANSACTION_SERIALIZABLE is supported";
+ private static final String ONLY_SERIALIZABLE_OR_REPEATABLE_READ =
+ "Only isolation levels TRANSACTION_SERIALIZABLE and TRANSACTION_REPEATABLE_READ are supported";
private static final String ONLY_CLOSE_ALLOWED =
"Only holdability CLOSE_CURSORS_AT_COMMIT is supported";
private static final String SQLXML_UNSUPPORTED = "SQLXML is not supported";
@@ -147,13 +147,15 @@ public void setTransactionIsolation(int level) throws SQLException {
|| level == TRANSACTION_READ_COMMITTED,
"Not a transaction isolation level");
JdbcPreconditions.checkSqlFeatureSupported(
- level == TRANSACTION_SERIALIZABLE, ONLY_SERIALIZABLE);
+ JdbcDatabaseMetaData.supportsIsolationLevel(level), ONLY_SERIALIZABLE_OR_REPEATABLE_READ);
+ spanner.setDefaultIsolationLevel(IsolationLevelConverter.convertToSpanner(level));
}
@Override
public int getTransactionIsolation() throws SQLException {
checkClosed();
- return TRANSACTION_SERIALIZABLE;
+ //noinspection MagicConstant
+ return IsolationLevelConverter.convertToJdbc(spanner.getDefaultIsolationLevel());
}
@Override
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/IsolationLevelConverter.java b/src/main/java/com/google/cloud/spanner/jdbc/IsolationLevelConverter.java
new file mode 100644
index 000000000..3e3e10c9f
--- /dev/null
+++ b/src/main/java/com/google/cloud/spanner/jdbc/IsolationLevelConverter.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.spanner.jdbc;
+
+import com.google.spanner.v1.TransactionOptions.IsolationLevel;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+
+class IsolationLevelConverter {
+ static IsolationLevel convertToSpanner(int jdbcIsolationLevel) throws SQLException {
+ switch (jdbcIsolationLevel) {
+ case Connection.TRANSACTION_SERIALIZABLE:
+ return IsolationLevel.SERIALIZABLE;
+ case Connection.TRANSACTION_REPEATABLE_READ:
+ return IsolationLevel.REPEATABLE_READ;
+ case Connection.TRANSACTION_READ_COMMITTED:
+ case Connection.TRANSACTION_READ_UNCOMMITTED:
+ case Connection.TRANSACTION_NONE:
+ throw new SQLFeatureNotSupportedException(
+ "Unsupported JDBC isolation level: " + jdbcIsolationLevel);
+ default:
+ throw new IllegalArgumentException("Invalid JDBC isolation level: " + jdbcIsolationLevel);
+ }
+ }
+
+ static int convertToJdbc(IsolationLevel isolationLevel) {
+ switch (isolationLevel) {
+ // Translate UNSPECIFIED to SERIALIZABLE as that is the default isolation level.
+ case ISOLATION_LEVEL_UNSPECIFIED:
+ case SERIALIZABLE:
+ return Connection.TRANSACTION_SERIALIZABLE;
+ case REPEATABLE_READ:
+ return Connection.TRANSACTION_REPEATABLE_READ;
+ default:
+ throw new IllegalArgumentException(
+ "Unknown or unsupported isolation level: " + isolationLevel);
+ }
+ }
+}
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
index bdebcad89..b7fe95145 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaData.java
@@ -664,7 +664,12 @@ public boolean supportsTransactions() {
@Override
public boolean supportsTransactionIsolationLevel(int level) {
- return Connection.TRANSACTION_SERIALIZABLE == level;
+ return supportsIsolationLevel(level);
+ }
+
+ static boolean supportsIsolationLevel(int level) {
+ return Connection.TRANSACTION_SERIALIZABLE == level
+ || Connection.TRANSACTION_REPEATABLE_READ == level;
}
@Override
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/IsolationLevelConverterTest.java b/src/test/java/com/google/cloud/spanner/jdbc/IsolationLevelConverterTest.java
new file mode 100644
index 000000000..2be9e5ea4
--- /dev/null
+++ b/src/test/java/com/google/cloud/spanner/jdbc/IsolationLevelConverterTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2025 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.spanner.jdbc;
+
+import static com.google.cloud.spanner.jdbc.IsolationLevelConverter.convertToJdbc;
+import static com.google.cloud.spanner.jdbc.IsolationLevelConverter.convertToSpanner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+import com.google.spanner.v1.TransactionOptions.IsolationLevel;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class IsolationLevelConverterTest {
+
+ @Test
+ public void testConvertToSpanner() throws SQLException {
+ assertEquals(
+ IsolationLevel.SERIALIZABLE, convertToSpanner(Connection.TRANSACTION_SERIALIZABLE));
+ assertEquals(
+ IsolationLevel.REPEATABLE_READ, convertToSpanner(Connection.TRANSACTION_REPEATABLE_READ));
+
+ assertThrows(
+ SQLFeatureNotSupportedException.class,
+ () -> convertToSpanner(Connection.TRANSACTION_READ_COMMITTED));
+ assertThrows(
+ SQLFeatureNotSupportedException.class,
+ () -> convertToSpanner(Connection.TRANSACTION_READ_UNCOMMITTED));
+ assertThrows(
+ SQLFeatureNotSupportedException.class, () -> convertToSpanner(Connection.TRANSACTION_NONE));
+
+ assertThrows(IllegalArgumentException.class, () -> convertToSpanner(-1));
+ }
+
+ @Test
+ public void testConvertToJdbc() {
+ // There is no 'unspecified' isolation level in JDBC, so we convert this to the default
+ // SERIALIZABLE isolation level in Spanner.
+ assertEquals(
+ Connection.TRANSACTION_SERIALIZABLE,
+ convertToJdbc(IsolationLevel.ISOLATION_LEVEL_UNSPECIFIED));
+ assertEquals(Connection.TRANSACTION_SERIALIZABLE, convertToJdbc(IsolationLevel.SERIALIZABLE));
+ assertEquals(
+ Connection.TRANSACTION_REPEATABLE_READ, convertToJdbc(IsolationLevel.REPEATABLE_READ));
+
+ assertThrows(IllegalArgumentException.class, () -> convertToJdbc(IsolationLevel.UNRECOGNIZED));
+ }
+}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java
index e0ea49f6f..d4cfeb8d0 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcConnectionTest.java
@@ -366,34 +366,28 @@ private void testInvokeMethodOnClosedConnection(Method method, Object... args)
public void testTransactionIsolation() throws SQLException {
ConnectionOptions options = mockOptions();
try (JdbcConnection connection = createConnection(options)) {
- assertThat(connection.getTransactionIsolation())
- .isEqualTo(Connection.TRANSACTION_SERIALIZABLE);
- // assert that setting it to this value is ok.
+ assertEquals(Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation());
+ // assert that setting it to these values is ok.
connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+ assertEquals(Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation());
+ connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
+ assertEquals(Connection.TRANSACTION_REPEATABLE_READ, connection.getTransactionIsolation());
// assert that setting it to something else is not ok.
- int[] settings =
+ int[] invalidValues =
new int[] {
- Connection.TRANSACTION_READ_COMMITTED,
- Connection.TRANSACTION_READ_UNCOMMITTED,
- Connection.TRANSACTION_REPEATABLE_READ,
- -100
+ Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_READ_UNCOMMITTED, -100
};
- for (int setting : settings) {
- boolean exception = false;
- try {
- connection.setTransactionIsolation(setting);
- } catch (SQLException e) {
- if (setting == -100) {
- exception =
- (e instanceof JdbcSqlException
- && ((JdbcSqlException) e).getCode() == Code.INVALID_ARGUMENT);
- } else {
- exception =
- (e instanceof JdbcSqlException
- && ((JdbcSqlException) e).getCode() == Code.UNIMPLEMENTED);
- }
+ for (int invalidValue : invalidValues) {
+ SQLException exception =
+ assertThrows(
+ SQLException.class, () -> connection.setTransactionIsolation(invalidValue));
+ assertTrue(exception instanceof JdbcSqlException);
+ JdbcSqlException spannerException = (JdbcSqlException) exception;
+ if (invalidValue == -100) {
+ assertEquals(Code.INVALID_ARGUMENT, spannerException.getCode());
+ } else {
+ assertEquals(Code.UNIMPLEMENTED, spannerException.getCode());
}
- assertThat(exception).isTrue();
}
}
}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java
index 47ab2e549..c8970fd76 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataTest.java
@@ -265,12 +265,12 @@ public void testTrivialMethods() throws SQLException {
assertFalse(meta.usesLocalFiles());
assertFalse(meta.usesLocalFilePerTable());
assertTrue(meta.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE));
+ assertTrue(meta.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ));
for (int level :
new int[] {
Connection.TRANSACTION_NONE,
Connection.TRANSACTION_READ_COMMITTED,
Connection.TRANSACTION_READ_UNCOMMITTED,
- Connection.TRANSACTION_REPEATABLE_READ
}) {
assertFalse(meta.supportsTransactionIsolationLevel(level));
}
diff --git a/src/test/java/com/google/cloud/spanner/jdbc/TransactionMockServerTest.java b/src/test/java/com/google/cloud/spanner/jdbc/TransactionMockServerTest.java
index 954d12e80..91086055d 100644
--- a/src/test/java/com/google/cloud/spanner/jdbc/TransactionMockServerTest.java
+++ b/src/test/java/com/google/cloud/spanner/jdbc/TransactionMockServerTest.java
@@ -17,10 +17,14 @@
package com.google.cloud.spanner.jdbc;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
import com.google.cloud.spanner.connection.AbstractMockServerTest;
import com.google.cloud.spanner.connection.SpannerPool;
import com.google.spanner.v1.CommitRequest;
+import com.google.spanner.v1.ExecuteSqlRequest;
+import com.google.spanner.v1.TransactionOptions.IsolationLevel;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -45,9 +49,13 @@ public void clearRequests() {
}
private String createUrl() {
+ return createUrl("");
+ }
+
+ private String createUrl(String extraOptions) {
return String.format(
- "jdbc:cloudspanner://localhost:%d/projects/%s/instances/%s/databases/%s?usePlainText=true;autoCommit=false",
- getPort(), "proj", "inst", "db");
+ "jdbc:cloudspanner://localhost:%d/projects/%s/instances/%s/databases/%s?usePlainText=true;autoCommit=false%s",
+ getPort(), "proj", "inst", "db", extraOptions);
}
@Override
@@ -98,4 +106,62 @@ public void testRollingBackEmptyExplicitTransactionIsNoOp() throws SQLException
assertEquals(0, mockSpanner.countRequestsOfType(CommitRequest.class));
}
+
+ @Test
+ public void testUsesDefaultIsolationLevel() throws SQLException {
+ try (Connection connection = createJdbcConnection()) {
+ for (IsolationLevel isolationLevel :
+ new IsolationLevel[] {IsolationLevel.SERIALIZABLE, IsolationLevel.REPEATABLE_READ}) {
+ //noinspection MagicConstant
+ connection.setTransactionIsolation(IsolationLevelConverter.convertToJdbc(isolationLevel));
+ runTestTransaction(connection, isolationLevel);
+ }
+ }
+ }
+
+ @Test
+ public void testUsesManualIsolationLevel() throws SQLException {
+ try (Connection connection = createJdbcConnection()) {
+ connection.setAutoCommit(true);
+ for (IsolationLevel isolationLevel :
+ new IsolationLevel[] {IsolationLevel.SERIALIZABLE, IsolationLevel.REPEATABLE_READ}) {
+ connection
+ .createStatement()
+ .execute(
+ "begin transaction isolation level " + isolationLevel.toString().replace("_", " "));
+ runTestTransaction(connection, isolationLevel);
+ }
+ }
+ }
+
+ @Test
+ public void testUsesDefaultIsolationLevelInConnectionString() throws SQLException {
+ for (IsolationLevel isolationLevel :
+ new IsolationLevel[] {IsolationLevel.SERIALIZABLE, IsolationLevel.REPEATABLE_READ}) {
+ try (Connection connection =
+ DriverManager.getConnection(
+ createUrl(";default_isolation_level=" + isolationLevel.name()))) {
+ runTestTransaction(connection, isolationLevel);
+ }
+ }
+ }
+
+ void runTestTransaction(Connection connection, IsolationLevel expectedIsolationLevel)
+ throws SQLException {
+ String sql = "insert into foo (id) values (1)";
+ mockSpanner.putStatementResult(
+ StatementResult.update(com.google.cloud.spanner.Statement.of(sql), 1L));
+
+ assertEquals(1, connection.createStatement().executeUpdate(sql));
+ connection.commit();
+
+ assertEquals(1, mockSpanner.countRequestsOfType(ExecuteSqlRequest.class));
+ ExecuteSqlRequest request = mockSpanner.getRequestsOfType(ExecuteSqlRequest.class).get(0);
+ assertTrue(request.hasTransaction());
+ assertTrue(request.getTransaction().hasBegin());
+ assertTrue(request.getTransaction().getBegin().hasReadWrite());
+ assertEquals(expectedIsolationLevel, request.getTransaction().getBegin().getIsolationLevel());
+
+ mockSpanner.clearRequests();
+ }
}
From 6b7ddf4352d4db87eab6d9f3fd4945e5650e7798 Mon Sep 17 00:00:00 2001
From: Mend Renovate
Date: Tue, 8 Apr 2025 17:29:42 +0200
Subject: [PATCH 08/15] deps: update dependency
io.opentelemetry:opentelemetry-bom to v1.49.0 (#1982)
---
samples/spring-data-jdbc/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/spring-data-jdbc/pom.xml b/samples/spring-data-jdbc/pom.xml
index 380e4fad7..d7cf3b959 100644
--- a/samples/spring-data-jdbc/pom.xml
+++ b/samples/spring-data-jdbc/pom.xml
@@ -44,7 +44,7 @@
io.opentelemetryopentelemetry-bom
- 1.48.0
+ 1.49.0pomimport
From 80e5c0c571612dbcdbdb18b66a2c32481ae22916 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?=
Date: Mon, 14 Apr 2025 10:56:45 +0200
Subject: [PATCH 09/15] chore: set Hibernate user-agent automatically (#1975)
Use the call stack the first time that a JDBC connection is being created to
determine whether the connection should use the sp-jdbc or sp-hib user-agent
token.
---
.../google/cloud/spanner/jdbc/JdbcDriver.java | 47 ++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
index 7c9b46052..f7bdb3b09 100644
--- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
+++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
@@ -26,6 +26,7 @@
import com.google.cloud.spanner.connection.ConnectionPropertiesHelper;
import com.google.cloud.spanner.connection.ConnectionProperty;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Suppliers;
import com.google.rpc.Code;
import io.opentelemetry.api.OpenTelemetry;
import java.sql.Connection;
@@ -222,7 +223,9 @@ public Connection connect(String url, Properties info) throws SQLException {
Matcher matcherExternalHost = EXTERNAL_HOST_URL_PATTERN.matcher(url);
if (matcher.matches() || matcherExternalHost.matches()) {
// strip 'jdbc:' from the URL, add any extra properties and pass on to the generic
- // Connection API
+ // Connection API. Also set the user-agent if we detect that the connection
+ // comes from known framework like Hibernate, and there is no other user-agent set.
+ maybeAddUserAgent(info);
String connectionUri = appendPropertiesToUrl(url.substring(5), info);
ConnectionOptions options = buildConnectionOptions(connectionUri, info);
JdbcConnection connection = new JdbcConnection(url, options);
@@ -259,6 +262,48 @@ private ConnectionOptions buildConnectionOptions(String connectionUrl, Propertie
return builder.build();
}
+ static void maybeAddUserAgent(Properties properties) {
+ if (properties.containsKey("userAgent")) {
+ return;
+ }
+ if (isHibernate()) {
+ properties.setProperty("userAgent", "sp-hib");
+ }
+ }
+
+ static boolean isHibernate() {
+ // Cache the result as the check is relatively expensive, and we also don't want to create
+ // multiple different Spanner instances just to get the correct user-agent in every case.
+ return Suppliers.memoize(
+ () -> {
+ try {
+ // First check if the Spanner Hibernate dialect is on the classpath. If it is, then
+ // we assume that Hibernate will (eventually) be used.
+ Class.forName(
+ "com.google.cloud.spanner.hibernate.SpannerDialect",
+ /*initialize=*/ false,
+ JdbcDriver.class.getClassLoader());
+ return true;
+ } catch (Throwable ignore) {
+ }
+
+ // If we did not find the Spanner Hibernate dialect on the classpath, then do a
+ // check if the connection is still being created by Hibernate using the built-in
+ // Spanner dialect in Hibernate.
+ try {
+ StackTraceElement[] callStack = Thread.currentThread().getStackTrace();
+ for (StackTraceElement element : callStack) {
+ if (element.getClassName().contains(".hibernate.")) {
+ return true;
+ }
+ }
+ } catch (Throwable ignore) {
+ }
+ return false;
+ })
+ .get();
+ }
+
private String appendPropertiesToUrl(String url, Properties info) {
StringBuilder res = new StringBuilder(url);
for (Entry