01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.ojb;
17:
18: import javax.transaction.TransactionManager;
19:
20: import org.apache.ojb.broker.transaction.tm.TransactionManagerFactoryException;
21: import org.kuali.rice.exceptions.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.database.WorkflowTransactionManagerFactory
45: * </code>
46: * </blockquote>
47: *
48: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
49: */
50: public class TransactionManagerFactory implements
51: org.apache.ojb.broker.transaction.tm.TransactionManagerFactory {
52:
53: private static TransactionManager transactionManager;
54:
55: public TransactionManager getTransactionManager()
56: throws TransactionManagerFactoryException {
57: // return SpringServiceLocator.getJtaTransactionManager().getTransactionManager();
58: if (transactionManager == null) {
59: throw new RiceRuntimeException(
60: "The JTA Transaction Manager for OJB was not configured properly.");
61: }
62: return transactionManager;
63: // core and plugins
64: // TODO what to do here
65: //return KSBServiceLocator.getTransactionManager();
66: }
67:
68: public static void setTransactionManager(
69: TransactionManager transactionManager) {
70: TransactionManagerFactory.transactionManager = transactionManager;
71: }
72:
73: }
|