Skip to content

Commit e04be8b

Browse files
authored
IGNITE-24074 Fix createStatement() throws when tx aware queries enabled (#11765)
1 parent 98f49d4 commit e04be8b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/jdbc/JdbcThinTransactionalSelfTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.sql.PreparedStatement;
2424
import java.sql.ResultSet;
2525
import java.sql.SQLException;
26+
import java.sql.Statement;
2627
import java.util.Arrays;
2728
import java.util.List;
2829
import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
@@ -292,4 +293,25 @@ public void testCloseConnectionWithoutCommit() throws Exception {
292293
assertTrue(rs0.isClosed());
293294
assertTrue(rs1.isClosed());
294295
}
296+
297+
/** */
298+
@Test
299+
public void testCreateStatementOnDefaults() throws Exception {
300+
try (Connection conn = DriverManager.getConnection(URL)) {
301+
conn.setAutoCommit(false);
302+
303+
try (Statement stmt = conn.createStatement()) {
304+
try (ResultSet rs = stmt.executeQuery("SELECT 1")) {
305+
assertEquals(1, F.size(grid().context().cache().context().tm().activeTransactions()));
306+
307+
try (Statement stmt2 = conn.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY)) {
308+
try (ResultSet rs2 = stmt.executeQuery("SELECT 1")) {
309+
assertEquals(1, F.size(grid().context().cache().context().tm().activeTransactions()));
310+
}
311+
}
312+
}
313+
}
314+
315+
}
316+
}
295317
}

modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,12 @@ void addBatch(String sql, List<Object> args) throws SQLException {
481481

482482
/** {@inheritDoc} */
483483
@Override public Statement createStatement() throws SQLException {
484-
return createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT);
484+
return createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, holdability);
485485
}
486486

487487
/** {@inheritDoc} */
488488
@Override public Statement createStatement(int resSetType, int resSetConcurrency) throws SQLException {
489-
return createStatement(resSetType, resSetConcurrency, HOLD_CURSORS_OVER_COMMIT);
489+
return createStatement(resSetType, resSetConcurrency, holdability);
490490
}
491491

492492
/** {@inheritDoc} */

0 commit comments

Comments
 (0)