KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > transaction > HibernateTransactionFactory


1 /*
2  * Shark Hibernate TransactionManager - Open Wide
3  */

4
5 package org.enhydra.shark.transaction;
6
7 import org.enhydra.shark.api.RootException;
8 import org.enhydra.shark.api.SharkTransaction;
9 import org.enhydra.shark.api.TransactionException;
10 import org.enhydra.shark.api.internal.transaction.TransactionFactory;
11 import org.enhydra.shark.api.internal.working.CallbackUtilities;
12
13 /**
14  * Implementation of TransactionFactory interface that creates Hibernate
15  * transaction.
16  * @author Vladislav Pernin
17  */

18 public class HibernateTransactionFactory implements TransactionFactory {
19
20     private CallbackUtilities cus;
21
22     static boolean _debug_ = false;
23
24     private static final String JavaDoc DBG_PARAM_NAME = "HibernateTransactionFactory.debug";
25
26     public void configure(CallbackUtilities cus) throws RootException {
27         if (null == cus)
28                 throw new RootException(
29                         "Cannot configure without call back impl.");
30         this.cus = cus;
31         _debug_ = Boolean.valueOf(cus.getProperty(DBG_PARAM_NAME, "false"))
32                 .booleanValue();
33     }
34
35     public SharkTransaction createTransaction() throws TransactionException {
36         try {
37             return new SharkHibernateTransaction(ThreadLocalSession
38                     .currentSession().beginTransaction());
39         } catch (Exception JavaDoc ex) {
40             throw new TransactionException(ex);
41         }
42     }
43
44 }
45
46
Popular Tags