KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > RAMTransactionContext


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.RAMTransactionContext
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.store.access;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25 import org.apache.derby.iapi.error.StandardException;
26 import org.apache.derby.iapi.store.access.TransactionController;
27 import org.apache.derby.iapi.services.context.ContextManager;
28
29 import org.apache.derby.iapi.services.context.ContextImpl;
30 import org.apache.derby.iapi.error.ExceptionSeverity;
31 final class RAMTransactionContext extends ContextImpl
32 {
33     /**
34     The transaction this context is managing.
35     **/

36     protected RAMTransaction transaction;
37
38     /**
39        true if any exception causes this transaction to be destroyed
40     **/

41     private boolean abortAll;
42
43     /*
44     ** Context methods (most are implemented by super-class).
45     */

46
47     /**
48     Handle cleanup processing for this context. The resources
49     associated with a transaction are the open controllers.
50     Cleanup involves closing them at the appropriate time.
51     Rollback of the underlying transaction is handled by the
52     raw store.
53     **/

54     public void cleanupOnError(Throwable JavaDoc error)
55         throws StandardException
56     {
57         if (SanityManager.DEBUG)
58             SanityManager.ASSERT(getContextManager() != null);
59
60         boolean destroy = false;
61
62         if (abortAll == false && (error instanceof StandardException))
63         {
64             StandardException se = (StandardException) error;
65
66             // If the severity is lower than a transaction error then do nothing.
67
if (se.getSeverity() < ExceptionSeverity.TRANSACTION_SEVERITY)
68                 return;
69
70             // If the session is going to disappear then we want to destroy this
71
// transaction, not just abort it.
72
if (se.getSeverity() >= ExceptionSeverity.SESSION_SEVERITY)
73                 destroy = true;
74         }
75         else
76         {
77             // abortAll is true or some java* error, throw away the
78
// transaction.
79
destroy = true;
80         }
81
82         if (transaction != null)
83         {
84             try
85             {
86                 transaction.invalidateConglomerateCache();
87             }
88             catch (StandardException se)
89             {
90                 // RESOLVE - what to do in error case.
91
if (SanityManager.DEBUG)
92                     SanityManager.THROWASSERT(
93                         "got error while invalidating cache.");
94             }
95
96             transaction.closeControllers(true /* close held controllers */ );
97         }
98
99         if (destroy)
100         {
101             transaction = null;
102             popMe();
103         }
104
105     }
106
107     /*
108     ** Methods of RAMTransactionContext
109     */

110
111     // this constructor is called with the transaction
112
// controller to be saved when the context
113
// is created (when the first statement comes in, likely).
114
RAMTransactionContext(
115     ContextManager cm,
116     String JavaDoc context_id,
117     RAMTransaction theTransaction,
118     boolean abortAll)
119         throws StandardException
120     {
121         super(cm, context_id);
122
123         this.abortAll = abortAll;
124         transaction = theTransaction;
125         transaction.setContext(this);
126     }
127
128     /* package */ RAMTransaction getTransaction()
129     {
130         return transaction;
131     }
132
133     /* package */ void setTransaction(
134     RAMTransaction transaction)
135     {
136         this.transaction = transaction;
137     }
138 }
139
140
141
Popular Tags