package io.trygvis.queue; import io.trygvis.async.JdbcAsyncService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; public class QueueSystem { private final Logger log = LoggerFactory.getLogger(getClass()); public final SqlEffectExecutor sqlEffectExecutor; private final JdbcQueueService queueService; private QueueSystem(SqlEffectExecutor sqlEffectExecutor) throws SQLException { sqlEffectExecutor.transaction(new SqlEffect.Void() { @Override public void doInConnection(Connection c) throws SQLException { if (c.getAutoCommit()) { throw new SQLException("The connection cannot be in auto-commit mode."); } DatabaseMetaData metaData = c.getMetaData(); String productName = metaData.getDatabaseProductName(); String productVersion = metaData.getDatabaseProductVersion(); log.info("productName = " + productName); log.info("productVersion = " + productVersion); } }); this.sqlEffectExecutor = sqlEffectExecutor; queueService = new JdbcQueueService(this); } /** * Initializes the queue system. Use this as the first thing do as it will validate the database. */ public static QueueSystem initialize(SqlEffectExecutor sqlEffectExecutor) throws SQLException { return new QueueSystem(sqlEffectExecutor); } public JdbcQueueService createQueueService() { return queueService; } public QueueDao createQueueDao(Connection c) { return new QueueDao(c); } public TaskDao createTaskDao(Connection c) { return new TaskDao(c); } public JdbcAsyncService createAsyncService() { return new JdbcAsyncService(this); } }