From 6c378accb3cb0cc7df9bd7a4f38687a50c3ad47b Mon Sep 17 00:00:00 2001 From: t-horikawa Date: Thu, 29 Aug 2024 11:26:13 +0900 Subject: [PATCH] add a program to reproduce the issue 948 --- modules/cases/build.gradle | 13 ++++++ .../examples/resultsetClose/CreateTable.java | 27 +++++++++++++ .../examples/resultsetClose/Insert.java | 40 +++++++++++++++++++ .../examples/resultsetClose/Main.java | 37 +++++++++++++++++ .../examples/resultsetClose/Select.java | 30 ++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/CreateTable.java create mode 100644 modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Insert.java create mode 100644 modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Main.java create mode 100644 modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Select.java diff --git a/modules/cases/build.gradle b/modules/cases/build.gradle index 4241fd3..7fba405 100644 --- a/modules/cases/build.gradle +++ b/modules/cases/build.gradle @@ -67,3 +67,16 @@ tasks.register('run406', JavaExec) { systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true' systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true' } + + +tasks.register('run948', JavaExec) { + classpath = sourceSets.main.runtimeClasspath + mainClass = 'com.tsurugidb.tsubakuro.examples.resultsetClose.Main' + + systemProperty 'tsurugi.dbname', findProperty('tsurugi.dbname') ?: 'ipc:tsurugi' + + systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', findProperty('loglevel') ?: 'info' + systemProperty 'org.slf4j.simpleLogger.showThreadName', 'false' + systemProperty 'org.slf4j.simpleLogger.showShortLogName', 'true' + systemProperty 'org.slf4j.simpleLogger.levelInBrackets', 'true' +} diff --git a/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/CreateTable.java b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/CreateTable.java new file mode 100644 index 0000000..a75e4c6 --- /dev/null +++ b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/CreateTable.java @@ -0,0 +1,27 @@ +package com.tsurugidb.tsubakuro.examples.resultsetClose; + +import java.io.IOException; + +import com.tsurugidb.tsubakuro.exception.ServerException; +import com.tsurugidb.tsubakuro.common.Session; +import com.tsurugidb.tsubakuro.common.SessionBuilder; +import com.tsurugidb.tsubakuro.sql.SqlClient; +import com.tsurugidb.tsubakuro.sql.Transaction; +import com.tsurugidb.tsubakuro.sql.Placeholders; +import com.tsurugidb.tsubakuro.sql.Parameters; + +public final class CreateTable { + public static void doCreateTable(String url) throws IOException, ServerException, InterruptedException { + try (Session session = SessionBuilder.connect(url).create(); + SqlClient sqlClient = SqlClient.attach(session); + Transaction transaction = sqlClient.createTransaction().get()) { + + transaction.executeStatement("DROP TABLE IF EXISTS foo"); + transaction.executeStatement("CREATE TABLE foo (bar1 INT, bar2 DOUBLE, bar3 VARCHAR(20), PRIMARY KEY(bar1))").get(); + transaction.commit().get(); + } + } + + private CreateTable() { + } +} diff --git a/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Insert.java b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Insert.java new file mode 100644 index 0000000..59c682c --- /dev/null +++ b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Insert.java @@ -0,0 +1,40 @@ +package com.tsurugidb.tsubakuro.examples.resultsetClose; + +import java.io.IOException; + +import com.tsurugidb.tsubakuro.exception.ServerException; +import com.tsurugidb.tsubakuro.common.Session; +import com.tsurugidb.tsubakuro.common.SessionBuilder; +import com.tsurugidb.tsubakuro.sql.SqlClient; +import com.tsurugidb.tsubakuro.sql.Transaction; +import com.tsurugidb.tsubakuro.sql.PreparedStatement; +import com.tsurugidb.tsubakuro.sql.Placeholders; +import com.tsurugidb.tsubakuro.sql.Parameters; + +public class Insert { + public static void doInsert(String url) throws IOException, ServerException, InterruptedException { + try (Session session = SessionBuilder.connect(url).create(); + SqlClient sqlClient = SqlClient.attach(session); + PreparedStatement preparedStatement = sqlClient.prepare("INSERT INTO foo (bar1, bar2, bar3) VALUES (:int_for_bar1, :double_for_bar2, :char_for_bar3)", + Placeholders.of("int_for_bar1", long.class), + Placeholders.of("double_for_bar2", double.class), + Placeholders.of("char_for_bar3", String.class)).get(); + Transaction transaction = sqlClient.createTransaction().get();) { + + // insert first data into foo table + transaction.executeStatement(preparedStatement, + Parameters.of("int_for_bar1", (long) 1234), + Parameters.of("double_for_bar2", (double) 56.789), + Parameters.of("char_for_bar3", "text for first data")).get(); + // insert second data into foo table + transaction.executeStatement(preparedStatement, + Parameters.of("int_for_bar1", (long) 5678), + Parameters.of("double_for_bar2", (double) 123.45), + Parameters.of("char_for_bar3", "text for second data")).get(); + transaction.commit().get(); + } + } + + private Insert() { + } +} diff --git a/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Main.java b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Main.java new file mode 100644 index 0000000..27e8b64 --- /dev/null +++ b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Main.java @@ -0,0 +1,37 @@ +package com.tsurugidb.tsubakuro.examples.resultsetClose; + +import java.io.IOException; +import java.util.ArrayList; + +import com.tsurugidb.tsubakuro.exception.ServerException; + +public final class Main { + private static String url = System.getProperty("tsurugi.dbname"); + + public static void main(String[] args) { + try { + CreateTable.doCreateTable(url); + } catch (IOException | ServerException | InterruptedException e) { + System.out.println(e); + e.printStackTrace(); + return; + } + try { + Insert.doInsert(url); + } catch (IOException | ServerException | InterruptedException e) { + System.out.println(e); + e.printStackTrace(); + return; + } + try { + Select.doSelect(url); + } catch (IOException | ServerException | InterruptedException e) { + System.out.println(e); + e.printStackTrace(); + return; + } + } + + private Main(String[] args) { + } +} diff --git a/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Select.java b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Select.java new file mode 100644 index 0000000..cda2dcb --- /dev/null +++ b/modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Select.java @@ -0,0 +1,30 @@ +package com.tsurugidb.tsubakuro.examples.resultsetClose; + +import java.io.IOException; +import java.util.ArrayList; + +import com.tsurugidb.tsubakuro.exception.ServerException; +import com.tsurugidb.tsubakuro.common.Session; +import com.tsurugidb.tsubakuro.common.SessionBuilder; +import com.tsurugidb.tsubakuro.sql.SqlClient; +import com.tsurugidb.tsubakuro.sql.Transaction; +import com.tsurugidb.tsubakuro.sql.ResultSet; + +public final class Select { + private static ArrayList resultSets = new ArrayList<>(); + public static void doSelect(String url) throws IOException, ServerException, InterruptedException { + System.out.println("select entered"); + try ( + Session session = SessionBuilder.connect(url).create(); + SqlClient sqlClient = SqlClient.attach(session); + Transaction transaction = sqlClient.createTransaction().get();) { + + var future = transaction.executeQuery("SELECT * FROM foo"); + future.close(); + } + System.out.println("select completed"); + } + + private Select() { + } +}