01: package org.hibernate.transaction;
02:
03: import java.util.Properties;
04:
05: import org.apache.commons.logging.Log;
06: import org.apache.commons.logging.LogFactory;
07:
08: import org.hibernate.HibernateException;
09: import org.hibernate.cfg.Environment;
10: import org.hibernate.util.ReflectHelper;
11:
12: /**
13: * @author Gavin King
14: */
15: public final class TransactionFactoryFactory {
16:
17: private static final Log log = LogFactory
18: .getLog(TransactionFactoryFactory.class);
19:
20: /**
21: * Obtain a TransactionFactory with the transaction handling strategy
22: * specified by the given Properties.
23: *
24: * @param transactionProps transaction properties
25: * @return TransactionFactory
26: * @throws HibernateException
27: */
28: public static TransactionFactory buildTransactionFactory(
29: Properties transactionProps) throws HibernateException {
30:
31: String strategyClassName = transactionProps
32: .getProperty(Environment.TRANSACTION_STRATEGY);
33: if (strategyClassName == null) {
34: log
35: .info("Using default transaction strategy (direct JDBC transactions)");
36: return new JDBCTransactionFactory();
37: }
38: log.info("Transaction strategy: " + strategyClassName);
39: TransactionFactory factory;
40: try {
41: factory = (TransactionFactory) ReflectHelper.classForName(
42: strategyClassName).newInstance();
43: } catch (ClassNotFoundException e) {
44: log.error("TransactionFactory class not found", e);
45: throw new HibernateException(
46: "TransactionFactory class not found: "
47: + strategyClassName);
48: } catch (IllegalAccessException e) {
49: log.error("Failed to instantiate TransactionFactory", e);
50: throw new HibernateException(
51: "Failed to instantiate TransactionFactory: " + e);
52: } catch (java.lang.InstantiationException e) {
53: log.error("Failed to instantiate TransactionFactory", e);
54: throw new HibernateException(
55: "Failed to instantiate TransactionFactory: " + e);
56: }
57: factory.configure(transactionProps);
58: return factory;
59: }
60:
61: private TransactionFactoryFactory() {
62: }
63: }
|