package lc.sips.jdbc;

import lc.mecha.log.MechaLogger;
import lc.mecha.log.MechaLoggerFactory;
import lc.sips.Transaction;
import lc.sips.schema.Table;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * An implementation of {@link Transaction} backed by JDBC.
 *
 * @author Alex Leigh
 * @since 1.0
 */
public class JDBCTransaction implements Transaction {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(JDBCTransaction.class);
    private final Connection connection;
    private final Dialect dialect;

    public JDBCTransaction(Connection connection, Dialect dialect) {
        this.connection = connection;
        this.dialect = dialect;
    }

    @Override
    public void deleteTable(Table t) throws SQLException {
        for (var query : dialect.createTableDrop(t)) {
            try (var ps = connection.prepareStatement(query)) {
                ps.execute();
            }
        }
    }

    @Override
    public void putTable(Table t) throws SQLException {
        for (var query : dialect.createTableQuery(t)) {
            try (var ps = connection.prepareStatement(query)) {
                ps.execute();
            }
        }
    }

    @Override
    public void select(Table t) throws Exception {

    }
}