1 21 22 package org.apache.derby.impl.store.raw.xact; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 26 import org.apache.derby.iapi.services.context.ContextImpl; 28 import org.apache.derby.iapi.services.context.ContextManager; 29 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 32 import org.apache.derby.iapi.store.raw.RawStoreFactory; 33 import org.apache.derby.iapi.store.raw.xact.RawTransaction; 34 35 import org.apache.derby.iapi.error.StandardException; 36 37 import org.apache.derby.iapi.error.ExceptionSeverity; 38 39 47 48 final class XactContext extends ContextImpl { 49 50 private RawTransaction xact; 51 private RawStoreFactory factory; 52 private boolean abortAll; 54 XactContext(ContextManager cm, String name, Xact xact, boolean abortAll, RawStoreFactory factory) { 55 super(cm, name); 56 57 this.xact = xact; 58 this.abortAll = abortAll; 59 this.factory = factory; 60 xact.xc = this; } 62 63 64 67 68 69 72 public void cleanupOnError(Throwable error) throws StandardException { 73 74 if (SanityManager.DEBUG) 75 { 76 SanityManager.ASSERT(getContextManager() != null); 77 } 78 79 boolean throwAway = false; 80 81 if (error instanceof StandardException) { 82 StandardException se = (StandardException) error; 83 84 if (abortAll) { 85 87 if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY) 88 { 89 throw StandardException.newException( 90 SQLState.XACT_INTERNAL_TRANSACTION_EXCEPTION, error); 91 } 92 93 throwAway = true; 94 95 96 } else { 97 98 if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY) 100 { 101 return; 102 } 103 104 105 if (se.getSeverity() >= ExceptionSeverity.SESSION_SEVERITY) 108 throwAway = true; 109 } 110 } else { 111 throwAway = true; 113 } 114 115 try { 116 117 if (xact != null) { 118 xact.abort(); 120 } 121 122 } catch (StandardException se) { 123 throwAway = true; 125 126 if ((se.getSeverity() <= ExceptionSeverity.SESSION_SEVERITY) && 128 (se.getSeverity() >= ((StandardException) error).getSeverity())) { 129 130 throw factory.markCorrupt( 131 StandardException.newException( 132 SQLState.XACT_ABORT_EXCEPTION, se)); 133 } 134 135 } finally { 136 137 if (throwAway) { 138 xact.close(); 141 xact = null; 142 } 143 } 144 145 } 146 147 RawTransaction getTransaction() { 148 return xact; 149 } 150 151 RawStoreFactory getFactory() { 152 return factory; 153 } 154 155 void substituteTransaction(Xact newTran) 156 { 157 Xact oldTran = (Xact)xact; 159 if (oldTran.xc == this) 160 oldTran.xc = null; 161 162 xact = newTran; 164 ((Xact)xact).xc = this; 165 } 166 167 } 168 | Popular Tags |