From 3f5078c41c6d5b6dc6f88499057b78736dd18ec9 Mon Sep 17 00:00:00 2001 From: Olav Loite Date: Fri, 13 Nov 2020 18:21:31 +0100 Subject: [PATCH 1/2] feat: add support for tagging to JDBC connection --- pom.xml | 7 ++++ .../jdbc/CloudSpannerJdbcConnection.java | 33 +++++++++++++++++++ .../cloud/spanner/jdbc/JdbcConnection.java | 32 ++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/pom.xml b/pom.xml index 26a86015..e78b44d6 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,7 @@ com.google.cloud google-cloud-spanner + 3.0.1-SNAPSHOT com.google.protobuf @@ -144,32 +145,38 @@ com.google.api.grpc proto-google-cloud-spanner-v1 + 3.0.1-SNAPSHOT com.google.api.grpc grpc-google-cloud-spanner-v1 + 3.0.1-SNAPSHOT com.google.cloud google-cloud-spanner + 3.0.1-SNAPSHOT test-jar test com.google.api.grpc grpc-google-cloud-spanner-v1 + 3.0.1-SNAPSHOT test com.google.api.grpc grpc-google-cloud-spanner-admin-instance-v1 + 3.0.1-SNAPSHOT test com.google.api.grpc grpc-google-cloud-spanner-admin-database-v1 + 3.0.1-SNAPSHOT test diff --git a/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java index dc52ca35..b669e091 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java @@ -34,6 +34,39 @@ */ public interface CloudSpannerJdbcConnection extends Connection { + /** + * Sets the transaction tag to use for the current transaction. This method may only be called + * when in a transaction, and before the transaction is actually started, i.e. before any + * statements have been executed in the transaction. + * + *

The tag will be set as the transaction tag of all statements during the transaction, and as + * the transaction tag of the commit. + * + *

The transaction tag will automatically be cleared after the transaction has ended. + * + * @param tag The tag to use. + */ + void setTransactionTag(String tag) throws SQLException; + + /** @return The transaction tag of the current transaction. */ + String getTransactionTag() throws SQLException; + + /** + * Sets the statement tag to use for the next statement that will be executed. The tag is + * automatically cleared after the statement is executed. Statement tags can be used both with + * autocommit=true and autocommit=false, and can be used for partitioned DML. + * + * @param tag The statement tag to use with the next statement that will be executed on this + * connection. + */ + void setStatementTag(String tag) throws SQLException; + + /** + * @return The statement tag that will be used with the next statement that is executed on this + * connection. + */ + String getStatementTag() throws SQLException; + /** * @return the commit {@link Timestamp} of the last read/write transaction. If the last * transaction was not a read/write transaction, or a read/write transaction that did not diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java index 4e231809..669d268b 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java @@ -74,6 +74,38 @@ public String nativeSQL(String sql) throws SQLException { .sqlWithNamedParameters; } + @Override + public String getStatementTag() throws SQLException { + checkClosed(); + return getSpannerConnection().getStatementTag(); + } + + @Override + public void setStatementTag(String tag) throws SQLException { + checkClosed(); + try { + getSpannerConnection().setStatementTag(tag); + } catch (SpannerException e) { + throw JdbcSqlExceptionFactory.of(e); + } + } + + @Override + public String getTransactionTag() throws SQLException { + checkClosed(); + return getSpannerConnection().getTransactionTag(); + } + + @Override + public void setTransactionTag(String tag) throws SQLException { + checkClosed(); + try { + getSpannerConnection().setTransactionTag(tag); + } catch (SpannerException e) { + throw JdbcSqlExceptionFactory.of(e); + } + } + @Override public void setAutoCommit(boolean autoCommit) throws SQLException { checkClosed(); From 7ddf8636fc0e638879b74134f9ecd9b2d2463e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Wed, 14 Jul 2021 10:13:20 +0200 Subject: [PATCH 2/2] fix: add ignored differences + default implementations --- clirr-ignored-differences.xml | 22 +++++++++++++++++++ .../jdbc/CloudSpannerJdbcConnection.java | 18 ++++++++++----- .../cloud/spanner/jdbc/JdbcConnection.java | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/clirr-ignored-differences.xml b/clirr-ignored-differences.xml index ac9c147d..0962d5e1 100644 --- a/clirr-ignored-differences.xml +++ b/clirr-ignored-differences.xml @@ -111,4 +111,26 @@ com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection void setReturnCommitStats(boolean) + + + + 7012 + com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection + java.lang.String getTransactionTag() + + + 7012 + com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection + void setTransactionTag(java.lang.String) + + + 7012 + com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection + java.lang.String getStatementTag() + + + 7012 + com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection + void setStatementTag(java.lang.String) + diff --git a/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java index b479b979..50ae71c5 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcConnection.java @@ -51,10 +51,14 @@ public interface CloudSpannerJdbcConnection extends Connection { * * @param tag The tag to use. */ - void setTransactionTag(String tag) throws SQLException; + default void setTransactionTag(String tag) throws SQLException { + throw new UnsupportedOperationException(); + }; /** @return The transaction tag of the current transaction. */ - String getTransactionTag() throws SQLException; + default String getTransactionTag() throws SQLException { + throw new UnsupportedOperationException(); + }; /** * Sets the statement tag to use for the next statement that will be executed. The tag is @@ -64,14 +68,18 @@ public interface CloudSpannerJdbcConnection extends Connection { * @param tag The statement tag to use with the next statement that will be executed on this * connection. */ - void setStatementTag(String tag) throws SQLException; + default void setStatementTag(String tag) throws SQLException { + throw new UnsupportedOperationException(); + }; /** * @return The statement tag that will be used with the next statement that is executed on this * connection. */ - String getStatementTag() throws SQLException; - + default String getStatementTag() throws SQLException { + throw new UnsupportedOperationException(); + }; + /** * Sets the transaction mode to use for current transaction. This method may only be called when * in a transaction, and before the transaction is actually started, i.e. before any statements diff --git a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java index cd2e3b03..53c1dc09 100644 --- a/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java +++ b/src/main/java/com/google/cloud/spanner/jdbc/JdbcConnection.java @@ -109,7 +109,7 @@ public void setTransactionTag(String tag) throws SQLException { throw JdbcSqlExceptionFactory.of(e); } } - + @Override public void setTransactionMode(TransactionMode mode) throws SQLException { checkClosed();