Добавить ListBlockchainHeads для межсерверной сверки

This commit is contained in:
AidarKC
2026-06-25 17:52:04 +04:00
parent f0e1ab3af8
commit 1f8b20a7d1
8 changed files with 229 additions and 8 deletions
@@ -4,6 +4,8 @@ import shine.db.SqliteDbController;
import shine.db.entities.BlockchainStateEntry;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public final class BlockchainStateDAO {
@@ -53,6 +55,39 @@ public final class BlockchainStateDAO {
}
}
/** Получить все blockchain_state записи. */
public List<BlockchainStateEntry> listAll() throws SQLException {
try (Connection c = db.getConnection()) {
return listAll(c);
}
}
/** Получить все blockchain_state записи с внешним соединением. Соединение НЕ закрывает. */
public List<BlockchainStateEntry> listAll(Connection c) throws SQLException {
String sql = """
SELECT
blockchain_name,
login,
blockchain_key,
size_limit,
file_size_bytes,
last_block_number,
last_block_hash,
updated_at_ms
FROM blockchain_state
ORDER BY blockchain_name COLLATE NOCASE
""";
List<BlockchainStateEntry> result = new ArrayList<>();
try (PreparedStatement ps = c.prepareStatement(sql);
ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
result.add(mapRow(rs));
}
}
return result;
}
/** UPSERT без внешнего соединения. Сам открывает/закрывает. */
public void upsert(BlockchainStateEntry e) throws SQLException {
try (Connection c = db.getConnection()) {
@@ -150,4 +185,4 @@ public final class BlockchainStateDAO {
}
private static String nn(String s) { return s == null ? "" : s; }
}
}