diff --git a/bindings/java/src/main/java/org/github/tursodatabase/core/CoreStatement.java b/bindings/java/src/main/java/org/github/tursodatabase/core/CoreStatement.java index f71827d07..98dd89ab3 100644 --- a/bindings/java/src/main/java/org/github/tursodatabase/core/CoreStatement.java +++ b/bindings/java/src/main/java/org/github/tursodatabase/core/CoreStatement.java @@ -1,5 +1,26 @@ package org.github.tursodatabase.core; -// TODO: add fields and methods -public class CoreStatement { +import org.github.tursodatabase.LimboConnection; + +import java.sql.SQLException; + +public abstract class CoreStatement { + + private final LimboConnection connection; + + protected CoreStatement(LimboConnection connection) { + this.connection = connection; + } + + protected void internalClose() throws SQLException { + // TODO + } + + protected void clearGeneratedKeys() throws SQLException { + // TODO + } + + protected void updateGeneratedKeys() throws SQLException { + // TODO + } } diff --git a/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java b/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java index f3eb0f6ed..d8ea925b4 100644 --- a/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java +++ b/bindings/java/src/main/java/org/github/tursodatabase/jdbc4/JDBC4Statement.java @@ -1,13 +1,23 @@ package org.github.tursodatabase.jdbc4; +import org.github.tursodatabase.LimboConnection; import org.github.tursodatabase.annotations.SkipNullableCheck; +import org.github.tursodatabase.core.CoreStatement; import java.sql.*; /** * Implementation of the {@link Statement} interface for JDBC 4. */ -public class JDBC4Statement implements Statement { +public class JDBC4Statement extends CoreStatement implements Statement { + + private boolean closed; + private boolean closeOnCompletion; + + public JDBC4Statement(LimboConnection connection) { + super(connection); + } + @Override @SkipNullableCheck public ResultSet executeQuery(String sql) throws SQLException { @@ -23,7 +33,9 @@ public class JDBC4Statement implements Statement { @Override public void close() throws SQLException { - // TODO + clearGeneratedKeys(); + internalClose(); + closed = true; } @Override @@ -242,13 +254,17 @@ public class JDBC4Statement implements Statement { @Override public void closeOnCompletion() throws SQLException { - // TODO + if (closed) throw new SQLException("statement is closed"); + closeOnCompletion = true; } + /** + * Indicates whether the statement should be closed automatically when all its dependent result sets are closed. + */ @Override public boolean isCloseOnCompletion() throws SQLException { - // TODO - return false; + if (closed) throw new SQLException("statement is closed"); + return closeOnCompletion; } @Override