01: //$Id: TransactionManagerLookupFactory.java 11406 2007-04-15 12:52:46Z max.andersen@jboss.com $
02: package org.hibernate.transaction;
03:
04: import java.util.Properties;
05:
06: import javax.transaction.TransactionManager;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10:
11: import org.hibernate.HibernateException;
12: import org.hibernate.cfg.Environment;
13: import org.hibernate.util.ReflectHelper;
14:
15: /**
16: * @author Gavin King
17: */
18: public final class TransactionManagerLookupFactory {
19:
20: private static final Log log = LogFactory
21: .getLog(TransactionManagerLookupFactory.class);
22:
23: private TransactionManagerLookupFactory() {
24: }
25:
26: public static final TransactionManager getTransactionManager(
27: Properties props) throws HibernateException {
28: log.info("obtaining TransactionManager");
29: return getTransactionManagerLookup(props)
30: .getTransactionManager(props);
31: }
32:
33: public static final TransactionManagerLookup getTransactionManagerLookup(
34: Properties props) throws HibernateException {
35:
36: String tmLookupClass = props
37: .getProperty(Environment.TRANSACTION_MANAGER_STRATEGY);
38: if (tmLookupClass == null) {
39: log
40: .info("No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)");
41: return null;
42: } else {
43:
44: log.info("instantiating TransactionManagerLookup: "
45: + tmLookupClass);
46:
47: try {
48: TransactionManagerLookup lookup = (TransactionManagerLookup) ReflectHelper
49: .classForName(tmLookupClass).newInstance();
50: log.info("instantiated TransactionManagerLookup");
51: return lookup;
52: } catch (Exception e) {
53: log
54: .error(
55: "Could not instantiate TransactionManagerLookup",
56: e);
57: throw new HibernateException(
58: "Could not instantiate TransactionManagerLookup '"
59: + tmLookupClass + "'");
60: }
61: }
62: }
63: }
|