001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.data.EncryptContainerUndoOperation
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.StoredFormatIds;
026:
027: import org.apache.derby.iapi.store.raw.Compensation;
028: import org.apache.derby.iapi.store.raw.Loggable;
029: import org.apache.derby.iapi.store.raw.Transaction;
030: import org.apache.derby.iapi.store.raw.Undoable;
031: import org.apache.derby.iapi.util.ByteArray;
032: import org.apache.derby.iapi.store.raw.log.LogInstant;
033: import org.apache.derby.iapi.error.StandardException;
034:
035: import java.io.ObjectOutput;
036: import java.io.ObjectInput;
037: import java.io.IOException;
038: import org.apache.derby.iapi.services.io.LimitObjectInput;
039:
040: /** A Encrypt Container undo operation rolls back the change of a
041: * Encrypt Container operation
042: */
043: public class EncryptContainerUndoOperation implements Compensation {
044: // the operation to rollback
045: transient private EncryptContainerOperation undoOp;
046:
047: /** During redo, the whole operation will be reconstituted from the log */
048:
049: /**
050: * Set up a Encrypt Container undo operation during run time rollback
051: * @param op Encrypt contaner operatation that is to be undone.
052: */
053: public EncryptContainerUndoOperation(EncryptContainerOperation op) {
054: undoOp = op;
055: }
056:
057: /*
058: * Formatable methods
059: */
060:
061: // no-arg constructor, required by Formatable
062: public EncryptContainerUndoOperation() {
063: super ();
064: }
065:
066: public void writeExternal(ObjectOutput out) throws IOException {
067: // nothing to write.
068: }
069:
070: /**
071: @exception IOException cannot read log record from log stream
072: @exception ClassNotFoundException cannot read ByteArray object
073: */
074: public void readExternal(ObjectInput in) throws IOException,
075: ClassNotFoundException {
076: // nothing to read.
077: }
078:
079: /**
080: Return my format identifier.
081: */
082: public int getTypeFormatId() {
083: return StoredFormatIds.LOGOP_ENCRYPT_CONTAINER_UNDO;
084: }
085:
086: /**
087: Compensation method
088: */
089:
090: /** Set up a Container undo operation during recovery redo. */
091: public void setUndoOp(Undoable op) {
092: if (SanityManager.DEBUG) {
093: SanityManager
094: .ASSERT(op instanceof EncryptContainerOperation);
095: }
096:
097: undoOp = (EncryptContainerOperation) op;
098: }
099:
100: /**
101: Loggable methods
102: */
103:
104: /**
105: * Check if this operation needs to be redone during recovery redo.
106: * Returns true if this op should be redone during recovery redo,
107: * @param xact the transaction that is doing the rollback
108: * @return true, if this operation needs to be redone during recovery.
109: * @exception StandardException Standard Derby error policy
110: */
111: public boolean needsRedo(Transaction xact) throws StandardException {
112: return true;
113: }
114:
115: /**
116: the default for prepared log is always null for all the operations
117: that don't have optionalData. If an operation has optional data,
118: the operation need to prepare the optional data for this method.
119:
120: Encrypt Conatainer Undo Operation has no optional data to write out
121: */
122: public ByteArray getPreparedLog() {
123: return (ByteArray) null;
124: }
125:
126: /** Apply the undo operation, in this implementation of the
127: RawStore, it can only call the undoMe method of undoOp
128: @param xact the Transaction that is doing the rollback
129: @param instant the log instant of this compenstaion operation
130: @param in optional data
131: @exception IOException Can be thrown by any of the methods of ObjectInput.
132: @exception StandardException Standard Derby policy.
133:
134: @see EncryptContainerOperation#generateUndo
135: */
136: public final void doMe(Transaction xact, LogInstant instant,
137: LimitObjectInput in) throws StandardException, IOException {
138: undoOp.undoMe(xact);
139: releaseResource(xact);
140: }
141:
142: /* make sure resource found in undoOp is released */
143: public void releaseResource(Transaction xact) {
144: if (undoOp != null)
145: undoOp.releaseResource(xact);
146: }
147:
148: /* Undo operation is a COMPENSATION log operation */
149: public int group() {
150: return Loggable.COMPENSATION | Loggable.RAWSTORE;
151: }
152:
153: /**
154: DEBUG: Print self.
155: */
156: public String toString() {
157: if (SanityManager.DEBUG) {
158: String str = "CLR (Encrypt Container Undo): ";
159: if (undoOp != null)
160: str += undoOp.toString();
161: else
162: str += "undo Operation not set";
163:
164: return str;
165: } else
166: return null;
167: }
168: }
|