KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.store.raw.data.ContainerUndoOperation
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.FormatIdUtil;
26 import org.apache.derby.iapi.services.io.StoredFormatIds;
27
28 import org.apache.derby.iapi.store.raw.Compensation;
29 import org.apache.derby.iapi.store.raw.ContainerHandle;
30 import org.apache.derby.iapi.store.raw.Loggable;
31 import org.apache.derby.iapi.store.raw.Transaction;
32 import org.apache.derby.iapi.store.raw.Undoable;
33
34 import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
35 import org.apache.derby.iapi.store.raw.log.LogInstant;
36
37 import org.apache.derby.iapi.error.StandardException;
38
39 import java.io.InputStream JavaDoc;
40 import java.io.ObjectOutput JavaDoc;
41 import java.io.ObjectInput JavaDoc;
42 import java.io.IOException JavaDoc;
43 import org.apache.derby.iapi.services.io.LimitObjectInput;
44
45 /** A Container undo operation rolls back the change of a Container operation */
46 public class ContainerUndoOperation extends ContainerBasicOperation
47         implements Compensation
48 {
49     // the operation to rollback
50
transient private ContainerOperation undoOp;
51
52     /** During redo, the whole operation will be reconstituted from the log */
53
54     /**
55         Set up a Container undo operation during run time rollback
56         @exception StandardException container Handle is not active
57     */

58     public ContainerUndoOperation(RawContainerHandle hdl, ContainerOperation op)
59          throws StandardException
60     {
61         super(hdl);
62         undoOp = op;
63     }
64
65     /*
66      * Formatable methods
67      */

68
69     // no-arg constructor, required by Formatable
70
public ContainerUndoOperation() { super(); }
71
72     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
73     {
74         super.writeExternal(out);
75     }
76
77     /**
78         @exception IOException cannot read log record from log stream
79         @exception ClassNotFoundException cannot read ByteArray object
80      */

81     public void readExternal(ObjectInput JavaDoc in)
82          throws IOException JavaDoc, ClassNotFoundException JavaDoc
83     {
84         super.readExternal(in);
85     }
86
87     /**
88         Return my format identifier.
89     */

90     public int getTypeFormatId() {
91         return StoredFormatIds.LOGOP_CONTAINER_UNDO;
92     }
93
94     /**
95         Compensation method
96     */

97
98     /** Set up a Container undo operation during recovery redo. */
99     public void setUndoOp(Undoable op)
100     {
101         if (SanityManager.DEBUG) {
102             SanityManager.ASSERT(op instanceof ContainerOperation);
103         }
104
105         undoOp = (ContainerOperation)op;
106     }
107
108     /**
109         Loggable methods
110     */

111
112     /** Apply the undo operation, in this implementation of the
113         RawStore, it can only call the undoMe method of undoOp
114
115         @param xact the Transaction that is doing the rollback
116         @param instant the log instant of this compenstaion operation
117         @param in optional data
118
119         @exception IOException Can be thrown by any of the methods of ObjectInput.
120         @exception StandardException Standard Cloudscape policy.
121
122         @see ContainerOperation#generateUndo
123      */

124     public final void doMe(Transaction xact, LogInstant instant, LimitObjectInput in)
125          throws StandardException, IOException JavaDoc
126     {
127         if (SanityManager.DEBUG) {
128             SanityManager.ASSERT(containerHdl != null, "clr has null containerHdl");
129         }
130
131         // if this is called during runtime rollback, generateUndo found
132
// the container and have it opened there.
133
// if this is called during recovery redo, this.needsRedo found
134
// the container and have it opened here.
135
//
136
// in either case, containerHdl is the opened container handle.
137

138         undoOp.undoMe(xact, containerHdl, instant, in);
139         releaseResource(xact);
140     }
141
142     /* make sure resource found in undoOp is released */
143     public void releaseResource(Transaction xact)
144     {
145         if (undoOp != null)
146             undoOp.releaseResource(xact);
147         super.releaseResource(xact);
148     }
149
150     /* Undo operation is a COMPENSATION log operation */
151     public int group()
152     {
153         return super.group() | Loggable.COMPENSATION | Loggable.RAWSTORE;
154     }
155
156 }
157
Popular Tags