Skip to content

Commit

Permalink
revise resultsetClose to ensure SCD-00403 is generated
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Sep 6, 2024
1 parent d8b92a8 commit 379bd39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)",
Expand All @@ -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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 379bd39

Please sign in to comment.