1 21 22 package org.apache.derbyTesting.unitTests.store; 23 24 import org.apache.derby.iapi.store.raw.*; 25 26 import org.apache.derby.iapi.services.context.ContextManager; 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 import org.apache.derby.iapi.services.context.ContextService; 29 import org.apache.derby.iapi.error.StandardException; 30 import org.apache.derby.iapi.services.locks.LockFactory; 31 import org.apache.derby.iapi.store.access.AccessFactoryGlobals; 32 33 37 public class T_TWC 38 { 39 protected Transaction tran; 40 protected ContextManager cm; 41 protected ContextService contextService; 42 protected LockFactory lf; 43 protected RawStoreFactory rawStore; 44 45 public T_TWC(ContextService contextService, 46 LockFactory lockFactory, 47 RawStoreFactory rawStoreFactory) 48 { 49 this.contextService = contextService; 50 this.lf = lockFactory; 51 this.rawStore = rawStoreFactory; 52 tran = null; 53 cm = null; 54 } 55 56 public T_TWC startUserTransaction() 57 throws StandardException 58 { 59 cm = contextService.newContextManager(); 60 contextService.setCurrentContextManager(cm); 61 try { 62 tran = 63 rawStore.startTransaction(cm, AccessFactoryGlobals.USER_TRANS_NAME); 64 65 if (SanityManager.DEBUG) 66 SanityManager.ASSERT(tran != null); 67 checkNullLockCount(); 68 } 69 finally { 70 contextService.resetCurrentContextManager(cm); 71 } 72 return this; 73 } 74 75 public void checkNullLockCount() 76 { 77 switchTransactionContext(); 78 try { 79 if (SanityManager.DEBUG) 80 SanityManager.ASSERT(!lf.areLocksHeld(tran)); 81 } finally { 82 resetContext(); 83 } 84 } 85 86 public void setSavePoint(String sp, Object kindOfSavepoint) 87 throws StandardException 88 { 89 switchTransactionContext(); 90 try { 91 tran.setSavePoint(sp, null); 92 } finally { 93 resetContext(); 94 } 95 } 96 97 public void rollbackToSavePoint(String sp, Object kindOfSavepoint) 98 throws StandardException 99 { 100 switchTransactionContext(); 101 try { 102 tran.rollbackToSavePoint(sp, null); 103 } finally { 104 resetContext(); 105 } 106 } 107 108 public void switchTransactionContext() 109 { 110 contextService.setCurrentContextManager(cm); 111 } 112 public void resetContext() { 113 contextService.resetCurrentContextManager(cm); 114 } 115 116 public void logAndDo(Loggable l) 117 throws StandardException 118 { 119 switchTransactionContext(); 120 try { 121 tran.logAndDo(l); 122 } finally { 123 resetContext(); 124 } 125 } 126 127 public void commit() 128 throws StandardException 129 { 130 switchTransactionContext(); 131 try { 132 tran.commit(); 133 } finally { 134 resetContext(); 135 } 136 checkNullLockCount(); 137 } 138 139 public void abort() 140 throws StandardException 141 { 142 switchTransactionContext(); 143 try { 144 tran.abort(); 145 } finally { 146 resetContext(); 147 } 148 checkNullLockCount(); 149 } 150 151 152 public GlobalTransactionId getId() 153 throws StandardException 154 { 155 switchTransactionContext(); 156 try { 157 return tran.getGlobalId(); 158 } finally { 159 resetContext(); 160 } 161 162 } 163 } 164 | Popular Tags |