Исправить стартовый bootstrap DM

This commit is contained in:
AidarKC
2026-08-22 20:13:14 +04:00
parent 7a5ac01d1c
commit da14b51e80
2 changed files with 19 additions and 8 deletions
@@ -1,6 +1,7 @@
package shine.db;
import shine.db.connection.DbProvider;
import shine.db.dao.DmDialogStateDAO;
import java.sql.Connection;
import java.sql.SQLException;
@@ -15,6 +16,7 @@ public final class DbController implements DbProvider {
private static volatile DbController instance;
private final PostgresDbController delegate;
private volatile boolean dmDialogStateBootstrapped;
private DbController() {
this.delegate = PostgresDbController.getInstance();
@@ -24,7 +26,9 @@ public final class DbController implements DbProvider {
if (instance == null) {
synchronized (DbController.class) {
if (instance == null) {
instance = new DbController();
DbController created = new DbController();
instance = created;
created.bootstrapDmDialogStateIfNeeded();
}
}
}
@@ -40,4 +44,18 @@ public final class DbController implements DbProvider {
public void close() {
delegate.close();
}
private void bootstrapDmDialogStateIfNeeded() {
if (dmDialogStateBootstrapped) return;
synchronized (this) {
if (dmDialogStateBootstrapped) return;
try (Connection connection = delegate.getConnection()) {
DmDialogStateDAO.getInstance().bootstrapIfEmpty(connection);
dmDialogStateBootstrapped = true;
} catch (SQLException e) {
instance = null;
throw new RuntimeException("DM dialog state bootstrap failed", e);
}
}
}
}
@@ -1,7 +1,6 @@
package shine.db;
import shine.db.connection.DriverManagerDbProvider;
import shine.db.dao.DmDialogStateDAO;
import utils.config.AppConfig;
import java.sql.Connection;
@@ -35,12 +34,6 @@ public final class PostgresDbController {
this.delegate = new DriverManagerDbProvider(jdbcUrl, dbUser, dbPassword, connection -> {
connection.setAutoCommit(true);
});
try (Connection connection = this.delegate.getConnection()) {
DmDialogStateDAO.getInstance().bootstrapIfEmpty(connection);
} catch (SQLException e) {
throw new RuntimeException("DM dialog state bootstrap failed", e);
}
}
public static PostgresDbController getInstance() {