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.tynamo.jpa;
016    
017    /**
018     * Service that can create an interceptor that wraps around a service implementation. After invoking
019     * service methods marked by {@link org.apache.tapestry5.jpa.annotations.CommitAfter} the current
020     * transaction is committed. Declared exceptions will also
021     * {@linkplain org.apache.tapestry5.jpa.JPATransationManager#commit() commit the transaction};
022     * runtime exceptions will {@linkplain org.apache.tapestry5.hibernate.JPATransationManager#abort()
023     * the transaction}.
024     * <p/>
025     * It is recommended that you switch from the use of decoration to the use of advice; use the
026     * {@link org.apache.tapestry5.hibernate.JPATransactionAdvisor} (from a service advisor method)
027     * instead.
028     */
029    public interface JPATransactionDecorator
030    {
031            /**
032             * Builds a transaction interceptor instance around the delegate.
033             * 
034             * @param <T>
035             * @param serviceInterface
036             *            interface implemented by the delegate
037             * @param delegate
038             *            existing object to be wrapped
039             * @param serviceId
040             *            id of service
041             * @return a new object implementing the interface that can be used in place of the delegate,
042             *         providing transactional behavior
043             */
044            <T> T build(Class<T> serviceInterface, T delegate, String serviceId);
045    }