KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > transaction > DummyTransactionManager


1 package org.jboss.cache.transaction;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 import javax.naming.Context JavaDoc;
7 import javax.naming.InitialContext JavaDoc;
8 import javax.naming.NamingException JavaDoc;
9 import java.util.Properties JavaDoc;
10
11 /**
12  * @author bela
13  * @version $Revision: 1.4 $
14  * Date: May 15, 2003
15  * Time: 4:11:37 PM
16  */

17 public class DummyTransactionManager extends DummyBaseTransactionManager
18 {
19    static DummyTransactionManager instance = null;
20
21    static Log log = LogFactory.getLog(DummyTransactionManager.class);
22
23    private static final long serialVersionUID = 4396695354693176535L;
24
25    public DummyTransactionManager()
26    {
27    }
28
29    public static DummyTransactionManager getInstance()
30    {
31       if (instance == null)
32       {
33          instance = new DummyTransactionManager();
34          try
35          {
36             Properties JavaDoc p = new Properties JavaDoc();
37             p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
38             Context JavaDoc ctx = new InitialContext JavaDoc(p);
39             ctx.bind("java:/TransactionManager", instance);
40             ctx.bind("UserTransaction", new DummyUserTransaction(instance));
41          }
42          catch (NamingException JavaDoc e)
43          {
44             log.error("binding of DummyTransactionManager failed", e);
45          }
46       }
47       return instance;
48    }
49
50    public static void destroy()
51    {
52       if (instance == null)
53          return;
54       try
55       {
56          Properties JavaDoc p = new Properties JavaDoc();
57          p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
58          Context JavaDoc ctx = new InitialContext JavaDoc(p);
59          ctx.unbind("java:/TransactionManager");
60          ctx.unbind("UserTransaction");
61       }
62       catch (NamingException JavaDoc e)
63       {
64          log.error("unbinding of DummyTransactionManager failed", e);
65       }
66       instance.setTransaction(null);
67       instance = null;
68    }
69
70 }
71
Popular Tags