call TursoDB::open from constructor

This commit is contained in:
Mikaël Francoeur
2025-07-17 10:12:04 -04:00
parent 434d1c60be
commit 8fe4f2163c
3 changed files with 5 additions and 35 deletions

View File

@@ -185,9 +185,10 @@ public final class TursoDB implements AutoCloseable {
}
// TODO: receive config as argument
private TursoDB(String url, String filePath) {
private TursoDB(String url, String filePath) throws SQLException {
this.url = url;
this.filePath = filePath;
open(0);
}
// TODO: add support for JNI
@@ -201,16 +202,11 @@ public final class TursoDB implements AutoCloseable {
return this.isOpen;
}
public void open(int openFlags) throws SQLException {
private void open(int openFlags) throws SQLException {
open0(filePath, openFlags);
}
private void open0(String filePath, int openFlags) throws SQLException {
if (isOpen) {
throw TursoExceptionUtils.buildTursoException(
TursoErrorCode.TURSO_ETC.code, "Already opened");
}
byte[] filePathBytes = stringToUtf8ByteArray(filePath);
if (filePathBytes == null) {
throw TursoExceptionUtils.buildTursoException(

View File

@@ -37,13 +37,7 @@ public final class TursoDBFactory {
try {
return databaseHolder.computeIfAbsent(
url,
(Sneaky<String, TursoDB, SQLException>)
u -> {
TursoDB tursoDB = TursoDB.create(u, filePath);
tursoDB.open(0);
return tursoDB;
});
url, (Sneaky<String, TursoDB, SQLException>) u -> TursoDB.create(u, filePath));
} catch (Exception e) {
throw new SQLException("Error opening connection", e);
}