From e04be8b252c66d87793ba14e6c338f1a01e5e175 Mon Sep 17 00:00:00 2001 From: Nikolay Date: Sun, 22 Dec 2024 10:32:09 +0300 Subject: [PATCH] IGNITE-24074 Fix createStatement() throws when tx aware queries enabled (#11765) --- .../jdbc/JdbcThinTransactionalSelfTest.java | 22 +++++++++++++++++++ .../jdbc/thin/JdbcThinConnection.java | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java index 22fb84ba4fedf..d1e17397d6dbc 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java @@ -23,6 +23,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.Arrays; import java.util.List; import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; @@ -292,4 +293,25 @@ public void testCloseConnectionWithoutCommit() throws Exception { assertTrue(rs0.isClosed()); assertTrue(rs1.isClosed()); } + + /** */ + @Test + public void testCreateStatementOnDefaults() throws Exception { + try (Connection conn = DriverManager.getConnection(URL)) { + conn.setAutoCommit(false); + + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery("SELECT 1")) { + assertEquals(1, F.size(grid().context().cache().context().tm().activeTransactions())); + + try (Statement stmt2 = conn.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY)) { + try (ResultSet rs2 = stmt.executeQuery("SELECT 1")) { + assertEquals(1, F.size(grid().context().cache().context().tm().activeTransactions())); + } + } + } + } + + } + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java index bdb9cecfad7eb..6888816b095e8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java @@ -481,12 +481,12 @@ void addBatch(String sql, List args) throws SQLException { /** {@inheritDoc} */ @Override public Statement createStatement() throws SQLException { - return createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT); + return createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, holdability); } /** {@inheritDoc} */ @Override public Statement createStatement(int resSetType, int resSetConcurrency) throws SQLException { - return createStatement(resSetType, resSetConcurrency, HOLD_CURSORS_OVER_COMMIT); + return createStatement(resSetType, resSetConcurrency, holdability); } /** {@inheritDoc} */