Implement close() on LimboStatement

This commit is contained in:
김선우 2025-01-27 20:20:10 +09:00
parent ef6a1be335
commit 4dd2d1c64a
5 changed files with 55 additions and 4 deletions

View file

@ -88,6 +88,15 @@ pub extern "system" fn Java_org_github_tursodatabase_core_LimboStatement_step<'l
}
}
#[no_mangle]
pub extern "system" fn Java_org_github_tursodatabase_core_LimboStatement__1close<'local>(
_env: JNIEnv<'local>,
_obj: JObject<'local>,
stmt_ptr: jlong
) {
LimboStatement::drop(stmt_ptr);
}
fn row_to_obj_array<'local>(
env: &mut JNIEnv<'local>,
row: &limbo_core::Row,

View file

@ -50,7 +50,11 @@ public class LimboResultSet {
* cursor can only move forward.
*/
public boolean next() throws SQLException {
if (!open || isEmptyResultSet || pastLastRow) {
if (!open) {
throw new SQLException("The resultSet is not open");
}
if (isEmptyResultSet || pastLastRow) {
return false; // completed ResultSet
}
@ -97,6 +101,11 @@ public class LimboResultSet {
}
}
public void close() throws SQLException {
this.statement.close();
this.open = false;
}
@Override
public String toString() {
return "LimboResultSet{"

View file

@ -67,6 +67,16 @@ public class LimboStatement {
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes);
}
/**
* Closes the current statement and releases any resources associated with it. This method calls
* the native `_close` method to perform the actual closing operation.
*/
public void close() {
_close(statementPointer);
}
private native void _close(long statementPointer);
@Override
public String toString() {
return "LimboStatement{"

View file

@ -25,7 +25,7 @@ public class JDBC4ResultSet implements ResultSet {
@Override
public void close() throws SQLException {
// TODO
resultSet.close();
}
@Override
@ -866,8 +866,7 @@ public class JDBC4ResultSet implements ResultSet {
@Override
public boolean isClosed() throws SQLException {
// TODO
return false;
return !resultSet.isOpen();
}
@Override

View file

@ -57,4 +57,28 @@ class JDBC4ResultSetTest {
// as well
assertFalse(resultSet.next());
}
@Test
void resultSet_close_test() throws Exception {
stmt.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
stmt.executeUpdate("INSERT INTO users VALUES (2, 'seonwoo');");
stmt.executeQuery("SELECT * FROM users");
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.executeUpdate("CREATE TABLE users (id INT PRIMARY KEY, username TEXT);");
stmt.executeUpdate("INSERT INTO users VALUES (2, 'seonwoo');");
stmt.executeQuery("SELECT * FROM users");
ResultSet resultSet = stmt.getResultSet();
resultSet.close();
assertTrue(resultSet.isClosed());
resultSet.next();
}
}