/* * 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.util.ArrayList; import java.util.List; import javax.transaction.UserTransaction; import org.wamblee.general.ThreadSpecificProxyFactory; import org.wamblee.general.ThreadSpecificProxyFactory.CreationCallback; import org.wamblee.test.persistence.JpaBuilder; /** * *
* Simple transaction manager provides a simple mechanism to manage transactions * in test code through the {@link UserTransaction} object. To construct the * transaction manager use: *
* ** SimpleTransactionManager manager = new SimpleTransactionManager( * new DefaultUserTransactionFactory()); ** *
* Next, add resources to manage using {@link #addResource(TransactionResource)}: * *
* manager.addResource(jpaTester.getJpaBuilder()); **
* As you can see from the above, {@link JpaBuilder} is a resource that can be * used so this mechanism can be used with JPA testing. *
* *
* The next step is to manage transactions using the standard
* UserTransaction
APIs:
*
* UserTransaction transaction = manager.getTransaction(); * transaction.begin(); * * ... do work... * * transaction.commit(); ** * @author Erik Brakkee * */ public class SimpleTransactionManager { private UserTransactionFactory factory; private List