Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
// Unchecked exceptions for invalid stateif (dataSource == null) {
thrownewIllegalStateException("DataSource not initialized");
}
// Try-with-resources for all closeable resourcestry (finalvarconn= dataSource.getConnection();
finalvarstmt= conn.prepareStatement(sql);
finalvarrs= stmt.executeQuery()) {
while (rs.next()) {
// Process results
}
} catch (final SQLException e) {
thrownewIllegalStateException("Database error", e);
}
// Interrupt handlingtry {
Thread.sleep(duration.toMillis());
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
// Exception chainingthrownewIllegalStateException("Failed to process batch", e);
Logging
privatestaticfinalLoggerLOGGER= LoggerFactory.getLogger(BybitStreamService.class);
// Info with context
LOGGER.info("Save {} spot 1m klines (tx) and updated offset {}", count, maxOffset);
// Warn with exception
LOGGER.warn("Error closing stream consumer", ex);
// Error with context and exception
LOGGER.error("Failed to process message from {}", streamName, exception);
// Startup/shutdown
LOGGER.info("StreamService started");
Database Patterns
Batch Insert with Transaction
publicintsaveKline1m(final List<Map<String, Object>> klines, finallong offset)throws SQLException {
finalvarsql="INSERT INTO crypto_scout.bybit_spot_kline_1m (...) VALUES (...)" +
" ON CONFLICT (...) DO UPDATE SET ...";
try (finalvarconn= dataSource.getConnection()) {
conn.setAutoCommit(false);
try (finalvarstmt= conn.prepareStatement(sql)) {
for (finalvar kline : klines) {
stmt.setString(1, (String) kline.get("symbol"));
// ... set parameters
stmt.addBatch();
}
finalvarresults= stmt.executeBatch();
// Update offset in same transaction
upsertOffset(conn, stream, offset);
conn.commit();
return Arrays.stream(results).sum();
} catch (final SQLException e) {
conn.rollback();
throw e;
}
}
}
Query with Mapping
public List<Map<String, Object>> getKline1m(final String symbol, final OffsetDateTime from,
final OffsetDateTime to)throws SQLException {
finalvarsql="SELECT * FROM crypto_scout.bybit_spot_kline_1m " +
"WHERE symbol = ? AND open_time BETWEEN ? AND ? ORDER BY open_time";
finalvarresults=newArrayList<Map<String, Object>>();
try (finalvarconn= dataSource.getConnection();
finalvarstmt= conn.prepareStatement(sql)) {
stmt.setString(1, symbol);
stmt.setObject(2, from);
stmt.setObject(3, to);
try (finalvarrs= stmt.executeQuery()) {
while (rs.next()) {
finalvarrow=newHashMap<String, Object>();
row.put("symbol", rs.getString("symbol"));
row.put("open_time", rs.getObject("open_time", OffsetDateTime.class));
// ... map columns
results.add(row);
}
}
}
return results;
}