Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: googleapis/java-spanner-jdbc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.17.1
Choose a base ref
...
head repository: googleapis/java-spanner-jdbc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.18.0
Choose a head ref
  • 10 commits
  • 15 files changed
  • 3 contributors

Commits on May 1, 2024

  1. chore(main): release 2.17.2-SNAPSHOT (#1592)

    Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
    release-please[bot] authored May 1, 2024
    Copy the full SHA
    c5abf2c View commit details
  2. build(deps): update dependency org.apache.maven.plugins:maven-shade-p…

    …lugin to v3.5.3 (#1591)
    renovate-bot authored May 1, 2024
    Copy the full SHA
    c27fb58 View commit details
  3. chore(deps): update dependency com.google.cloud:google-cloud-spanner-…

    …jdbc to v2.17.1 (#1593)
    
    [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)
    
    This PR contains the following updates:
    
    | Package | Change | Age | Adoption | Passing | Confidence |
    |---|---|---|---|---|---|
    | [com.google.cloud:google-cloud-spanner-jdbc](https://togithub.com/googleapis/java-spanner-jdbc) | `2.17.0` -> `2.17.1` | [![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.cloud:google-cloud-spanner-jdbc/2.17.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.cloud:google-cloud-spanner-jdbc/2.17.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.cloud:google-cloud-spanner-jdbc/2.17.0/2.17.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.cloud:google-cloud-spanner-jdbc/2.17.0/2.17.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
    
    ---
    
    ### Release Notes
    
    <details>
    <summary>googleapis/java-spanner-jdbc (com.google.cloud:google-cloud-spanner-jdbc)</summary>
    
    ### [`v2.17.1`](https://togithub.com/googleapis/java-spanner-jdbc/blob/HEAD/CHANGELOG.md#2171-2024-04-30)
    
    [Compare Source](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.17.0...v2.17.1)
    
    ##### Dependencies
    
    -   Update dependency com.google.cloud:google-cloud-spanner-bom to v6.65.1 ([#&#8203;1588](https://togithub.com/googleapis/java-spanner-jdbc/issues/1588)) ([1b1218a](https://togithub.com/googleapis/java-spanner-jdbc/commit/1b1218adaa25ecec3def66b7031c7f0e5e8c23b0))
    
    </details>
    
    ---
    
    ### Configuration
    
    📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
    
    🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
    
    ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
    
    🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
    
    ---
    
     - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box
    
    ---
    
    This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/java-spanner-jdbc).
    <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMzEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjMzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
    renovate-bot authored May 1, 2024
    Copy the full SHA
    a303867 View commit details

Commits on May 3, 2024

  1. deps: update dependency com.google.cloud:sdk-platform-java-config to …

    …v3.30.0 (#1597)
    renovate-bot authored May 3, 2024
    Copy the full SHA
    40a7212 View commit details
  2. deps: update dependency org.mybatis.dynamic-sql:mybatis-dynamic-sql t…

    …o v1.5.1 (#1596)
    renovate-bot authored May 3, 2024
    Copy the full SHA
    f54beb2 View commit details
  3. fix: ClassCastException in Spring Data JDBC sample (#1595)

    olavloite authored May 3, 2024
    Copy the full SHA
    e96a86a View commit details

Commits on May 4, 2024

  1. deps: update dependency com.google.cloud:google-cloud-spanner-bom to …

    …v6.66.0 (#1599)
    
    [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)
    
    This PR contains the following updates:
    
    | Package | Change | Age | Adoption | Passing | Confidence |
    |---|---|---|---|---|---|
    | [com.google.cloud:google-cloud-spanner-bom](https://togithub.com/googleapis/java-spanner) | `6.65.1` -> `6.66.0` | [![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.cloud:google-cloud-spanner-bom/6.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.cloud:google-cloud-spanner-bom/6.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.cloud:google-cloud-spanner-bom/6.65.1/6.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.cloud:google-cloud-spanner-bom/6.65.1/6.66.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
    
    ---
    
    ### Release Notes
    
    <details>
    <summary>googleapis/java-spanner (com.google.cloud:google-cloud-spanner-bom)</summary>
    
    ### [`v6.66.0`](https://togithub.com/googleapis/java-spanner/blob/HEAD/CHANGELOG.md#6660-2024-05-03)
    
    [Compare Source](https://togithub.com/googleapis/java-spanner/compare/v6.65.1...v6.66.0)
    
    ##### Features
    
    -   Allow DDL with autocommit=false ([#&#8203;3057](https://togithub.com/googleapis/java-spanner/issues/3057)) ([22833ac](https://togithub.com/googleapis/java-spanner/commit/22833acf9f073271ce0ee10f2b496f3a1d39566a))
    -   Include stack trace of checked out sessions in exception ([#&#8203;3092](https://togithub.com/googleapis/java-spanner/issues/3092)) ([ba6a0f6](https://togithub.com/googleapis/java-spanner/commit/ba6a0f644b6caa4d2f3aa130c6061341b70957dd))
    
    ##### Bug Fixes
    
    -   Multiplexed session metrics were not included in refactor move ([#&#8203;3088](https://togithub.com/googleapis/java-spanner/issues/3088)) ([f3589c4](https://togithub.com/googleapis/java-spanner/commit/f3589c430b0e84933a91008bb306c26089788357))
    
    ##### Dependencies
    
    -   Update dependency com.google.cloud:sdk-platform-java-config to v3.30.0 ([#&#8203;3082](https://togithub.com/googleapis/java-spanner/issues/3082)) ([ddfc98e](https://togithub.com/googleapis/java-spanner/commit/ddfc98e240fb47ef51075ba4461bf9a98aa25ce0))
    
    </details>
    
    ---
    
    ### Configuration
    
    📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
    
    🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.
    
    ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
    
    🔕 **Ignore**: Close this PR and you won't be reminded about this update again.
    
    ---
    
     - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box
    
    ---
    
    This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/java-spanner-jdbc).
    <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMzEuMCIsInVwZGF0ZWRJblZlciI6IjM3LjMzMS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
    renovate-bot authored May 4, 2024
    Copy the full SHA
    84ea11a View commit details
  2. feat: allow DDL with autocommit=false (#1600)

    Adds support for running DDL statements when a connection is in autocommit=false mode. By default, DDL statements are only allowed when no transaction is active. That is; no query or DML statement has been executed which activated a read/write transaction.
    
    A new flag is added that can be used to revert the behavior back to the original behavior where DDL is always refused when autocommit=false. The same flag can also be used to make the API behave the same as MySQL and Oracle, where any active transaction is automatically committed whenever a DDL statement is encountered.
    
    Concretely this means that the following is now allowed:
    
    ```
    set autocommit=false;
    create table Singers (SingerId INT64, Name STRING(MAX)) PRIMARY KEY (SingerId);
    ```
    
    The following is by default NOT allowed, unless
    ddlInTransactionMode=AUTO_COMMIT_TRANSACTION
    
    ```
    set autocommit=false;
    select * from singers; -- This starts a transaction
    create table Albums (AlbumId INT64) PRIMARY KEY (AlbumId); -- This is not allowed
    ```
    olavloite authored May 4, 2024
    Copy the full SHA
    a61c25d View commit details
  3. feat: support concurrent transactions on the emulator (#1601)

    Adds support for overlapping transactions on the emulator in the Connection API, even when these are executed on one thread. This is normally not supported, as it requires multiple transactions to run concurrently on the emulator.
    
    This change works around that by keeping track of what the active transaction on the emulator is, and then abort that transaction when another transaction needs to make progress. The transaction that was aborted will be retried up to the point where it was when it again wants to make progress.
    
    This step-by-step progress is implemented by automatically setting a savepoint in the transaction after each successful step. The transaction is then rolled back to that savepoint when another transaction needs to make progress.
    
    The feature is only enabled if the autoConfigEmulator flag is enabled.
    olavloite authored May 4, 2024
    Copy the full SHA
    7123991 View commit details
  4. chore(main): release 2.18.0 (#1598)

    🤖 I have created a release *beep* *boop*
    ---
    
    
    ## [2.18.0](https://togithub.com/googleapis/java-spanner-jdbc/compare/v2.17.1...v2.18.0) (2024-05-04)
    
    
    ### Features
    
    * Allow DDL with autocommit=false ([#1600](https://togithub.com/googleapis/java-spanner-jdbc/issues/1600)) ([a61c25d](https://togithub.com/googleapis/java-spanner-jdbc/commit/a61c25d8f90460ec507b383dbaee0ca686104ba8))
    * Support concurrent transactions on the emulator ([#1601](https://togithub.com/googleapis/java-spanner-jdbc/issues/1601)) ([7123991](https://togithub.com/googleapis/java-spanner-jdbc/commit/71239912a8078569dcd985314810131e593c0ed7))
    
    
    ### Bug Fixes
    
    * ClassCastException in Spring Data JDBC sample ([#1595](https://togithub.com/googleapis/java-spanner-jdbc/issues/1595)) ([e96a86a](https://togithub.com/googleapis/java-spanner-jdbc/commit/e96a86a4b82ac4b47bd1ce25e810f01299597339))
    
    
    ### Dependencies
    
    * Update dependency com.google.cloud:google-cloud-spanner-bom to v6.66.0 ([#1599](https://togithub.com/googleapis/java-spanner-jdbc/issues/1599)) ([84ea11a](https://togithub.com/googleapis/java-spanner-jdbc/commit/84ea11ac27635dbe6fb101134767d14488dde8c2))
    * Update dependency com.google.cloud:sdk-platform-java-config to v3.30.0 ([#1597](https://togithub.com/googleapis/java-spanner-jdbc/issues/1597)) ([40a7212](https://togithub.com/googleapis/java-spanner-jdbc/commit/40a721237c79882e55d86d48402c64cc09782522))
    * Update dependency org.mybatis.dynamic-sql:mybatis-dynamic-sql to v1.5.1 ([#1596](https://togithub.com/googleapis/java-spanner-jdbc/issues/1596)) ([f54beb2](https://togithub.com/googleapis/java-spanner-jdbc/commit/f54beb20d6bbe3f4974385c4758ba77d31d25ce3))
    
    ---
    This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
    release-please[bot] authored May 4, 2024
    Copy the full SHA
    ba0aa41 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/unmanaged_dependency_check.yaml
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@ jobs:
shell: bash
run: .kokoro/build.sh
- name: Unmanaged dependency check
uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.29.0
uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.30.0
with:
bom-path: pom.xml
2 changes: 1 addition & 1 deletion .kokoro/presubmit/graalvm-native-17.cfg
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:3.29.0"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_b:3.30.0"
}

env_vars: {
2 changes: 1 addition & 1 deletion .kokoro/presubmit/graalvm-native.cfg
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.29.0"
value: "gcr.io/cloud-devrel-public-resources/graalvm_sdk_platform_a:3.30.0"
}

env_vars: {
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## [2.18.0](https://github.com/googleapis/java-spanner-jdbc/compare/v2.17.1...v2.18.0) (2024-05-04)


### Features

* Allow DDL with autocommit=false ([#1600](https://github.com/googleapis/java-spanner-jdbc/issues/1600)) ([a61c25d](https://github.com/googleapis/java-spanner-jdbc/commit/a61c25d8f90460ec507b383dbaee0ca686104ba8))
* Support concurrent transactions on the emulator ([#1601](https://github.com/googleapis/java-spanner-jdbc/issues/1601)) ([7123991](https://github.com/googleapis/java-spanner-jdbc/commit/71239912a8078569dcd985314810131e593c0ed7))


### Bug Fixes

* ClassCastException in Spring Data JDBC sample ([#1595](https://github.com/googleapis/java-spanner-jdbc/issues/1595)) ([e96a86a](https://github.com/googleapis/java-spanner-jdbc/commit/e96a86a4b82ac4b47bd1ce25e810f01299597339))


### Dependencies

* Update dependency com.google.cloud:google-cloud-spanner-bom to v6.66.0 ([#1599](https://github.com/googleapis/java-spanner-jdbc/issues/1599)) ([84ea11a](https://github.com/googleapis/java-spanner-jdbc/commit/84ea11ac27635dbe6fb101134767d14488dde8c2))
* Update dependency com.google.cloud:sdk-platform-java-config to v3.30.0 ([#1597](https://github.com/googleapis/java-spanner-jdbc/issues/1597)) ([40a7212](https://github.com/googleapis/java-spanner-jdbc/commit/40a721237c79882e55d86d48402c64cc09782522))
* Update dependency org.mybatis.dynamic-sql:mybatis-dynamic-sql to v1.5.1 ([#1596](https://github.com/googleapis/java-spanner-jdbc/issues/1596)) ([f54beb2](https://github.com/googleapis/java-spanner-jdbc/commit/f54beb20d6bbe3f4974385c4758ba77d31d25ce3))

## [2.17.1](https://github.com/googleapis/java-spanner-jdbc/compare/v2.17.0...v2.17.1) (2024-04-30)


8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>google-cloud-spanner-jdbc</artifactId>
<version>2.17.1</version><!-- {x-version-update:google-cloud-spanner-jdbc:current} -->
<version>2.18.0</version><!-- {x-version-update:google-cloud-spanner-jdbc:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner JDBC</name>
<url>https://github.com/googleapis/java-spanner-jdbc</url>
@@ -14,7 +14,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>sdk-platform-java-config</artifactId>
<version>3.29.0</version>
<version>3.30.0</version>
</parent>
<developers>
<developer>
@@ -62,7 +62,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-bom</artifactId>
<version>6.65.1</version>
<version>6.66.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -273,7 +273,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<version>3.5.3</version>
<executions>
<execution>
<goals>
2 changes: 1 addition & 1 deletion samples/install-without-bom/pom.xml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-jdbc</artifactId>
<version>2.17.0</version>
<version>2.17.1</version>
</dependency>
<!-- [END spanner-jdbc_install_without_bom] -->

2 changes: 1 addition & 1 deletion samples/snapshot/pom.xml
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-jdbc</artifactId>
<version>2.17.1</version>
<version>2.18.0</version>
</dependency>
<!-- {x-version-update-end} -->

2 changes: 1 addition & 1 deletion samples/snippets/pom.xml
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>sdk-platform-java-config</artifactId>
<version>3.29.0</version>
<version>3.30.0</version>
<relativePath/>
</parent>

Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public static boolean isCloudSpannerPG(JdbcOperations operations) {
"The selected Cloud Spanner database does not use the PostgreSQL dialect");
} catch (DataAccessException exception) {
if (exception.getCause() instanceof JdbcSqlException) {
JdbcSqlException jdbcSqlException = (JdbcSqlException) exception;
JdbcSqlException jdbcSqlException = (JdbcSqlException) exception.getCause();
if (jdbcSqlException.getCode() == Code.PERMISSION_DENIED
|| jdbcSqlException.getCode() == Code.NOT_FOUND) {
throw new RuntimeException(
2 changes: 1 addition & 1 deletion samples/spring-data-mybatis/pom.xml
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
<dependency>
<groupId>org.mybatis.dynamic-sql</groupId>
<artifactId>mybatis-dynamic-sql</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
</dependency>

<!-- Add both the Cloud Spanner and the PostgreSQL JDBC driver. -->
7 changes: 7 additions & 0 deletions src/main/java/com/google/cloud/spanner/jdbc/JdbcDriver.java
Original file line number Diff line number Diff line change
@@ -84,6 +84,13 @@
* instance and database in the connection string will automatically be created if these do
* not yet exist on the emulator. This means that you do not need to execute any `gcloud`
* commands on the emulator to create the instance and database before you can connect to it.
* Setting this property to true also enables running concurrent transactions on the emulator.
* The emulator aborts any concurrent transaction on the emulator, and the JDBC driver works
* around this by automatically setting a savepoint after each statement that is executed.
* When the transaction has been aborted by the emulator and the JDBC connection wants to
* continue with that transaction, the transaction is replayed up until the savepoint that had
* automatically been set after the last statement that was executed before the transaction
* was aborted by the emulator.
* <li>endpoint (string): Set this property to specify a custom endpoint that the JDBC driver
* should connect to. You can use this property in combination with the autoConfigEmulator
* property to instruct the JDBC driver to connect to an emulator instance that uses a
101 changes: 101 additions & 0 deletions src/test/java/com/google/cloud/spanner/jdbc/DdlMockServerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2024 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 org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult;
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.connection.AbstractMockServerTest;
import com.google.longrunning.Operation;
import com.google.protobuf.Any;
import com.google.protobuf.Empty;
import com.google.rpc.Code;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class DdlMockServerTest extends AbstractMockServerTest {

private String createUrl(boolean autoCommit) {
return String.format(
"jdbc:cloudspanner://localhost:%d/projects/%s/instances/%s/databases/%s?usePlainText=true;autoCommit=%s",
getPort(), "proj", "inst", "db", autoCommit);
}

private Connection createConnection(boolean autoCommit) throws SQLException {
return DriverManager.getConnection(createUrl(autoCommit));
}

@Test
public void testDdlInAutoCommitIsTrue_succeeds() throws SQLException {
mockDatabaseAdmin.addResponse(
Operation.newBuilder()
.setDone(true)
.setResponse(Any.pack(Empty.getDefaultInstance()))
.setMetadata(Any.pack(UpdateDatabaseDdlMetadata.getDefaultInstance()))
.build());

try (Connection connection = createConnection(/* autoCommit = */ true)) {
assertFalse(
connection.createStatement().execute("create table foo (id int64) primary key (id)"));
}
}

@Test
public void testDdlInAutoCommitIsFalse_succeedsWithNoActiveTransaction() throws SQLException {
mockDatabaseAdmin.addResponse(
Operation.newBuilder()
.setDone(true)
.setResponse(Any.pack(Empty.getDefaultInstance()))
.setMetadata(Any.pack(UpdateDatabaseDdlMetadata.getDefaultInstance()))
.build());

try (Connection connection = createConnection(/* autoCommit = */ false)) {
assertFalse(
connection.createStatement().execute("create table foo (id int64) primary key (id)"));
}
}

@Test
public void testDdlInAutoCommitIsFalse_failsWithActiveTransaction() throws SQLException {
mockSpanner.putStatementResult(
StatementResult.update(Statement.of("update foo set bar=1 where true"), 1L));

try (Connection connection = createConnection(/* autoCommit = */ false)) {
assertFalse(connection.createStatement().execute("update foo set bar=1 where true"));
SQLException exception =
assertThrows(
SQLException.class,
() ->
connection
.createStatement()
.execute("create table foo (id int64) primary key (id)"));
assertTrue(exception instanceof JdbcSqlException);
JdbcSqlException jdbcSqlException = (JdbcSqlException) exception;
assertEquals(Code.FAILED_PRECONDITION, jdbcSqlException.getCode());
}
}
}
Loading