/* * Copyright 2005-2010 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.test.transactions; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.logging.Level; import javax.persistence.EntityManager; import org.wamblee.general.ThreadSpecificProxyFactory; import org.wamblee.test.persistence.JpaBuilder; import org.wamblee.test.persistence.LoggingTransactionResultCallback; import org.wamblee.test.persistence.JpaBuilder.JpaUnitOfWork; /** * This utility makes sure that each invocation on a certain interface is * carried out within a JPA unit of work. Note that this is equivalent * to the sementics of a requiresNew transaction attribute. * * Use {@link #getTransactionScopedEntityManager()} to get the transaction * scoped entity manager to pass to services. * * * For example: *
* JpaBuilder builder = ... * TransactionProxyFactory* The above example executes the executeMethod() call on the service object within an active transaction. * In the constructor of the service a transaction scoped entity manager is passed. * * @param T * Type of interface to proxy. * * @author Erik Brakkee */ public class TransactionProxyFactoryfactory = new TransactionProxyFactory ( * builder, Service.class); * Service service = new JpaService(factory.getTransactionScopedEntityManager()); * Service proxy = factory.getProxy(service); * proxy.executeMethod(...); *