Skip to content

Commit

Permalink
add a program to reproduce the issue 948
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Aug 29, 2024
1 parent 9a43c09 commit 6c378ac
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/cases/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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() {
}
}
Original file line number Diff line number Diff line change
@@ -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) {
}
}
Original file line number Diff line number Diff line change
@@ -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<ResultSet> 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() {
}
}

0 comments on commit 6c378ac

Please sign in to comment.