1 2 5 14 package org.jacorb.trading.db.pse.util; 15 16 import COM.odi.*; 17 18 19 24 public class TransactionMgr 25 { 26 private Thread m_mainThread; 27 private Thread m_owner = null; 28 private int m_refCount = 0; 29 30 31 public TransactionMgr() 32 { 33 m_mainThread = Thread.currentThread(); 35 } 36 37 38 public synchronized void begin() 39 { 40 ObjectStore.initialize(m_mainThread); 42 43 Thread currentThread = Thread.currentThread(); 44 45 if (currentThread != m_owner) { 47 while (m_refCount != 0) { 48 try { 49 wait(); 50 } 51 catch (InterruptedException e) { 52 } 53 } 54 } 55 56 if (m_refCount == 0) 59 Transaction.begin(ObjectStore.UPDATE); 60 61 m_owner = currentThread; 62 m_refCount++; 63 } 64 65 66 public synchronized void commit(int retain) 67 { 68 Thread currentThread = Thread.currentThread(); 69 if (currentThread != m_owner) 70 throw new RuntimeException ("Thread not owner"); 71 72 if (m_refCount > 0) 73 m_refCount--; 74 else if (m_refCount == 0) 75 throw new RuntimeException ("refCount should not be 0"); 76 77 if (m_refCount == 0) { 79 Transaction.current().commit(retain); 80 ObjectStore.shutdown(false); 82 m_owner = null; 83 notifyAll(); 84 } 85 } 86 } 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | Popular Tags |