001/**
002 * Copyright 2005-2016 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.core.framework.persistence.ojb;
017
018import javax.transaction.TransactionManager;
019
020import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
021import org.kuali.rice.core.api.exception.RiceRuntimeException;
022
023/**
024 * <p>An implementation of an OJB TransactionManagerFactory which provides access to Workflow's
025 * JTA UserTransaction.</p>
026 *
027 * <p>If the TransactionManager singleton has been set via {@link #setTransactionManager(TransactionManager)}
028 * then that reference is returned, otherwise the TransactionManager is pulled from Workflow's Spring core
029 * via the SpringServiceLocator.</p>
030 *
031 * <p>When accessed from outside the workflow core (i.e. embedded mode), the transaction manager
032 * singleton MUST explicitly be set - it cannot be resolved through the SpringServiceLocator.</p>
033 *
034 * <p>Note: if OJB is caused to initialize DURING Spring initialization (for example, by programmatically
035 * obtaining the OJB PersistenceBrokerFactory to set the platform attribute of connection descriptors
036 * from within a bean initialized by Spring), the TransactionManager singleton MUST be set beforehand,
037 * otherwise NPE will result from attempting to traverse SpringServiceLocator as the GlobalResourceLoader
038 * will not have been initialized yet).</p>
039 *
040 * <p>This TransactionManagerFactory implementation is specified in OJB via the following
041 * setting the OJB properties:</p>
042 * <blockquote>
043 *   <code>
044 *     JTATransactionManagerClass=org.kuali.rice.core.database.WorkflowTransactionManagerFactory
045 *   </code>
046 * </blockquote>
047 *
048 * @author Kuali Rice Team (rice.collab@kuali.org)
049 */
050@Deprecated
051public class TransactionManagerFactory implements org.apache.ojb.broker.transaction.tm.TransactionManagerFactory {
052
053        private static TransactionManager transactionManager;
054
055        public TransactionManager getTransactionManager() throws TransactionManagerFactoryException {
056            // return SpringServiceLocator.getJtaTransactionManager().getTransactionManager();
057                if (transactionManager == null) {
058                        throw new RiceRuntimeException("The JTA Transaction Manager for OJB was not configured properly.");
059                }
060                return transactionManager;
061                // core and plugins
062                // TODO what to do here
063        //return KSBServiceLocator.getTransactionManager();
064        }
065
066        public static void setTransactionManager(TransactionManager transactionManager) {
067                TransactionManagerFactory.transactionManager = transactionManager;
068        }
069
070}