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>( fn row_to_obj_array<'local>(
env: &mut JNIEnv<'local>, env: &mut JNIEnv<'local>,
row: &limbo_core::Row, row: &limbo_core::Row,

View File

@@ -50,7 +50,11 @@ public class LimboResultSet {
* cursor can only move forward. * cursor can only move forward.
*/ */
public boolean next() throws SQLException { 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 return false; // completed ResultSet
} }
@@ -97,6 +101,11 @@ public class LimboResultSet {
} }
} }
public void close() throws SQLException {
this.statement.close();
this.open = false;
}
@Override @Override
public String toString() { public String toString() {
return "LimboResultSet{" return "LimboResultSet{"

View File

@@ -67,6 +67,16 @@ public class LimboStatement {
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes); 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 @Override
public String toString() { public String toString() {
return "LimboStatement{" return "LimboStatement{"

View File

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

View File

@@ -57,4 +57,28 @@ class JDBC4ResultSetTest {
// as well // as well
assertFalse(resultSet.next()); 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();
}
} }