001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.data.ContainerUndoOperation
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.raw.data;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025: import org.apache.derby.iapi.services.io.FormatIdUtil;
026: import org.apache.derby.iapi.services.io.StoredFormatIds;
027:
028: import org.apache.derby.iapi.store.raw.Compensation;
029: import org.apache.derby.iapi.store.raw.ContainerHandle;
030: import org.apache.derby.iapi.store.raw.Loggable;
031: import org.apache.derby.iapi.store.raw.Transaction;
032: import org.apache.derby.iapi.store.raw.Undoable;
033:
034: import org.apache.derby.iapi.store.raw.data.RawContainerHandle;
035: import org.apache.derby.iapi.store.raw.log.LogInstant;
036:
037: import org.apache.derby.iapi.error.StandardException;
038:
039: import java.io.InputStream;
040: import java.io.ObjectOutput;
041: import java.io.ObjectInput;
042: import java.io.IOException;
043: import org.apache.derby.iapi.services.io.LimitObjectInput;
044:
045: /** A Container undo operation rolls back the change of a Container operation */
046: public class ContainerUndoOperation extends ContainerBasicOperation
047: implements Compensation {
048: // the operation to rollback
049: transient private ContainerOperation undoOp;
050:
051: /** During redo, the whole operation will be reconstituted from the log */
052:
053: /**
054: Set up a Container undo operation during run time rollback
055: @exception StandardException container Handle is not active
056: */
057: public ContainerUndoOperation(RawContainerHandle hdl,
058: ContainerOperation op) throws StandardException {
059: super (hdl);
060: undoOp = op;
061: }
062:
063: /*
064: * Formatable methods
065: */
066:
067: // no-arg constructor, required by Formatable
068: public ContainerUndoOperation() {
069: super ();
070: }
071:
072: public void writeExternal(ObjectOutput out) throws IOException {
073: super .writeExternal(out);
074: }
075:
076: /**
077: @exception IOException cannot read log record from log stream
078: @exception ClassNotFoundException cannot read ByteArray object
079: */
080: public void readExternal(ObjectInput in) throws IOException,
081: ClassNotFoundException {
082: super .readExternal(in);
083: }
084:
085: /**
086: Return my format identifier.
087: */
088: public int getTypeFormatId() {
089: return StoredFormatIds.LOGOP_CONTAINER_UNDO;
090: }
091:
092: /**
093: Compensation method
094: */
095:
096: /** Set up a Container undo operation during recovery redo. */
097: public void setUndoOp(Undoable op) {
098: if (SanityManager.DEBUG) {
099: SanityManager.ASSERT(op instanceof ContainerOperation);
100: }
101:
102: undoOp = (ContainerOperation) op;
103: }
104:
105: /**
106: Loggable methods
107: */
108:
109: /** Apply the undo operation, in this implementation of the
110: RawStore, it can only call the undoMe method of undoOp
111:
112: @param xact the Transaction that is doing the rollback
113: @param instant the log instant of this compenstaion operation
114: @param in optional data
115:
116: @exception IOException Can be thrown by any of the methods of ObjectInput.
117: @exception StandardException Standard Cloudscape policy.
118:
119: @see ContainerOperation#generateUndo
120: */
121: public final void doMe(Transaction xact, LogInstant instant,
122: LimitObjectInput in) throws StandardException, IOException {
123: if (SanityManager.DEBUG) {
124: SanityManager.ASSERT(containerHdl != null,
125: "clr has null containerHdl");
126: }
127:
128: // if this is called during runtime rollback, generateUndo found
129: // the container and have it opened there.
130: // if this is called during recovery redo, this.needsRedo found
131: // the container and have it opened here.
132: //
133: // in either case, containerHdl is the opened container handle.
134:
135: undoOp.undoMe(xact, containerHdl, instant, in);
136: releaseResource(xact);
137: }
138:
139: /* make sure resource found in undoOp is released */
140: public void releaseResource(Transaction xact) {
141: if (undoOp != null)
142: undoOp.releaseResource(xact);
143: super .releaseResource(xact);
144: }
145:
146: /* Undo operation is a COMPENSATION log operation */
147: public int group() {
148: return super.group() | Loggable.COMPENSATION
149: | Loggable.RAWSTORE;
150: }
151:
152: }
|