KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > transaction > TransactionManagerLookupFactory


1 //$Id: TransactionManagerLookupFactory.java,v 1.2 2004/09/07 02:14:43 oneovthafew Exp $
2
package org.hibernate.transaction;
3
4 import java.util.Properties JavaDoc;
5
6 import javax.transaction.TransactionManager JavaDoc;
7
8 import org.apache.commons.logging.Log;
9 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.getLog(TransactionManagerLookupFactory.class);
21
22     private TransactionManagerLookupFactory() {}
23
24     public static final TransactionManager JavaDoc getTransactionManager(Properties JavaDoc props) throws HibernateException {
25         log.info("obtaining TransactionManager");
26         return getTransactionManagerLookup(props).getTransactionManager(props);
27     }
28
29     public static final TransactionManagerLookup getTransactionManagerLookup(Properties JavaDoc props) throws HibernateException {
30
31         String JavaDoc tmLookupClass = props.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY);
32         if (tmLookupClass==null) {
33             log.info("No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)");
34             return null;
35         }
36         else {
37
38             log.info("instantiating TransactionManagerLookup: " + tmLookupClass);
39
40             try {
41                 TransactionManagerLookup lookup = (TransactionManagerLookup) ReflectHelper.classForName(tmLookupClass).newInstance();
42                 log.info("instantiated TransactionManagerLookup");
43                 return lookup;
44             }
45             catch (Exception JavaDoc e) {
46                 log.error("Could not instantiate TransactionManagerLookup", e);
47                 throw new HibernateException("Could not instantiate TransactionManagerLookup");
48             }
49         }
50     }
51 }
52
Popular Tags