    001    // Copyright 2008, 2009 The Apache Software Foundation
    002    //
    003    // Licensed under the Apache License, Version 2.0 (the "License");
    004    // you may not use this file except in compliance with the License.
    005    // You may obtain a copy of the License at
    006    //
    007    //     http://www.apache.org/licenses/LICENSE-2.0
    008    //
    009    // Unless required by applicable law or agreed to in writing, software
    010    // distributed under the License is distributed on an "AS IS" BASIS,
    011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    012    // See the License for the specific language governing permissions and
    013    // limitations under the License.
    014
    015    package org.apache.tapestry5.hibernate;
    016
    017    /**
    018     * Service that can create an interceptor that wraps around a service implementation. After invoking service methods
    019     * marked by {@link org.apache.tapestry5.hibernate.annotations.CommitAfter} the current transaction is committed.
    020     * Declared exceptions will also {@linkplain org.apache.tapestry5.hibernate.HibernateSessionManager#commit() commit the
    021     * transaction}; runtime exceptions will {@linkplain org.apache.tapestry5.hibernate.HibernateSessionManager#abort() the
    022     * transaction}.
    023     * <p/>
    024     * It is recommended that you switch from the use of decoration to the use of advice; use the {@link
    025     * org.apache.tapestry5.hibernate.HibernateTransactionAdvisor} (from a service advisor method) instead.
    026     */
    027    public interface HibernateTransactionDecorator
    028    {
    029        /**
    030         * Builds a transaction interceptor instance around the delegate.
    031         *
    032         * @param <T>
    033         * @param serviceInterface interface implemented by the delegate
    034         * @param delegate         existing object to be wrapped
    035         * @param serviceId        id of service
    036         * @return a new object implementing the interface that can be used in place of the delegate, providing
    037         *         transactional behavior
    038         */
    039        <T> T build(Class<T> serviceInterface, T delegate, String serviceId);
    040    }