Merge 'bindings/java: Clean up ' from Kim Seon Woo

- Add finals to classes where we don't want users to inherit
- Make `JDBC4ResultSet` to implement `ResultSetMetaData` and add TODOs

Closes #1045
This commit is contained in:
Pekka Enberg
2025-02-24 11:20:44 +02:00
17 changed files with 144 additions and 22 deletions

View File

@@ -9,7 +9,7 @@ import tech.turso.jdbc4.JDBC4Connection;
import tech.turso.utils.Logger;
import tech.turso.utils.LoggerFactory;
public class JDBC implements Driver {
public final class JDBC implements Driver {
private static final Logger logger = LoggerFactory.getLogger(JDBC.class);
private static final String VALID_URL_PREFIX = "jdbc:sqlite:";

View File

@@ -5,7 +5,7 @@ import java.util.Arrays;
import java.util.Properties;
/** Limbo Configuration. */
public class LimboConfig {
public final class LimboConfig {
private final Properties pragma;
public LimboConfig(Properties properties) {

View File

@@ -11,7 +11,7 @@ import tech.turso.annotations.Nullable;
import tech.turso.annotations.SkipNullableCheck;
/** Provides {@link DataSource} API for configuring Limbo database connection. */
public class LimboDataSource implements DataSource {
public final class LimboDataSource implements DataSource {
private final LimboConfig limboConfig;
private final String url;

View File

@@ -10,7 +10,7 @@ import tech.turso.utils.LimboExceptionUtils;
import tech.turso.utils.Logger;
import tech.turso.utils.LoggerFactory;
public class LimboConnection {
public final class LimboConnection {
private static final Logger logger = LoggerFactory.getLogger(LimboConnection.class);
private final String url;

View File

@@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Factory class for managing and creating instances of {@link LimboDB}. This class ensures that
* multiple instances of {@link LimboDB} with the same URL are not created.
*/
public class LimboDBFactory {
public final class LimboDBFactory {
private static final ConcurrentHashMap<String, LimboDB> databaseHolder =
new ConcurrentHashMap<>();

View File

@@ -13,7 +13,7 @@ import tech.turso.utils.LoggerFactory;
* <p>A {@link LimboResultSet} object is automatically closed when the {@link LimboStatement} object
* that generated it is closed or re-executed.
*/
public class LimboResultSet {
public final class LimboResultSet {
private static final Logger log = LoggerFactory.getLogger(LimboResultSet.class);

View File

@@ -14,7 +14,7 @@ import tech.turso.utils.LoggerFactory;
* objects. All execution method in the <code>LimboStatement</code> implicitly close the current
* <code>resultSet</code> object of the statement if an open one exists.
*/
public class LimboStatement {
public final class LimboStatement {
private static final Logger log = LoggerFactory.getLogger(LimboStatement.class);
private final String sql;

View File

@@ -5,7 +5,7 @@ import tech.turso.annotations.NativeInvocation;
import tech.turso.annotations.Nullable;
/** Represents the step result of limbo's statement's step function. */
public class LimboStepResult {
public final class LimboStepResult {
private static final int STEP_RESULT_ID_ROW = 10;
private static final int STEP_RESULT_ID_IO = 20;
private static final int STEP_RESULT_ID_DONE = 30;

View File

@@ -16,7 +16,7 @@
package tech.turso.core;
/** Sqlite error codes. */
public class SqliteCode {
public final class SqliteCode {
/** Successful result */
public static final int SQLITE_OK = 0;

View File

@@ -3,7 +3,7 @@ package tech.turso.exceptions;
import java.sql.SQLException;
import tech.turso.LimboErrorCode;
public class LimboException extends SQLException {
public final class LimboException extends SQLException {
private final LimboErrorCode resultCode;
public LimboException(String message, LimboErrorCode resultCode) {

View File

@@ -9,7 +9,7 @@ import tech.turso.annotations.SkipNullableCheck;
import tech.turso.core.LimboConnection;
import tech.turso.core.LimboStatement;
public class JDBC4Connection implements Connection {
public final class JDBC4Connection implements Connection {
private final LimboConnection connection;
@@ -87,8 +87,7 @@ public class JDBC4Connection implements Connection {
@Override
@SkipNullableCheck
public DatabaseMetaData getMetaData() throws SQLException {
// TODO
return null;
return new JDBC4DatabaseMetaData(this);
}
@Override

View File

@@ -15,7 +15,7 @@ import tech.turso.annotations.SkipNullableCheck;
import tech.turso.utils.Logger;
import tech.turso.utils.LoggerFactory;
public class JDBC4DatabaseMetaData implements DatabaseMetaData {
public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
private static final Logger logger = LoggerFactory.getLogger(JDBC4DatabaseMetaData.class);

View File

@@ -25,7 +25,7 @@ import java.util.Calendar;
import tech.turso.annotations.SkipNullableCheck;
import tech.turso.core.LimboResultSet;
public class JDBC4PreparedStatement extends JDBC4Statement implements PreparedStatement {
public final class JDBC4PreparedStatement extends JDBC4Statement implements PreparedStatement {
private final String sql;

View File

@@ -26,7 +26,7 @@ import tech.turso.annotations.Nullable;
import tech.turso.annotations.SkipNullableCheck;
import tech.turso.core.LimboResultSet;
public class JDBC4ResultSet implements ResultSet {
public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
private final LimboResultSet resultSet;
@@ -310,10 +310,8 @@ public class JDBC4ResultSet implements ResultSet {
}
@Override
@SkipNullableCheck
public ResultSetMetaData getMetaData() throws SQLException {
// TODO
return null;
return this;
}
@Override
@@ -1181,6 +1179,131 @@ public class JDBC4ResultSet implements ResultSet {
return false;
}
@Override
public int getColumnCount() throws SQLException {
return this.resultSet.getColumnNames().length;
}
@Override
public boolean isAutoIncrement(int column) throws SQLException {
// TODO
return false;
}
@Override
public boolean isCaseSensitive(int column) throws SQLException {
// TODO
return false;
}
@Override
public boolean isSearchable(int column) throws SQLException {
// TODO
return false;
}
@Override
public boolean isCurrency(int column) throws SQLException {
// TODO
return false;
}
@Override
public int isNullable(int column) throws SQLException {
// TODO
return 0;
}
@Override
public boolean isSigned(int column) throws SQLException {
// TODO
return false;
}
@Override
public int getColumnDisplaySize(int column) throws SQLException {
// TODO
return 0;
}
@Override
public String getColumnLabel(int column) throws SQLException {
// TODO
return "";
}
@Override
public String getColumnName(int column) throws SQLException {
// TODO
return "";
}
@Override
public String getSchemaName(int column) throws SQLException {
// TODO
return "";
}
@Override
public int getPrecision(int column) throws SQLException {
// TODO
return 0;
}
@Override
public int getScale(int column) throws SQLException {
// TODO
return 0;
}
@Override
public String getTableName(int column) throws SQLException {
// TODO
return "";
}
@Override
public String getCatalogName(int column) throws SQLException {
// TODO
return "";
}
@Override
public int getColumnType(int column) throws SQLException {
// TODO
return 0;
}
@Override
public String getColumnTypeName(int column) throws SQLException {
// TODO
return "";
}
@Override
public boolean isReadOnly(int column) throws SQLException {
// TODO
return false;
}
@Override
public boolean isWritable(int column) throws SQLException {
// TODO
return false;
}
@Override
public boolean isDefinitelyWritable(int column) throws SQLException {
// TODO
return false;
}
@Override
public String getColumnClassName(int column) throws SQLException {
// TODO
return "";
}
@FunctionalInterface
public interface ResultSetSupplier<T> {
T get() throws Exception;

View File

@@ -3,7 +3,7 @@ package tech.turso.utils;
import java.nio.charset.StandardCharsets;
import tech.turso.annotations.Nullable;
public class ByteArrayUtils {
public final class ByteArrayUtils {
@Nullable
public static String utf8ByteBufferToString(@Nullable byte[] buffer) {
if (buffer == null) {

View File

@@ -7,7 +7,7 @@ import tech.turso.LimboErrorCode;
import tech.turso.annotations.Nullable;
import tech.turso.exceptions.LimboException;
public class LimboExceptionUtils {
public final class LimboExceptionUtils {
/**
* Throws formatted SQLException with error code and message.
*

View File

@@ -6,7 +6,7 @@ import java.util.logging.Level;
* A factory for {@link Logger} instances that uses SLF4J if present, falling back on a
* java.util.logging implementation otherwise.
*/
public class LoggerFactory {
public final class LoggerFactory {
static final boolean USE_SLF4J;
static {