mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 11:14:20 +01:00
bind/java: Rename to Turso
This commit is contained in:
@@ -5,15 +5,16 @@ import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
import tech.turso.core.LimboPropertiesHolder;
|
||||
import tech.turso.core.TursoPropertiesHolder;
|
||||
import tech.turso.jdbc4.JDBC4Connection;
|
||||
import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
|
||||
public final class JDBC implements Driver {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JDBC.class);
|
||||
|
||||
private static final String VALID_URL_PREFIX = "jdbc:sqlite:";
|
||||
private static final String VALID_URL_PREFIX = "jdbc:turso:";
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -33,7 +34,7 @@ public final class JDBC implements Driver {
|
||||
}
|
||||
|
||||
private static boolean isValidURL(String url) {
|
||||
return url != null && url.toLowerCase(Locale.ROOT).startsWith(VALID_URL_PREFIX);
|
||||
return (url != null && url.toLowerCase(Locale.ROOT).startsWith(VALID_URL_PREFIX));
|
||||
}
|
||||
|
||||
private static String extractAddress(String url) {
|
||||
@@ -53,17 +54,17 @@ public final class JDBC implements Driver {
|
||||
|
||||
@Override
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
return LimboConfig.getDriverPropertyInfo();
|
||||
return TursoConfig.getDriverPropertyInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return Integer.parseInt(LimboPropertiesHolder.getDriverVersion().split("\\.")[0]);
|
||||
return Integer.parseInt(TursoPropertiesHolder.getDriverVersion().split("\\.")[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return Integer.parseInt(LimboPropertiesHolder.getDriverVersion().split("\\.")[1]);
|
||||
return Integer.parseInt(TursoPropertiesHolder.getDriverVersion().split("\\.")[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,11 +4,12 @@ import java.sql.DriverPropertyInfo;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
|
||||
/** Limbo Configuration. */
|
||||
public final class LimboConfig {
|
||||
private final Properties pragma;
|
||||
/** Turso Configuration. */
|
||||
public final class TursoConfig {
|
||||
|
||||
public LimboConfig(Properties properties) {
|
||||
private Properties pragma;
|
||||
|
||||
public TursoConfig(Properties properties) {
|
||||
this.pragma = properties;
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ public final class LimboConfig {
|
||||
|
||||
public enum Pragma {
|
||||
;
|
||||
|
||||
private final String pragmaName;
|
||||
private final String description;
|
||||
private final String[] choices;
|
||||
@@ -10,19 +10,19 @@ import javax.sql.DataSource;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
|
||||
/** Provides {@link DataSource} API for configuring Limbo database connection. */
|
||||
public final class LimboDataSource implements DataSource {
|
||||
/** Provides {@link DataSource} API for configuring Turso database connection. */
|
||||
public final class TursoDataSource implements DataSource {
|
||||
|
||||
private final LimboConfig limboConfig;
|
||||
private final TursoConfig tursoConfig;
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* Creates a datasource based on the provided configuration.
|
||||
*
|
||||
* @param limboConfig The configuration for the datasource.
|
||||
* @param tursoConfig The configuration for the datasource.
|
||||
*/
|
||||
public LimboDataSource(LimboConfig limboConfig, String url) {
|
||||
this.limboConfig = limboConfig;
|
||||
public TursoDataSource(TursoConfig tursoConfig, String url) {
|
||||
this.tursoConfig = tursoConfig;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public final class LimboDataSource implements DataSource {
|
||||
@Nullable
|
||||
public Connection getConnection(@Nullable String username, @Nullable String password)
|
||||
throws SQLException {
|
||||
Properties properties = limboConfig.toProperties();
|
||||
Properties properties = tursoConfig.toProperties();
|
||||
if (username != null) properties.put("user", username);
|
||||
if (password != null) properties.put("pass", password);
|
||||
return JDBC.createConnection(url, properties);
|
||||
@@ -2,8 +2,8 @@ package tech.turso;
|
||||
|
||||
import tech.turso.core.SqliteCode;
|
||||
|
||||
/** Limbo error code. Superset of SQLite3 error code. */
|
||||
public enum LimboErrorCode {
|
||||
/** Turso error code. Superset of SQLite3 error code. */
|
||||
public enum TursoErrorCode {
|
||||
SQLITE_OK(SqliteCode.SQLITE_OK, "Successful result"),
|
||||
SQLITE_ERROR(SqliteCode.SQLITE_ERROR, "SQL error or missing database"),
|
||||
SQLITE_INTERNAL(SqliteCode.SQLITE_INTERNAL, "An internal logic error in SQLite"),
|
||||
@@ -37,9 +37,9 @@ public enum LimboErrorCode {
|
||||
SQLITE_NULL(SqliteCode.SQLITE_NULL, "Null type"),
|
||||
|
||||
UNKNOWN_ERROR(-1, "Unknown error"),
|
||||
LIMBO_FAILED_TO_PARSE_BYTE_ARRAY(1100, "Failed to parse ut8 byte array"),
|
||||
LIMBO_FAILED_TO_PREPARE_STATEMENT(1200, "Failed to prepare statement"),
|
||||
LIMBO_ETC(9999, "Unclassified error");
|
||||
TURSO_FAILED_TO_PARSE_BYTE_ARRAY(1100, "Failed to parse ut8 byte array"),
|
||||
TURSO_FAILED_TO_PREPARE_STATEMENT(1200, "Failed to prepare statement"),
|
||||
TURSO_ETC(9999, "Unclassified error");
|
||||
|
||||
public final int code;
|
||||
public final String message;
|
||||
@@ -48,14 +48,14 @@ public enum LimboErrorCode {
|
||||
* @param code Error code
|
||||
* @param message Message for the error.
|
||||
*/
|
||||
LimboErrorCode(int code, String message) {
|
||||
TursoErrorCode(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static LimboErrorCode getErrorCode(int errorCode) {
|
||||
for (LimboErrorCode limboErrorCode : LimboErrorCode.values()) {
|
||||
if (errorCode == limboErrorCode.code) return limboErrorCode;
|
||||
public static TursoErrorCode getErrorCode(int errorCode) {
|
||||
for (TursoErrorCode tursoErrorCode : TursoErrorCode.values()) {
|
||||
if (errorCode == tursoErrorCode.code) return tursoErrorCode;
|
||||
}
|
||||
|
||||
return UNKNOWN_ERROR;
|
||||
@@ -63,6 +63,6 @@ public enum LimboErrorCode {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LimboErrorCode{" + "code=" + code + ", message='" + message + '\'' + '}';
|
||||
return ("tursoErrorCode{" + "code=" + code + ", message='" + message + '\'' + '}');
|
||||
}
|
||||
}
|
||||
@@ -6,37 +6,38 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
import tech.turso.annotations.NativeInvocation;
|
||||
import tech.turso.utils.LimboExceptionUtils;
|
||||
import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
import tech.turso.utils.TursoExceptionUtils;
|
||||
|
||||
public final class LimboConnection {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LimboConnection.class);
|
||||
public final class TursoConnection {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TursoConnection.class);
|
||||
|
||||
private final String url;
|
||||
private final long connectionPtr;
|
||||
private final LimboDB database;
|
||||
private final TursoDB database;
|
||||
private boolean closed;
|
||||
|
||||
public LimboConnection(String url, String filePath) throws SQLException {
|
||||
public TursoConnection(String url, String filePath) throws SQLException {
|
||||
this(url, filePath, new Properties());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a connection to limbo database
|
||||
* Creates a connection to turso database
|
||||
*
|
||||
* @param url e.g. "jdbc:sqlite:fileName"
|
||||
* @param url e.g. "jdbc:turso:fileName"
|
||||
* @param filePath path to file
|
||||
*/
|
||||
public LimboConnection(String url, String filePath, Properties properties) throws SQLException {
|
||||
public TursoConnection(String url, String filePath, Properties properties) throws SQLException {
|
||||
this.url = url;
|
||||
this.database = open(url, filePath, properties);
|
||||
this.connectionPtr = this.database.connect();
|
||||
}
|
||||
|
||||
private static LimboDB open(String url, String filePath, Properties properties)
|
||||
private static TursoDB open(String url, String filePath, Properties properties)
|
||||
throws SQLException {
|
||||
return LimboDBFactory.open(url, filePath, properties);
|
||||
return TursoDBFactory.open(url, filePath, properties);
|
||||
}
|
||||
|
||||
public void checkOpen() throws SQLException {
|
||||
@@ -61,7 +62,7 @@ public final class LimboConnection {
|
||||
return closed;
|
||||
}
|
||||
|
||||
public LimboDB getDatabase() {
|
||||
public TursoDB getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
@@ -72,18 +73,18 @@ public final class LimboConnection {
|
||||
* @return Pointer to statement.
|
||||
* @throws SQLException if a database access error occurs.
|
||||
*/
|
||||
public LimboStatement prepare(String sql) throws SQLException {
|
||||
public TursoStatement prepare(String sql) throws SQLException {
|
||||
logger.trace("DriverManager [{}] [SQLite EXEC] {}", Thread.currentThread().getName(), sql);
|
||||
byte[] sqlBytes = stringToUtf8ByteArray(sql);
|
||||
if (sqlBytes == null) {
|
||||
throw new SQLException("Failed to convert " + sql + " into bytes");
|
||||
}
|
||||
return new LimboStatement(sql, prepareUtf8(connectionPtr, sqlBytes));
|
||||
return new TursoStatement(sql, prepareUtf8(connectionPtr, sqlBytes));
|
||||
}
|
||||
|
||||
private native long prepareUtf8(long connectionPtr, byte[] sqlUtf8) throws SQLException;
|
||||
|
||||
// TODO: check whether this is still valid for limbo
|
||||
// TODO: check whether this is still valid for turso
|
||||
/**
|
||||
* Checks whether the type, concurrency, and holdability settings for a {@link ResultSet} are
|
||||
* supported by the SQLite interface. Supported settings are:
|
||||
@@ -117,8 +118,8 @@ public final class LimboConnection {
|
||||
* @param errorCode Error code.
|
||||
* @param errorMessageBytes Error message.
|
||||
*/
|
||||
@NativeInvocation(invokedFrom = "limbo_connection.rs")
|
||||
private void throwLimboException(int errorCode, byte[] errorMessageBytes) throws SQLException {
|
||||
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes);
|
||||
@NativeInvocation(invokedFrom = "turso_connection.rs")
|
||||
private void throwTursoException(int errorCode, byte[] errorMessageBytes) throws SQLException {
|
||||
TursoExceptionUtils.throwTursoException(errorCode, errorMessageBytes);
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,17 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import tech.turso.LimboErrorCode;
|
||||
import tech.turso.TursoErrorCode;
|
||||
import tech.turso.annotations.NativeInvocation;
|
||||
import tech.turso.annotations.VisibleForTesting;
|
||||
import tech.turso.utils.LimboExceptionUtils;
|
||||
import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
import tech.turso.utils.TursoExceptionUtils;
|
||||
|
||||
/** This class provides a thin JNI layer over the SQLite3 C API. */
|
||||
public final class LimboDB implements AutoCloseable {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LimboDB.class);
|
||||
public final class TursoDB implements AutoCloseable {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TursoDB.class);
|
||||
// Pointer to database instance
|
||||
private long dbPointer;
|
||||
private boolean isOpen;
|
||||
@@ -39,10 +40,10 @@ public final class LimboDB implements AutoCloseable {
|
||||
* extensions.
|
||||
*/
|
||||
enum Architecture {
|
||||
MACOS_ARM64("libs/macos_arm64/lib_limbo_java.dylib", ".dylib"),
|
||||
MACOS_X86("libs/macos_x86/lib_limbo_java.dylib", ".dylib"),
|
||||
LINUX_X86("libs/linux_x86/lib_limbo_java.so", ".so"),
|
||||
WINDOWS("libs/windows/lib_limbo_java.dll", ".dll"),
|
||||
MACOS_ARM64("libs/macos_arm64/lib_turso_java.dylib", ".dylib"),
|
||||
MACOS_X86("libs/macos_x86/lib_turso_java.dylib", ".dylib"),
|
||||
LINUX_X86("libs/linux_x86/lib_turso_java.so", ".so"),
|
||||
WINDOWS("libs/windows/lib_turso_java.dll", ".dll"),
|
||||
UNSUPPORTED("", "");
|
||||
|
||||
private final String libPath;
|
||||
@@ -90,7 +91,7 @@ public final class LimboDB implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method attempts to load the native library required for Limbo operations. It first tries
|
||||
* This method attempts to load the native library required for turso operations. It first tries
|
||||
* to load the library from the system's library path using {@link #loadFromSystemPath()}. If that
|
||||
* fails, it attempts to load the library from the JAR file using {@link #loadFromJar()}. If
|
||||
* either method succeeds, the `isLoaded` flag is set to true. If both methods fail, an {@link
|
||||
@@ -115,14 +116,14 @@ public final class LimboDB implements AutoCloseable {
|
||||
/**
|
||||
* Load the native library from the system path.
|
||||
*
|
||||
* <p>This method attempts to load the native library named "_limbo_java" from the system's
|
||||
* <p>This method attempts to load the native library named "_turso_java" from the system's
|
||||
* library path. If the library is successfully loaded, the `isLoaded` flag is set to true.
|
||||
*
|
||||
* @return true if the library was successfully loaded, false otherwise.
|
||||
*/
|
||||
private static boolean loadFromSystemPath() {
|
||||
try {
|
||||
System.loadLibrary("_limbo_java");
|
||||
System.loadLibrary("_turso_java");
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
logger.info("Unable to load from default path: {}", String.valueOf(t));
|
||||
@@ -148,7 +149,7 @@ public final class LimboDB implements AutoCloseable {
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream is = LimboDB.class.getClassLoader().getResourceAsStream(arch.getLibPath());
|
||||
InputStream is = TursoDB.class.getClassLoader().getResourceAsStream(arch.getLibPath());
|
||||
assert is != null;
|
||||
File file = convertInputStreamToFile(is, arch);
|
||||
System.load(file.getPath());
|
||||
@@ -178,15 +179,15 @@ public final class LimboDB implements AutoCloseable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url e.g. "jdbc:sqlite:fileName
|
||||
* @param url eTurso.gTursoTurso. "jdbc:turso:fileName
|
||||
* @param filePath e.g. path to file
|
||||
*/
|
||||
public static LimboDB create(String url, String filePath) throws SQLException {
|
||||
return new LimboDB(url, filePath);
|
||||
public static TursoDB create(String url, String filePath) throws SQLException {
|
||||
return new TursoDB(url, filePath);
|
||||
}
|
||||
|
||||
// TODO: receive config as argument
|
||||
private LimboDB(String url, String filePath) {
|
||||
private TursoDB(String url, String filePath) {
|
||||
this.url = url;
|
||||
this.filePath = filePath;
|
||||
}
|
||||
@@ -208,14 +209,14 @@ public final class LimboDB implements AutoCloseable {
|
||||
|
||||
private void open0(String filePath, int openFlags) throws SQLException {
|
||||
if (isOpen) {
|
||||
throw LimboExceptionUtils.buildLimboException(
|
||||
LimboErrorCode.LIMBO_ETC.code, "Already opened");
|
||||
throw TursoExceptionUtils.buildTursoException(
|
||||
TursoErrorCode.TURSO_ETC.code, "Already opened");
|
||||
}
|
||||
|
||||
byte[] filePathBytes = stringToUtf8ByteArray(filePath);
|
||||
if (filePathBytes == null) {
|
||||
throw LimboExceptionUtils.buildLimboException(
|
||||
LimboErrorCode.LIMBO_ETC.code,
|
||||
throw TursoExceptionUtils.buildTursoException(
|
||||
TursoErrorCode.TURSO_ETC.code,
|
||||
"File path cannot be converted to byteArray. File name: " + filePath);
|
||||
}
|
||||
|
||||
@@ -250,8 +251,8 @@ public final class LimboDB implements AutoCloseable {
|
||||
* @param errorCode Error code.
|
||||
* @param errorMessageBytes Error message.
|
||||
*/
|
||||
@NativeInvocation(invokedFrom = "limbo_db.rs")
|
||||
private void throwLimboException(int errorCode, byte[] errorMessageBytes) throws SQLException {
|
||||
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes);
|
||||
@NativeInvocation(invokedFrom = "turso_db.rs")
|
||||
private void throwTursoException(int errorCode, byte[] errorMessageBytes) throws SQLException {
|
||||
TursoExceptionUtils.throwTursoException(errorCode, errorMessageBytes);
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ import java.util.Properties;
|
||||
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.
|
||||
* Factory class for managing and creating instances of {@link TursoDB}. This class ensures that
|
||||
* multiple instances of {@link TursoDB} with the same URL are not created.
|
||||
*/
|
||||
public final class LimboDBFactory {
|
||||
public final class TursoDBFactory {
|
||||
|
||||
private static final ConcurrentHashMap<String, LimboDB> databaseHolder =
|
||||
private static final ConcurrentHashMap<String, TursoDB> databaseHolder =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
@@ -20,11 +20,11 @@ public final class LimboDBFactory {
|
||||
* @param url the URL of the database
|
||||
* @param filePath the path to the database file
|
||||
* @param properties additional properties for the database connection
|
||||
* @return an instance of {@link LimboDB}
|
||||
* @return an instance of {@link tursoDB}
|
||||
* @throws SQLException if there is an error opening the connection
|
||||
* @throws IllegalArgumentException if the fileName is empty
|
||||
*/
|
||||
public static LimboDB open(String url, String filePath, Properties properties)
|
||||
public static TursoDB open(String url, String filePath, Properties properties)
|
||||
throws SQLException {
|
||||
if (databaseHolder.containsKey(url)) {
|
||||
return databaseHolder.get(url);
|
||||
@@ -34,10 +34,10 @@ public final class LimboDBFactory {
|
||||
throw new IllegalArgumentException("filePath should not be empty");
|
||||
}
|
||||
|
||||
final LimboDB database;
|
||||
final TursoDB database;
|
||||
try {
|
||||
LimboDB.load();
|
||||
database = LimboDB.create(url, filePath);
|
||||
TursoDB.load();
|
||||
database = TursoDB.create(url, filePath);
|
||||
} catch (Exception e) {
|
||||
throw new SQLException("Error opening connection", e);
|
||||
}
|
||||
@@ -7,21 +7,24 @@ import tech.turso.jdbc4.JDBC4DatabaseMetaData;
|
||||
import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
|
||||
public class LimboPropertiesHolder {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LimboPropertiesHolder.class);
|
||||
public class TursoPropertiesHolder {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TursoPropertiesHolder.class);
|
||||
|
||||
private static String driverName = "";
|
||||
private static String driverVersion = "";
|
||||
|
||||
static {
|
||||
try (InputStream limboJdbcPropStream =
|
||||
JDBC4DatabaseMetaData.class.getClassLoader().getResourceAsStream("limbo-jdbc.properties")) {
|
||||
if (limboJdbcPropStream == null) {
|
||||
throw new IOException("Cannot load limbo-jdbc.properties from jar");
|
||||
try (InputStream tursoJdbcPropStream =
|
||||
JDBC4DatabaseMetaData.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("turso-jdbc.properties"); ) {
|
||||
if (tursoJdbcPropStream == null) {
|
||||
throw new IOException("Cannot load turso-jdbc.properties from jar");
|
||||
}
|
||||
|
||||
final Properties properties = new Properties();
|
||||
properties.load(limboJdbcPropStream);
|
||||
properties.load(tursoJdbcPropStream);
|
||||
driverName = properties.getProperty("driverName");
|
||||
driverVersion = properties.getProperty("driverVersion");
|
||||
} catch (IOException e) {
|
||||
@@ -7,17 +7,17 @@ import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A table of data representing limbo database result set, which is generated by executing a
|
||||
* A table of data representing turso database result set, which is generated by executing a
|
||||
* statement that queries the database.
|
||||
*
|
||||
* <p>A {@link LimboResultSet} object is automatically closed when the {@link LimboStatement} object
|
||||
* <p>A {@link TursoResultSet} object is automatically closed when the {@link TursoStatement} object
|
||||
* that generated it is closed or re-executed.
|
||||
*/
|
||||
public final class LimboResultSet {
|
||||
public final class TursoResultSet {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(LimboResultSet.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(TursoResultSet.class);
|
||||
|
||||
private final LimboStatement statement;
|
||||
private final TursoStatement statement;
|
||||
|
||||
// Name of the columns
|
||||
private String[] columnNames = new String[0];
|
||||
@@ -31,13 +31,13 @@ public final class LimboResultSet {
|
||||
private int row = 0;
|
||||
private boolean pastLastRow = false;
|
||||
|
||||
@Nullable private LimboStepResult lastStepResult;
|
||||
@Nullable private TursoStepResult lastStepResult;
|
||||
|
||||
public static LimboResultSet of(LimboStatement statement) {
|
||||
return new LimboResultSet(statement);
|
||||
public static TursoResultSet of(TursoStatement statement) {
|
||||
return new TursoResultSet(statement);
|
||||
}
|
||||
|
||||
private LimboResultSet(LimboStatement statement) {
|
||||
private TursoResultSet(TursoStatement statement) {
|
||||
this.open = true;
|
||||
this.statement = statement;
|
||||
}
|
||||
@@ -57,13 +57,13 @@ public final class LimboResultSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the cursor forward one row from its current position. A {@link LimboResultSet} cursor is
|
||||
* Moves the cursor forward one row from its current position. A {@link tursoResultSet} cursor is
|
||||
* initially positioned before the first fow; the first call to the method <code>next</code> makes
|
||||
* the first row the current row; the second call makes the second row the current row, and so on.
|
||||
* When a call to the <code>next</code> method returns <code>false</code>, the cursor is
|
||||
* positioned after the last row.
|
||||
*
|
||||
* <p>Note that limbo only supports <code>ResultSet.TYPE_FORWARD_ONLY</code>, which means that the
|
||||
* <p>Note that turso only supports <code>ResultSet.TYPE_FORWARD_ONLY</code>, which means that the
|
||||
* cursor can only move forward.
|
||||
*/
|
||||
public boolean next() throws SQLException {
|
||||
@@ -157,7 +157,7 @@ public final class LimboResultSet {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LimboResultSet{"
|
||||
return ("tursoResultSet{"
|
||||
+ "statement="
|
||||
+ statement
|
||||
+ ", isEmptyResultSet="
|
||||
@@ -172,6 +172,6 @@ public final class LimboResultSet {
|
||||
+ pastLastRow
|
||||
+ ", lastResult="
|
||||
+ lastStepResult
|
||||
+ '}';
|
||||
+ '}');
|
||||
}
|
||||
}
|
||||
@@ -3,36 +3,37 @@ package tech.turso.core;
|
||||
import java.sql.SQLException;
|
||||
import tech.turso.annotations.NativeInvocation;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.utils.LimboExceptionUtils;
|
||||
import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
import tech.turso.utils.TursoExceptionUtils;
|
||||
|
||||
/**
|
||||
* By default, only one <code>resultSet</code> object per <code>LimboStatement</code> can be open at
|
||||
* By default, only one <code>resultSet</code> object per <code>TursoStatement</code> can be open at
|
||||
* the same time. Therefore, if the reading of one <code>resultSet</code> object is interleaved with
|
||||
* the reading of another, each must have been generated by different <code>LimboStatement</code>
|
||||
* objects. All execution method in the <code>LimboStatement</code> implicitly close the current
|
||||
* the reading of another, each must have been generated by different <code>TursoStatement</code>
|
||||
* objects. All execution method in the <code>TursoStatement</code> implicitly close the current
|
||||
* <code>resultSet</code> object of the statement if an open one exists.
|
||||
*/
|
||||
public final class LimboStatement {
|
||||
private static final Logger log = LoggerFactory.getLogger(LimboStatement.class);
|
||||
public final class TursoStatement {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TursoStatement.class);
|
||||
|
||||
private final String sql;
|
||||
private final long statementPointer;
|
||||
private final LimboResultSet resultSet;
|
||||
private final TursoResultSet 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) {
|
||||
public TursoStatement(String sql, long statementPointer) {
|
||||
this.sql = sql;
|
||||
this.statementPointer = statementPointer;
|
||||
this.resultSet = LimboResultSet.of(this);
|
||||
this.resultSet = TursoResultSet.of(this);
|
||||
log.debug("Creating statement with sql: {}", this.sql);
|
||||
}
|
||||
|
||||
public LimboResultSet getResultSet() {
|
||||
public TursoResultSet getResultSet() {
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
@@ -46,8 +47,8 @@ public final class LimboStatement {
|
||||
return resultSet.hasLastStepReturnedRow();
|
||||
}
|
||||
|
||||
LimboStepResult step() throws SQLException {
|
||||
final LimboStepResult result = step(this.statementPointer);
|
||||
TursoStepResult step() throws SQLException {
|
||||
final TursoStepResult result = step(this.statementPointer);
|
||||
if (result == null) {
|
||||
throw new SQLException("step() returned null, which is only returned when an error occurs");
|
||||
}
|
||||
@@ -56,12 +57,12 @@ public final class LimboStatement {
|
||||
}
|
||||
|
||||
/**
|
||||
* Because Limbo supports async I/O, it is possible to return a {@link LimboStepResult} with
|
||||
* {@link LimboStepResult#STEP_RESULT_ID_ROW}. However, this is handled by the native side, so you
|
||||
* can expect that this method will not return a {@link LimboStepResult#STEP_RESULT_ID_ROW}.
|
||||
* Because turso supports async I/O, it is possible to return a {@link TursoStepResult} with
|
||||
* {@link TursoStepResult#STEP_RESULT_ID_ROW}. However, this is handled by the native side, so you
|
||||
* can expect that this method will not return a {@link TursoStepResult#STEP_RESULT_ID_ROW}.
|
||||
*/
|
||||
@Nullable
|
||||
private native LimboStepResult step(long stmtPointer) throws SQLException;
|
||||
private native TursoStepResult step(long stmtPointer) throws SQLException;
|
||||
|
||||
/**
|
||||
* Throws formatted SQLException with error code and message.
|
||||
@@ -69,9 +70,9 @@ public final class LimboStatement {
|
||||
* @param errorCode Error code.
|
||||
* @param errorMessageBytes Error message.
|
||||
*/
|
||||
@NativeInvocation(invokedFrom = "limbo_statement.rs")
|
||||
private void throwLimboException(int errorCode, byte[] errorMessageBytes) throws SQLException {
|
||||
LimboExceptionUtils.throwLimboException(errorCode, errorMessageBytes);
|
||||
@NativeInvocation(invokedFrom = "turso_statement.rs")
|
||||
private void throwTursoException(int errorCode, byte[] errorMessageBytes) throws SQLException {
|
||||
TursoExceptionUtils.throwTursoException(errorCode, errorMessageBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +91,8 @@ public final class LimboStatement {
|
||||
private native void _close(long statementPointer);
|
||||
|
||||
/**
|
||||
* Initializes the column metadata, such as the names of the columns. Since {@link LimboStatement}
|
||||
* can only have a single {@link LimboResultSet}, it is appropriate to place the initialization of
|
||||
* Initializes the column metadata, such as the names of the columns. Since {@link tursoStatement}
|
||||
* can only have a single {@link tursoResultSet}, it is appropriate to place the initialization of
|
||||
* column metadata here.
|
||||
*
|
||||
* @throws SQLException if a database access error occurs while retrieving column names
|
||||
@@ -125,7 +126,7 @@ public final class LimboStatement {
|
||||
|
||||
/**
|
||||
* Binds an integer value to the prepared statement at the specified position. This function calls
|
||||
* bindLong because Limbo treats all integers as long (as well as SQLite).
|
||||
* bindLong because turso treats all integers as long (as well as SQLite).
|
||||
*
|
||||
* <p>According to SQLite documentation, the value is a signed integer, stored in 0, 1, 2, 3, 4,
|
||||
* 6, or 8 bytes depending on the magnitude of the value.
|
||||
@@ -229,6 +230,7 @@ public final class LimboStatement {
|
||||
}
|
||||
|
||||
private native long totalChanges(long statementPointer) throws SQLException;
|
||||
|
||||
/**
|
||||
* Checks if the statement is closed.
|
||||
*
|
||||
@@ -240,12 +242,12 @@ public final class LimboStatement {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LimboStatement{"
|
||||
return ("tursoStatement{"
|
||||
+ "statementPointer="
|
||||
+ statementPointer
|
||||
+ ", sql='"
|
||||
+ sql
|
||||
+ '\''
|
||||
+ '}';
|
||||
+ '}');
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import java.util.Arrays;
|
||||
import tech.turso.annotations.NativeInvocation;
|
||||
import tech.turso.annotations.Nullable;
|
||||
|
||||
/** Represents the step result of limbo's statement's step function. */
|
||||
public final class LimboStepResult {
|
||||
/** Represents the step result of turso's statement's step function. */
|
||||
public final class TursoStepResult {
|
||||
|
||||
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;
|
||||
@@ -15,18 +16,19 @@ public final class LimboStepResult {
|
||||
private static final int STEP_RESULT_ID_BUSY = 50;
|
||||
private static final int STEP_RESULT_ID_ERROR = 60;
|
||||
|
||||
// Identifier for limbo's StepResult
|
||||
// Identifier for Turso's StepResult
|
||||
private final int stepResultId;
|
||||
|
||||
@Nullable private final Object[] result;
|
||||
|
||||
@NativeInvocation(invokedFrom = "limbo_statement.rs")
|
||||
public LimboStepResult(int stepResultId) {
|
||||
@NativeInvocation(invokedFrom = "turso_statement.rs")
|
||||
public TursoStepResult(int stepResultId) {
|
||||
this.stepResultId = stepResultId;
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
@NativeInvocation(invokedFrom = "limbo_statement.rs")
|
||||
public LimboStepResult(int stepResultId, Object[] result) {
|
||||
@NativeInvocation(invokedFrom = "turso_statement.rs")
|
||||
public TursoStepResult(int stepResultId, Object[] result) {
|
||||
this.stepResultId = stepResultId;
|
||||
this.result = result;
|
||||
}
|
||||
@@ -41,10 +43,10 @@ public final class LimboStepResult {
|
||||
|
||||
public boolean isInInvalidState() {
|
||||
// current implementation doesn't allow STEP_RESULT_ID_IO to be returned
|
||||
return stepResultId == STEP_RESULT_ID_IO
|
||||
return (stepResultId == STEP_RESULT_ID_IO
|
||||
|| stepResultId == STEP_RESULT_ID_INTERRUPT
|
||||
|| stepResultId == STEP_RESULT_ID_BUSY
|
||||
|| stepResultId == STEP_RESULT_ID_ERROR;
|
||||
|| stepResultId == STEP_RESULT_ID_ERROR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -54,12 +56,12 @@ public final class LimboStepResult {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LimboStepResult{"
|
||||
return ("tursoStepResult{"
|
||||
+ "stepResultName="
|
||||
+ getStepResultName()
|
||||
+ ", result="
|
||||
+ Arrays.toString(result)
|
||||
+ '}';
|
||||
+ '}');
|
||||
}
|
||||
|
||||
private String getStepResultName() {
|
||||
@@ -1,17 +0,0 @@
|
||||
package tech.turso.exceptions;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import tech.turso.LimboErrorCode;
|
||||
|
||||
public final class LimboException extends SQLException {
|
||||
private final LimboErrorCode resultCode;
|
||||
|
||||
public LimboException(String message, LimboErrorCode resultCode) {
|
||||
super(message, null, resultCode.code & 0xff);
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
|
||||
public LimboErrorCode getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package tech.turso.exceptions;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import tech.turso.TursoErrorCode;
|
||||
|
||||
public final class TursoException extends SQLException {
|
||||
|
||||
private TursoErrorCode resultCode;
|
||||
|
||||
public TursoException(String message, TursoErrorCode resultCode) {
|
||||
super(message, null, resultCode.code & 0xff);
|
||||
this.resultCode = resultCode;
|
||||
}
|
||||
|
||||
public TursoErrorCode getResultCode() {
|
||||
return resultCode;
|
||||
}
|
||||
}
|
||||
@@ -6,24 +6,24 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
import tech.turso.core.LimboConnection;
|
||||
import tech.turso.core.LimboStatement;
|
||||
import tech.turso.core.TursoConnection;
|
||||
import tech.turso.core.TursoStatement;
|
||||
|
||||
public final class JDBC4Connection implements Connection {
|
||||
|
||||
private final LimboConnection connection;
|
||||
private final TursoConnection connection;
|
||||
|
||||
private Map<String, Class<?>> typeMap = new HashMap<>();
|
||||
|
||||
public JDBC4Connection(String url, String filePath) throws SQLException {
|
||||
this.connection = new LimboConnection(url, filePath);
|
||||
this.connection = new TursoConnection(url, filePath);
|
||||
}
|
||||
|
||||
public JDBC4Connection(String url, String filePath, Properties properties) throws SQLException {
|
||||
this.connection = new LimboConnection(url, filePath, properties);
|
||||
this.connection = new TursoConnection(url, filePath, properties);
|
||||
}
|
||||
|
||||
public LimboStatement prepare(String sql) throws SQLException {
|
||||
public TursoStatement prepare(String sql) throws SQLException {
|
||||
return connection.prepare(sql);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ public final class JDBC4Connection implements Connection {
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
connection.checkOpen();
|
||||
if (holdability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
|
||||
throw new SQLException("Limbo only supports CLOSE_CURSORS_AT_COMMIT");
|
||||
throw new SQLException("turso only supports CLOSE_CURSORS_AT_COMMIT");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ public final class JDBC4Connection implements Connection {
|
||||
public CallableStatement prepareCall(
|
||||
String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
throw new SQLException("Limbo does not support stored procedures");
|
||||
throw new SQLException("turso does not support stored procedures");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
import tech.turso.core.LimboPropertiesHolder;
|
||||
import tech.turso.core.TursoPropertiesHolder;
|
||||
import tech.turso.utils.Logger;
|
||||
import tech.turso.utils.LoggerFactory;
|
||||
|
||||
@@ -18,22 +18,37 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JDBC4DatabaseMetaData.class);
|
||||
|
||||
private final JDBC4Connection connection;
|
||||
|
||||
@Nullable private PreparedStatement getTables = null;
|
||||
|
||||
@Nullable private PreparedStatement getTableTypes = null;
|
||||
|
||||
@Nullable private PreparedStatement getTypeInfo = null;
|
||||
|
||||
@Nullable private PreparedStatement getCatalogs = null;
|
||||
|
||||
@Nullable private PreparedStatement getSchemas = null;
|
||||
|
||||
@Nullable private PreparedStatement getUDTs = null;
|
||||
|
||||
@Nullable private PreparedStatement getColumnsTblName = null;
|
||||
|
||||
@Nullable private PreparedStatement getSuperTypes = null;
|
||||
|
||||
@Nullable private PreparedStatement getSuperTables = null;
|
||||
|
||||
@Nullable private PreparedStatement getTablePrivileges = null;
|
||||
|
||||
@Nullable private PreparedStatement getIndexInfo = null;
|
||||
|
||||
@Nullable private PreparedStatement getProcedures = null;
|
||||
@Nullable private PreparedStatement getProcedureColumns = null;
|
||||
|
||||
@Nullable private PreparedStatement getAttributes = null;
|
||||
|
||||
@Nullable private PreparedStatement getBestRowIdentifier = null;
|
||||
|
||||
@Nullable private PreparedStatement getVersionColumns = null;
|
||||
|
||||
@Nullable private PreparedStatement getColumnPrivileges = null;
|
||||
|
||||
public JDBC4DatabaseMetaData(JDBC4Connection connection) {
|
||||
@@ -88,7 +103,7 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public String getDatabaseProductName() {
|
||||
return "Limbo";
|
||||
return "turso";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,12 +114,12 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public String getDriverName() {
|
||||
return LimboPropertiesHolder.getDriverName();
|
||||
return TursoPropertiesHolder.getDriverName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverVersion() {
|
||||
return LimboPropertiesHolder.getDriverVersion();
|
||||
return TursoPropertiesHolder.getDriverVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,13 +189,13 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public String getSQLKeywords() {
|
||||
// TODO: add more limbo supported keywords
|
||||
return "ABORT,ACTION,AFTER,ANALYZE,ATTACH,AUTOINCREMENT,BEFORE,"
|
||||
// TODO: add more turso supported keywords
|
||||
return ("ABORT,ACTION,AFTER,ANALYZE,ATTACH,AUTOINCREMENT,BEFORE,"
|
||||
+ "CASCADE,CONFLICT,DATABASE,DEFERRABLE,DEFERRED,DESC,DETACH,"
|
||||
+ "EXCLUSIVE,EXPLAIN,FAIL,GLOB,IGNORE,INDEX,INDEXED,INITIALLY,INSTEAD,ISNULL,"
|
||||
+ "KEY,LIMIT,NOTNULL,OFFSET,PLAN,PRAGMA,QUERY,"
|
||||
+ "RAISE,REGEXP,REINDEX,RENAME,REPLACE,RESTRICT,"
|
||||
+ "TEMP,TEMPORARY,TRANSACTION,VACUUM,VIEW,VIRTUAL";
|
||||
+ "TEMP,TEMPORARY,TRANSACTION,VACUUM,VIEW,VIRTUAL");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -318,7 +333,7 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
// DECLARE CURSOR
|
||||
// FETCH
|
||||
// CLOSE CURSOR
|
||||
// TODO: Let's return true when limbo supports them all
|
||||
// TODO: Let's return true when turso supports them all
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -331,7 +346,7 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
// Table expressions (SELECT column FROM (SELECT * FROM table) AS subquery)
|
||||
// Data type support (includes more SQL data types like FLOAT, NUMERIC, DECIMAL)
|
||||
// Basic string functions (e.g., LENGTH(), SUBSTRING(), CONCAT())
|
||||
// TODO: Let's return true when limbo supports them all
|
||||
// TODO: Let's return true when turso supports them all
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -392,7 +407,7 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public boolean isCatalogAtStart() {
|
||||
// sqlite and limbo doesn't use catalog
|
||||
// sqlite and turso doesn't use catalog
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -498,13 +513,13 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public boolean supportsUnion() {
|
||||
// TODO: return true when limbo supports
|
||||
// TODO: return true when turso supports
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsUnionAll() {
|
||||
// TODO: return true when limbo supports
|
||||
// TODO: return true when turso supports
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -635,13 +650,13 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public int getDefaultTransactionIsolation() {
|
||||
// TODO: after limbo introduces Hekaton MVCC, what should we return?
|
||||
// TODO: after turso introduces Hekaton MVCC, what should we return?
|
||||
return Connection.TRANSACTION_SERIALIZABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTransactions() {
|
||||
// TODO: limbo doesn't support transactions fully, let's return true when supported
|
||||
// TODO: turso doesn't support transactions fully, let's return true when supported
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -922,7 +937,7 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public boolean supportsResultSetConcurrency(int type, int concurrency) {
|
||||
return type == ResultSet.TYPE_FORWARD_ONLY && concurrency == ResultSet.CONCUR_READ_ONLY;
|
||||
return (type == ResultSet.TYPE_FORWARD_ONLY && concurrency == ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1001,13 +1016,13 @@ public final class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public boolean supportsSavepoints() {
|
||||
// TODO: return true when limbo supports save points
|
||||
// TODO: return true when turso supports save points
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsNamedParameters() {
|
||||
// TODO: return true when both limbo and jdbc supports named parameters
|
||||
// TODO: return true when both turso and jdbc supports named parameters
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Calendar;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
import tech.turso.core.LimboResultSet;
|
||||
import tech.turso.core.TursoResultSet;
|
||||
|
||||
public final class JDBC4PreparedStatement extends JDBC4Statement implements PreparedStatement {
|
||||
|
||||
@@ -32,7 +32,6 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
|
||||
|
||||
public JDBC4PreparedStatement(JDBC4Connection connection, String sql) throws SQLException {
|
||||
super(connection);
|
||||
|
||||
this.sql = sql;
|
||||
this.statement = connection.prepare(sql);
|
||||
this.statement.initializeColumnMetadata();
|
||||
@@ -48,7 +47,7 @@ public final class JDBC4PreparedStatement extends JDBC4Statement implements Prep
|
||||
@Override
|
||||
public int executeUpdate() throws SQLException {
|
||||
requireNonNull(this.statement);
|
||||
final LimboResultSet resultSet = statement.getResultSet();
|
||||
final TursoResultSet resultSet = statement.getResultSet();
|
||||
resultSet.consumeAll();
|
||||
|
||||
// TODO: return updated count
|
||||
|
||||
@@ -24,13 +24,13 @@ import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
import tech.turso.core.LimboResultSet;
|
||||
import tech.turso.core.TursoResultSet;
|
||||
|
||||
public final class JDBC4ResultSet implements ResultSet, ResultSetMetaData {
|
||||
|
||||
private final LimboResultSet resultSet;
|
||||
private final TursoResultSet resultSet;
|
||||
|
||||
public JDBC4ResultSet(LimboResultSet resultSet) {
|
||||
public JDBC4ResultSet(TursoResultSet resultSet) {
|
||||
this.resultSet = resultSet;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,15 +10,16 @@ import java.sql.Statement;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.annotations.SkipNullableCheck;
|
||||
import tech.turso.core.LimboResultSet;
|
||||
import tech.turso.core.LimboStatement;
|
||||
import tech.turso.core.TursoResultSet;
|
||||
import tech.turso.core.TursoStatement;
|
||||
|
||||
public class JDBC4Statement implements Statement {
|
||||
|
||||
private final JDBC4Connection connection;
|
||||
@Nullable protected LimboStatement statement = null;
|
||||
|
||||
// Because JDBC4Statement has different life cycle in compared to LimboStatement, let's use this
|
||||
@Nullable protected TursoStatement statement = null;
|
||||
|
||||
// Because JDBC4Statement has different life cycle in compared to tursoStatement, let's use this
|
||||
// field to manage JDBC4Statement lifecycle
|
||||
private boolean closed;
|
||||
private boolean closeOnCompletion;
|
||||
@@ -76,7 +77,7 @@ public class JDBC4Statement implements Statement {
|
||||
|
||||
execute(sql);
|
||||
requireNonNull(statement, "statement should not be null after running execute method");
|
||||
final LimboResultSet resultSet = statement.getResultSet();
|
||||
final TursoResultSet resultSet = statement.getResultSet();
|
||||
resultSet.consumeAll();
|
||||
|
||||
return (int) (statement.totalChanges() - previousTotalChanges);
|
||||
|
||||
@@ -3,21 +3,22 @@ package tech.turso.utils;
|
||||
import static tech.turso.utils.ByteArrayUtils.utf8ByteBufferToString;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import tech.turso.LimboErrorCode;
|
||||
import tech.turso.TursoErrorCode;
|
||||
import tech.turso.annotations.Nullable;
|
||||
import tech.turso.exceptions.LimboException;
|
||||
import tech.turso.exceptions.TursoException;
|
||||
|
||||
public final class TursoExceptionUtils {
|
||||
|
||||
public final class LimboExceptionUtils {
|
||||
/**
|
||||
* Throws formatted SQLException with error code and message.
|
||||
*
|
||||
* @param errorCode Error code.
|
||||
* @param errorMessageBytes Error message.
|
||||
*/
|
||||
public static void throwLimboException(int errorCode, byte[] errorMessageBytes)
|
||||
public static void throwTursoException(int errorCode, byte[] errorMessageBytes)
|
||||
throws SQLException {
|
||||
String errorMessage = utf8ByteBufferToString(errorMessageBytes);
|
||||
throw buildLimboException(errorCode, errorMessage);
|
||||
throw buildTursoException(errorCode, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,16 +27,16 @@ public final class LimboExceptionUtils {
|
||||
* @param errorCode Error code.
|
||||
* @param errorMessage Error message.
|
||||
*/
|
||||
public static LimboException buildLimboException(int errorCode, @Nullable String errorMessage)
|
||||
public static TursoException buildTursoException(int errorCode, @Nullable String errorMessage)
|
||||
throws SQLException {
|
||||
LimboErrorCode code = LimboErrorCode.getErrorCode(errorCode);
|
||||
TursoErrorCode code = TursoErrorCode.getErrorCode(errorCode);
|
||||
String msg;
|
||||
if (code == LimboErrorCode.UNKNOWN_ERROR) {
|
||||
if (code == TursoErrorCode.UNKNOWN_ERROR) {
|
||||
msg = String.format("%s:%s (%s)", code, errorCode, errorMessage);
|
||||
} else {
|
||||
msg = String.format("%s (%s)", code, errorMessage);
|
||||
}
|
||||
|
||||
return new LimboException(msg, code);
|
||||
return new TursoException(msg, code);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
driverName=limbo-jdbc
|
||||
driverName=turso-jdbc
|
||||
# find a way to relate driverVersion with project.version defined in gradle.properties
|
||||
driverVersion=0.0.1-SNAPSHOT
|
||||
Reference in New Issue
Block a user