mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-18 06:24:56 +01:00
Merge 'bindings/java: Implement close() for LimboStatement and LimboResultSet ' from Kim Seon Woo
## Purpose of this PR - Implement `close()` method for `LimboStatement`(+`JDBC4Statement`) and `LimboResultSet`(+ `JDBC4ResultSet`) ## Changes - Add `consumeAll` method in `LimboResultSet` - Implement `close()` methods - Because `JDBC4Statement` has longer lifecycle in compared to `LimboStatement`, we manage different `close` fields(`LimboStatement` is created when first `execute` method is called on `JDBC4Statemenet`) ## Reference - [Issue](https://github.com/tursodatabase/limbo/issues/615) Closes #799
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package org.github.tursodatabase.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Properties;
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
import org.github.tursodatabase.jdbc4.JDBC4Connection;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class LimboStatementTest {
|
||||
|
||||
private JDBC4Connection connection;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
String filePath = TestUtils.createTempFile();
|
||||
String url = "jdbc:sqlite:" + filePath;
|
||||
connection = new JDBC4Connection(url, filePath, new Properties());
|
||||
}
|
||||
|
||||
@Test
|
||||
void closing_statement_closes_related_resources() throws Exception {
|
||||
LimboStatement stmt = connection.prepare("SELECT 1;");
|
||||
stmt.execute();
|
||||
|
||||
stmt.close();
|
||||
assertTrue(stmt.isClosed());
|
||||
assertFalse(stmt.getResultSet().isOpen());
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.github.tursodatabase.jdbc4;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
@@ -57,4 +59,24 @@ class JDBC4ResultSetTest {
|
||||
// as well
|
||||
assertFalse(resultSet.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
void close_resultSet_test() throws Exception {
|
||||
stmt.executeQuery("SELECT 1;");
|
||||
ResultSet resultSet = stmt.getResultSet();
|
||||
|
||||
assertFalse(resultSet.isClosed());
|
||||
resultSet.close();
|
||||
assertTrue(resultSet.isClosed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void calling_methods_on_closed_resultSet_should_throw_exception() throws Exception {
|
||||
stmt.executeQuery("SELECT 1;");
|
||||
ResultSet resultSet = stmt.getResultSet();
|
||||
resultSet.close();
|
||||
assertTrue(resultSet.isClosed());
|
||||
|
||||
assertThrows(SQLException.class, resultSet::next);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.github.tursodatabase.jdbc4;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
@@ -51,4 +52,22 @@ class JDBC4StatementTest {
|
||||
stmt.execute("INSERT INTO users VALUES (1, 'limbo');");
|
||||
assertTrue(stmt.execute("SELECT * FROM users;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void close_statement_test() throws Exception {
|
||||
stmt.close();
|
||||
assertTrue(stmt.isClosed());
|
||||
}
|
||||
|
||||
@Test
|
||||
void double_close_is_no_op() throws SQLException {
|
||||
stmt.close();
|
||||
assertDoesNotThrow(() -> stmt.close());
|
||||
}
|
||||
|
||||
@Test
|
||||
void operations_on_closed_statement_should_throw_exception() throws Exception {
|
||||
stmt.close();
|
||||
assertThrows(SQLException.class, () -> stmt.execute("SELECT 1;"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user