1 package org.hibernate.transaction; 3 4 import java.util.Properties ; 5 6 import javax.transaction.TransactionManager ; 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 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 getTransactionManager(Properties props) throws HibernateException { 25 log.info("obtaining TransactionManager"); 26 return getTransactionManagerLookup(props).getTransactionManager(props); 27 } 28 29 public static final TransactionManagerLookup getTransactionManagerLookup(Properties props) throws HibernateException { 30 31 String 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 e) { 46 log.error("Could not instantiate TransactionManagerLookup", e); 47 throw new HibernateException("Could not instantiate TransactionManagerLookup"); 48 } 49 } 50 } 51 } 52 | Popular Tags |