| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TransactionManagerFactory |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * Copyright 2007 The Kuali Foundation | |
| 3 | * | |
| 4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.opensource.org/licenses/ecl2.php | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.kuali.rice.core.ojb; | |
| 17 | ||
| 18 | import javax.transaction.TransactionManager; | |
| 19 | ||
| 20 | import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException; | |
| 21 | import org.kuali.rice.core.exception.RiceRuntimeException; | |
| 22 | ||
| 23 | /** | |
| 24 | * <p>An implementation of an OJB TransactionManagerFactory which provides access to Workflow's | |
| 25 | * JTA UserTransaction.</p> | |
| 26 | * | |
| 27 | * <p>If the TransactionManager singleton has been set via {@link #setTransactionManager(TransactionManager)} | |
| 28 | * then that reference is returned, otherwise the TransactionManager is pulled from Workflow's Spring core | |
| 29 | * via the SpringServiceLocator.</p> | |
| 30 | * | |
| 31 | * <p>When accessed from outside the workflow core (i.e. embedded mode), the transaction manager | |
| 32 | * singleton MUST explicitly be set - it cannot be resolved through the SpringServiceLocator.</p> | |
| 33 | * | |
| 34 | * <p>Note: if OJB is caused to initialize DURING Spring initialization (for example, by programmatically | |
| 35 | * obtaining the OJB PersistenceBrokerFactory to set the platform attribute of connection descriptors | |
| 36 | * from within a bean initialized by Spring), the TransactionManager singleton MUST be set beforehand, | |
| 37 | * otherwise NPE will result from attempting to traverse SpringServiceLocator as the GlobalResourceLoader | |
| 38 | * will not have been initialized yet).</p> | |
| 39 | * | |
| 40 | * <p>This TransactionManagerFactory implementation is specified in OJB via the following | |
| 41 | * setting the OJB properties:</p> | |
| 42 | * <blockquote> | |
| 43 | * <code> | |
| 44 | * JTATransactionManagerClass=org.kuali.rice.core.database.WorkflowTransactionManagerFactory | |
| 45 | * </code> | |
| 46 | * </blockquote> | |
| 47 | * | |
| 48 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 49 | */ | |
| 50 | 0 | public class TransactionManagerFactory implements org.apache.ojb.broker.transaction.tm.TransactionManagerFactory { |
| 51 | ||
| 52 | private static TransactionManager transactionManager; | |
| 53 | ||
| 54 | public TransactionManager getTransactionManager() throws TransactionManagerFactoryException { | |
| 55 | // return SpringServiceLocator.getJtaTransactionManager().getTransactionManager(); | |
| 56 | 0 | if (transactionManager == null) { |
| 57 | 0 | throw new RiceRuntimeException("The JTA Transaction Manager for OJB was not configured properly."); |
| 58 | } | |
| 59 | 0 | return transactionManager; |
| 60 | // core and plugins | |
| 61 | // TODO what to do here | |
| 62 | //return KSBServiceLocator.getTransactionManager(); | |
| 63 | } | |
| 64 | ||
| 65 | public static void setTransactionManager(TransactionManager transactionManager) { | |
| 66 | 0 | TransactionManagerFactory.transactionManager = transactionManager; |
| 67 | 0 | } |
| 68 | ||
| 69 | } |