1 package org.hibernate.transaction; 2 3 import java.util.Properties ; 4 5 import org.apache.commons.logging.Log; 6 import org.apache.commons.logging.LogFactory; 7 8 import org.hibernate.HibernateException; 9 import org.hibernate.cfg.Environment; 10 import org.hibernate.util.ReflectHelper; 11 12 15 public final class TransactionFactoryFactory { 16 17 private static final Log log = LogFactory.getLog(TransactionFactoryFactory.class); 18 19 27 public static TransactionFactory buildTransactionFactory(Properties transactionProps) throws HibernateException { 28 29 String strategyClassName = transactionProps.getProperty(Environment.TRANSACTION_STRATEGY); 30 if (strategyClassName==null) { 31 log.info("Using default transaction strategy (direct JDBC transactions)"); 32 return new JDBCTransactionFactory(); 33 } 34 log.info("Transaction strategy: " + strategyClassName); 35 TransactionFactory factory; 36 try { 37 factory = (TransactionFactory) ReflectHelper.classForName(strategyClassName).newInstance(); 38 } 39 catch (ClassNotFoundException e) { 40 log.error("TransactionFactory class not found", e); 41 throw new HibernateException("TransactionFactory class not found: " + strategyClassName); 42 } 43 catch (IllegalAccessException e) { 44 log.error("Failed to instantiate TransactionFactory", e); 45 throw new HibernateException("Failed to instantiate TransactionFactory: " + e); 46 } 47 catch (java.lang.InstantiationException e) { 48 log.error("Failed to instantiate TransactionFactory", e); 49 throw new HibernateException("Failed to instantiate TransactionFactory: " + e); 50 } 51 factory.configure(transactionProps); 52 return factory; 53 } 54 55 private TransactionFactoryFactory() {} 56 } 57 | Popular Tags |