-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a program to reproduce the issue 948
- Loading branch information
1 parent
9a43c09
commit 6c378ac
Showing
5 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/CreateTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Insert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
modules/cases/src/main/java/com/tsurugidb/tsubakuro/examples/resultsetClose/Select.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |