1 /*
2 * (C) Copyright 1989-2012 Trend Micro, Inc.
3 * All Rights Reserved.
4 *
5 * This program is an unpublished copyrighted work which is proprietary
6 * to Trend Micro, Inc. and contains confidential information that is not
7 * to be reproduced or disclosed to any other person or entity without
8 * prior written consent from Trend Micro, Inc. in each and every instance.
9 *
10 * WARNING: Unauthorized reproduction of this program as well as
11 * unauthorized preparation of derivative works based upon the
12 * program or distribution of copies by sale, rental, lease or
13 * lending are violations of federal copyright laws and state trade
14 * secret laws, punishable by civil and criminal penalties.
15 */
16 package org.hibernate.transaction;
17
18 import java.util.Properties;
19
20 import javax.transaction.TransactionManager;
21 import javax.transaction.Transaction;
22
23 import org.hibernate.HibernateException;
24
25 /**
26 * TransactionManager lookup strategy for BTM
27 *
28 * @author Ludovic Orban
29 */
30 public class BTMTransactionManagerLookup implements TransactionManagerLookup {
31
32 /**
33 * {@inheritDoc}
34 */
35 public TransactionManager getTransactionManager(Properties props) throws HibernateException {
36 try {
37 Class clazz = Class.forName("bitronix.tm.TransactionManagerServices");
38 return (TransactionManager) clazz.getMethod("getTransactionManager", null).invoke(null, null);
39 }
40 catch (Exception e) {
41 throw new HibernateException( "Could not obtain BTM transaction manager instance", e );
42 }
43 }
44
45 /**
46 * {@inheritDoc}
47 */
48 public String getUserTransactionName() {
49 return "java:comp/UserTransaction";
50 }
51
52 /**
53 * {@inheritDoc}
54 */
55 public Object getTransactionIdentifier(Transaction transaction) {
56 return transaction;
57 }
58 }