KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.hibernate.transaction;
2
3 import java.util.Properties JavaDoc;
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 /**
13  * @author Gavin King
14  */

15 public final class TransactionFactoryFactory {
16
17     private static final Log log = LogFactory.getLog(TransactionFactoryFactory.class);
18
19     /**
20      * Obtain a TransactionFactory with the transaction handling strategy
21      * specified by the given Properties.
22      *
23      * @param transactionProps transaction properties
24      * @return TransactionFactory
25      * @throws HibernateException
26      */

27     public static TransactionFactory buildTransactionFactory(Properties JavaDoc transactionProps) throws HibernateException {
28
29         String JavaDoc 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 JavaDoc e) {
40             log.error("TransactionFactory class not found", e);
41             throw new HibernateException("TransactionFactory class not found: " + strategyClassName);
42         }
43         catch (IllegalAccessException JavaDoc e) {
44             log.error("Failed to instantiate TransactionFactory", e);
45             throw new HibernateException("Failed to instantiate TransactionFactory: " + e);
46         }
47         catch (java.lang.InstantiationException JavaDoc 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