mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-20 15:35:29 +01:00
Implement close on LimboStatement and JDBC4Statement independently
This commit is contained in:
@@ -114,7 +114,6 @@ public class LimboResultSet {
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
this.statement.close();
|
||||
this.open = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public class LimboStatement {
|
||||
private final long statementPointer;
|
||||
private final LimboResultSet resultSet;
|
||||
|
||||
private boolean closed;
|
||||
|
||||
// TODO: what if the statement we ran was DDL, update queries and etc. Should we still create a
|
||||
// resultSet?
|
||||
public LimboStatement(String sql, long statementPointer) {
|
||||
@@ -71,12 +73,26 @@ public class LimboStatement {
|
||||
* 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() {
|
||||
public void close() throws SQLException {
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
this.resultSet.close();
|
||||
_close(statementPointer);
|
||||
closed = true;
|
||||
}
|
||||
|
||||
private native void _close(long statementPointer);
|
||||
|
||||
/**
|
||||
* Checks if the statement is closed.
|
||||
*
|
||||
* @return true if the statement is closed, false otherwise.
|
||||
*/
|
||||
public boolean isClosed() {
|
||||
return closed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LimboStatement{"
|
||||
|
||||
@@ -19,6 +19,8 @@ public class JDBC4Statement implements Statement {
|
||||
private final LimboConnection connection;
|
||||
@Nullable private LimboStatement statement = null;
|
||||
|
||||
// Because JDBC4Statement has different life cycle in compared to LimboStatement, let's use this
|
||||
// field to manage JDBC4Statement lifecycle
|
||||
private boolean closed;
|
||||
private boolean closeOnCompletion;
|
||||
|
||||
@@ -73,8 +75,14 @@ public class JDBC4Statement implements Statement {
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
clearGeneratedKeys();
|
||||
internalClose();
|
||||
if (closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.statement != null) {
|
||||
this.statement.close();
|
||||
}
|
||||
|
||||
closed = true;
|
||||
}
|
||||
|
||||
@@ -148,8 +156,7 @@ public class JDBC4Statement implements Statement {
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
internalClose();
|
||||
|
||||
ensureOpen();
|
||||
return this.withConnectionTimeout(
|
||||
() -> {
|
||||
try {
|
||||
@@ -296,8 +303,7 @@ public class JDBC4Statement implements Statement {
|
||||
|
||||
@Override
|
||||
public boolean isClosed() throws SQLException {
|
||||
// TODO
|
||||
return false;
|
||||
return this.closed;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,14 +350,6 @@ public class JDBC4Statement implements Statement {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void internalClose() throws SQLException {
|
||||
// TODO
|
||||
}
|
||||
|
||||
protected void clearGeneratedKeys() throws SQLException {
|
||||
// TODO
|
||||
}
|
||||
|
||||
protected void updateGeneratedKeys() throws SQLException {
|
||||
// TODO
|
||||
}
|
||||
@@ -376,4 +374,10 @@ public class JDBC4Statement implements Statement {
|
||||
protected interface SQLCallable<T> {
|
||||
T call() throws SQLException;
|
||||
}
|
||||
|
||||
private void ensureOpen() throws SQLException {
|
||||
if (closed) {
|
||||
throw new SQLException("Statement is closed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user