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

@@ -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();
}
}