From 379bd3956cdd9afb1f159303f621c3d30aef0460 Mon Sep 17 00:00:00 2001 From: t-horikawa Date: Fri, 6 Sep 2024 17:33:35 +0900 Subject: [PATCH] revise resultsetClose to ensure SCD-00403 is generated --- .../examples/resultsetClose/Insert.java | 41 ++++++++++--------- .../examples/resultsetClose/Main.java | 11 ++++- 2 files changed, 31 insertions(+), 21 deletions(-) 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 index d4895c4..44b0e70 100644 --- 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 @@ -1,6 +1,7 @@ package com.tsurugidb.tsubakuro.examples.resultsetClose; import java.io.IOException; +import java.util.Random; import com.tsurugidb.tsubakuro.exception.ServerException; import com.tsurugidb.tsubakuro.common.Session; @@ -13,6 +14,9 @@ public class Insert { public static void doInsert(String url, boolean testResponse) throws IOException, ServerException, InterruptedException { + Random rand = new Random(); + int num = rand.nextInt(10) + 100; + 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)", @@ -21,30 +25,29 @@ public static void doInsert(String url, boolean testResponse) throws IOException Placeholders.of("char_for_bar3", String.class)).get(); Transaction transaction = sqlClient.createTransaction().get();) { - // insert first data into foo table - var f1 = 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")); - if (testResponse) { - f1.close(); // test of FutureResponse close without performing get() - } else { - f1.get(); // normal operation; - } - // insert second data into foo table - var f2 = 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")); - if (testResponse) { - f2.close(); // test of FutureResponse close without performing get() - } else { - f2.get(); // normal operation; + oneInsert(transaction, preparedStatement, testResponse, 1234, 56.789, "text for first data"); + oneInsert(transaction, preparedStatement, testResponse, 5678, 123.45, "text for second data"); + for (long i = 10000; i < 100000; i++) { + oneInsert(transaction, preparedStatement, testResponse, i, (double) rand.nextInt(10000) / (double) 1000., "text for other data"); } + transaction.commit().get(); } } + private static void oneInsert(Transaction transaction, PreparedStatement preparedStatement, boolean testResponse, long lv, double dv, String sv) throws IOException, ServerException, InterruptedException { + // insert first data into foo table + var f = transaction.executeStatement(preparedStatement, + Parameters.of("int_for_bar1", lv), + Parameters.of("double_for_bar2", dv), + Parameters.of("char_for_bar3", sv)); + if (testResponse) { + f.close(); // test of FutureResponse close without performing get() + } else { + f.get(); // normal operation; + } + } + 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 index 2028276..9c07cbd 100644 --- 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 @@ -26,8 +26,15 @@ public static void main(String[] args) { CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; - if (cmd.hasOption("i")) { - testResponse = true; + try { + cmd = parser.parse(options, args); + if (cmd.hasOption("i")) { + testResponse = true; + } + } catch (ParseException e) { + System.out.println(e); + e.printStackTrace(); + return; } try {