KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > raw > data > EncryptContainerUndoOperation


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.EncryptContainerUndoOperation
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.raw.data;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25 import org.apache.derby.iapi.services.io.StoredFormatIds;
26
27 import org.apache.derby.iapi.store.raw.Compensation;
28 import org.apache.derby.iapi.store.raw.Loggable;
29 import org.apache.derby.iapi.store.raw.Transaction;
30 import org.apache.derby.iapi.store.raw.Undoable;
31 import org.apache.derby.iapi.util.ByteArray;
32 import org.apache.derby.iapi.store.raw.log.LogInstant;
33 import org.apache.derby.iapi.error.StandardException;
34
35 import java.io.ObjectOutput JavaDoc;
36 import java.io.ObjectInput JavaDoc;
37 import java.io.IOException JavaDoc;
38 import org.apache.derby.iapi.services.io.LimitObjectInput;
39
40 /** A Encrypt Container undo operation rolls back the change of a
41  * Encrypt Container operation
42  */

43 public class EncryptContainerUndoOperation implements Compensation
44 {
45     // the operation to rollback
46
transient private EncryptContainerOperation undoOp;
47
48     /** During redo, the whole operation will be reconstituted from the log */
49
50     /**
51      * Set up a Encrypt Container undo operation during run time rollback
52      * @param op Encrypt contaner operatation that is to be undone.
53      */

54     public EncryptContainerUndoOperation(EncryptContainerOperation op)
55     {
56         undoOp = op;
57     }
58
59     /*
60      * Formatable methods
61      */

62
63     // no-arg constructor, required by Formatable
64
public EncryptContainerUndoOperation() { super(); }
65
66     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
67     {
68         // nothing to write.
69
}
70
71     /**
72         @exception IOException cannot read log record from log stream
73         @exception ClassNotFoundException cannot read ByteArray object
74      */

75     public void readExternal(ObjectInput JavaDoc in)
76          throws IOException JavaDoc, ClassNotFoundException JavaDoc
77     {
78         // nothing to read.
79
}
80
81     /**
82         Return my format identifier.
83     */

84     public int getTypeFormatId() {
85         return StoredFormatIds.LOGOP_ENCRYPT_CONTAINER_UNDO;
86     }
87
88     /**
89         Compensation method
90     */

91
92     /** Set up a Container undo operation during recovery redo. */
93     public void setUndoOp(Undoable op)
94     {
95         if (SanityManager.DEBUG) {
96             SanityManager.ASSERT(op instanceof EncryptContainerOperation);
97         }
98
99         undoOp = (EncryptContainerOperation)op;
100     }
101
102     /**
103         Loggable methods
104     */

105
106     
107     /**
108      * Check if this operation needs to be redone during recovery redo.
109      * Returns true if this op should be redone during recovery redo,
110      * @param xact the transaction that is doing the rollback
111      * @return true, if this operation needs to be redone during recovery.
112      * @exception StandardException Standard Derby error policy
113      */

114     public boolean needsRedo(Transaction xact)
115         throws StandardException
116     {
117         return true;
118     }
119
120     /**
121        the default for prepared log is always null for all the operations
122        that don't have optionalData. If an operation has optional data,
123        the operation need to prepare the optional data for this method.
124
125        Encrypt Conatainer Undo Operation has no optional data to write out
126     */

127     public ByteArray getPreparedLog()
128     {
129         return (ByteArray) null;
130     }
131
132
133     /** Apply the undo operation, in this implementation of the
134         RawStore, it can only call the undoMe method of undoOp
135         @param xact the Transaction that is doing the rollback
136         @param instant the log instant of this compenstaion operation
137         @param in optional data
138         @exception IOException Can be thrown by any of the methods of ObjectInput.
139         @exception StandardException Standard Derby policy.
140
141         @see EncryptContainerOperation#generateUndo
142     */

143     public final void doMe(Transaction xact, LogInstant instant,
144                            LimitObjectInput in)
145         throws StandardException, IOException JavaDoc
146     {
147         undoOp.undoMe(xact);
148         releaseResource(xact);
149     }
150
151     /* make sure resource found in undoOp is released */
152     public void releaseResource(Transaction xact)
153     {
154         if (undoOp != null)
155             undoOp.releaseResource(xact);
156     }
157
158     /* Undo operation is a COMPENSATION log operation */
159     public int group()
160     {
161         return Loggable.COMPENSATION | Loggable.RAWSTORE;
162     }
163
164     /**
165       DEBUG: Print self.
166     */

167     public String JavaDoc toString()
168     {
169         if (SanityManager.DEBUG)
170         {
171             String JavaDoc str = "CLR (Encrypt Container Undo): " ;
172             if (undoOp != null)
173                 str += undoOp.toString();
174             else
175                 str += "undo Operation not set";
176
177             return str;
178         }
179         else
180             return null;
181     }
182 }
183
Popular Tags