Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
JotmTransactionManagerFactory |
|
| 2.0;2 |
1 | /* | |
2 | * $Id: JotmTransactionManagerFactory.java 7963 2007-08-21 08:53:15Z dirk.olmes $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.extras.jotm; | |
12 | ||
13 | import org.mule.umo.manager.UMOTransactionManagerFactory; | |
14 | ||
15 | import javax.transaction.TransactionManager; | |
16 | ||
17 | import org.objectweb.jotm.Current; | |
18 | import org.objectweb.jotm.Jotm; | |
19 | ||
20 | /** | |
21 | * This factory retrieves the transaction manager for <a | |
22 | * href="http://jotm.objectweb.org">JOTM </a>. If an existing JOTM instance exists | |
23 | * (for example if running on JOnAS) it will retrieve it, else if will create a new | |
24 | * local JOTM instance. | |
25 | */ | |
26 | public class JotmTransactionManagerFactory implements UMOTransactionManagerFactory | |
27 | { | |
28 | private TransactionManager jotmCurrent; | |
29 | ||
30 | public JotmTransactionManagerFactory() | |
31 | { | |
32 | 0 | super(); |
33 | 0 | } |
34 | ||
35 | /** | |
36 | * Retrieves the JOTM Current object that implements the TransactionManager | |
37 | * interface. | |
38 | * | |
39 | * @see org.mule.umo.manager.UMOTransactionManagerFactory#create() | |
40 | */ | |
41 | public synchronized TransactionManager create() throws Exception | |
42 | { | |
43 | 0 | if (jotmCurrent == null) |
44 | { | |
45 | // check for already active JOTM instance | |
46 | 0 | jotmCurrent = Current.getCurrent(); |
47 | // if none found, create new local JOTM instance | |
48 | 0 | if (jotmCurrent == null) |
49 | { | |
50 | 0 | jotmCurrent = new Jotm(true, false).getTransactionManager(); |
51 | } | |
52 | } | |
53 | 0 | return jotmCurrent; |
54 | } | |
55 | ||
56 | } |