001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.data.PhysicalPageOperation
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.impl.store.raw.data.BasePage;
025:
026: import org.apache.derby.iapi.store.raw.Compensation;
027:
028: import org.apache.derby.iapi.store.raw.log.LogInstant;
029:
030: import org.apache.derby.iapi.store.raw.Transaction;
031: import org.apache.derby.iapi.store.raw.Undoable;
032:
033: import org.apache.derby.iapi.error.StandardException;
034:
035: import java.io.InputStream;
036: import java.io.ObjectInput;
037: import java.io.IOException;
038: import org.apache.derby.iapi.services.io.LimitObjectInput;
039:
040: /**
041: An abstract class that is used for physical log operation. A physical log
042: operation is one where the undo of the operation must be applied to the
043: same page as the original operation, and the undo operation must store the
044: byte image of the row(s) changed to its before image. (If a logical page
045: operation happened to the page or if another transaction altered other rows
046: on the page, the undo of this operation will only restore the before image
047: of the row(s) affected).
048:
049: <PRE>
050: @format_id no format id, an abstract class.
051: @purpose provide methods for physical undo
052: @upgrade
053: @disk_layout
054: PageBasicOperation the super class
055: @end_format
056: </PRE>
057: */
058:
059: public abstract class PhysicalPageOperation extends PageBasicOperation
060: implements Undoable {
061: protected PhysicalPageOperation(BasePage page) {
062: super (page);
063: }
064:
065: /*
066: * Formatable methods
067: */
068:
069: // no-arg constructor, required by Formatable
070: public PhysicalPageOperation() {
071: super ();
072: }
073:
074: // no fields, therefore no writeExternal or readExternal
075:
076: /**
077: Undoable method
078: */
079:
080: /**
081: Generate a Compensation (PageUndoOperation) that will rollback the
082: changes of this page operation. If this Page operation cannot or need not
083: be rolled back (redo only), overwrite this function to return null.
084:
085: <P><B>Note</B><BR> For operation that needs logical undo, use
086: LogicalUndoOperation instead</B> This implementation just finds
087: the same page that the PageOperation was applied on - i.e., only works
088: for undo on the same page.
089:
090: <P>During recovery redo, the logging system is page oriented and will use
091: the pageID stored in the PageUndoOperation to find the page. The
092: page will be latched and released using the default findpage and
093: releaseResource - this.releaseResource() will still be called so it has
094: to know not to release any resource it did not acquire.
095:
096: @param xact the transaction doing the compensating
097: @param in optional input
098:
099: @return the compensation operation that will rollback this change
100:
101: @exception StandardException Standard Cloudscape policy.
102:
103: @see PageBasicOperation
104: @see Undoable#generateUndo
105:
106: */
107: public Compensation generateUndo(Transaction xact,
108: LimitObjectInput in) throws StandardException {
109: // findpage will have the page latched.
110: // CompensationOperation.doMe must call this.releaseResource the page
111: // when it is done
112: BasePage undoPage = findpage(xact);
113:
114: // Needs to pre-dirty this page so that if a checkpoint is taken any
115: // time after the CLR is sent to the log stream, it will wait for the
116: // actual undo to happen on the page. We need this to preserve the
117: // integrity of the redoLWM.
118: undoPage.preDirty();
119:
120: return new PhysicalUndoOperation(undoPage, this );
121: }
122:
123: /**
124: Undo the change indicated by this log operation and optional data.
125: The page the undo should apply to is the latched undoPage, the
126: recordId is the same as the roll forward operation.
127:
128: <BR><B>In this RawStore implementation, should only only be called via
129: CompOp.doMe</B>.
130:
131: <P> The available() method of in indicates how much data can be read, i.e.
132: how much was originally written.
133:
134: @param xact the Transaction doing the rollback
135: @param undoPage the page to rollback changes on
136: @param CLRinstant the log instant of this (PageUndo) operation
137: @param in optional data for the rollback operation
138:
139: @exception IOException Can be thrown by any of the methods of ObjectInput.
140: @exception StandardException Standard Cloudscape policy.
141: */
142: abstract public void undoMe(Transaction xact, BasePage undoPage,
143: LogInstant CLRinstant, LimitObjectInput in)
144: throws StandardException, IOException;
145:
146: }
|