001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc.sql;
019
020import java.sql.Connection;
021import java.sql.SQLException;
022
023import net.sf.hajdbc.Database;
024import net.sf.hajdbc.durability.Durability;
025import net.sf.hajdbc.invocation.InvocationStrategy;
026import net.sf.hajdbc.invocation.Invoker;
027
028/**
029 * Decorates an invocation strategy with transaction boundary logic.
030 * @author Paul Ferraro
031 * @param <Z>
032 * @param <D>
033 */
034public interface TransactionContext<Z, D extends Database<Z>>
035{
036        /**
037         * Decorates the specified invocation strategy with start transaction logic.
038         * @param strategy
039         * @param connection
040         * @return the decorated invocation strategy
041         * @throws SQLException
042         */
043        InvocationStrategy start(InvocationStrategy strategy, Connection connection) throws SQLException;
044
045        /**
046         * Decorates the specified invoker with start transaction logic.
047         * @param <T>
048         * @param <R>
049         * @param invoker
050         * @param connection
051         * @return the decorated invoker
052         * @throws SQLException
053         */
054        <T, R> Invoker<Z, D, T, R, SQLException> start(Invoker<Z, D, T, R, SQLException> invoker, Connection connection) throws SQLException;
055
056        /**
057         * Decorates the specified invocation strategy with end transaction logic.
058         * @param strategy
059         * @param phase
060         * @return the decorated invocation strategy
061         * @throws SQLException
062         */
063        InvocationStrategy end(InvocationStrategy strategy, Durability.Phase phase) throws SQLException;
064
065        /**
066         * Decorates the specified invok with end transaction logic.
067         * @param <T>
068         * @param <R>
069         * @param invoker
070         * @param phase
071         * @return the decorated invoker
072         * @throws SQLException
073         */
074        <T, R> Invoker<Z, D, T, R, SQLException> end(Invoker<Z, D, T, R, SQLException> invoker, Durability.Phase phase) throws SQLException;
075        
076        /**
077         * Closes this transaction context.
078         */
079        void close();
080}