001: /*
002:
003: Derby - Class org.apache.derby.impl.store.raw.data.LoggableActions
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.PageActions;
025: import org.apache.derby.impl.store.raw.data.BasePage;
026:
027: import org.apache.derby.iapi.services.io.FormatIdUtil;
028:
029: import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo;
030:
031: import org.apache.derby.iapi.store.raw.xact.RawTransaction;
032: import org.apache.derby.iapi.store.raw.RecordHandle;
033: import org.apache.derby.iapi.store.raw.Loggable;
034: import org.apache.derby.iapi.store.raw.log.LogInstant;
035:
036: import org.apache.derby.iapi.error.StandardException;
037: import org.apache.derby.iapi.types.DataValueDescriptor;
038:
039: import org.apache.derby.iapi.services.sanity.SanityManager;
040: import org.apache.derby.iapi.services.io.FormatableBitSet;
041: import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;
042: import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;
043:
044: import java.io.IOException;
045:
046: public class LoggableActions implements PageActions {
047:
048: public void actionDelete(RawTransaction t, BasePage page, int slot,
049: int recordId, boolean delete, LogicalUndo undo)
050: throws StandardException {
051:
052: DeleteOperation lop = new DeleteOperation(t, page, slot,
053: recordId, delete, undo);
054:
055: doAction(t, page, lop);
056: }
057:
058: public int actionUpdate(RawTransaction t, BasePage page, int slot,
059: int recordId, Object[] row, FormatableBitSet validColumns,
060: int realStartColumn,
061: DynamicByteArrayOutputStream logBuffer,
062: int realSpaceOnPage, RecordHandle headRowHandle)
063: throws StandardException {
064: UpdateOperation lop = new UpdateOperation(t, page, slot,
065: recordId, row, validColumns, realStartColumn,
066: logBuffer, realSpaceOnPage, headRowHandle);
067:
068: doAction(t, page, lop);
069:
070: return lop.getNextStartColumn();
071: }
072:
073: public void actionPurge(RawTransaction t, BasePage page, int slot,
074: int num_rows, int[] recordIds, boolean logData)
075: throws StandardException {
076: PurgeOperation lop = new PurgeOperation(t, page, slot,
077: num_rows, recordIds, logData);
078:
079: doAction(t, page, lop);
080: }
081:
082: public void actionUpdateField(RawTransaction t, BasePage page,
083: int slot, int recordId, int fieldId, Object newValue,
084: LogicalUndo undo) throws StandardException {
085: UpdateFieldOperation lop = new UpdateFieldOperation(t, page,
086: slot, recordId, fieldId, newValue, undo);
087:
088: doAction(t, page, lop);
089: }
090:
091: public int actionInsert(RawTransaction t, BasePage page, int slot,
092: int recordId, Object[] row, FormatableBitSet validColumns,
093: LogicalUndo undo, byte insertFlag, int startColumn,
094: boolean isLongColumn, int realStartColumn,
095: DynamicByteArrayOutputStream logBuffer,
096: int realSpaceOnPage, int overflowThreshold)
097: throws StandardException {
098: InsertOperation lop = new InsertOperation(t, page, slot,
099: recordId, row, validColumns, undo, insertFlag,
100: startColumn, isLongColumn, realStartColumn, logBuffer,
101: realSpaceOnPage, overflowThreshold);
102:
103: doAction(t, page, lop);
104: return (lop.getNextStartColumn());
105:
106: }
107:
108: public void actionCopyRows(RawTransaction t, BasePage destPage,
109: BasePage srcPage, int srcSlot, int numRows, int destSlot,
110: int[] recordIds) throws StandardException {
111:
112: CopyRowsOperation lop = new CopyRowsOperation(t, destPage,
113: srcPage, srcSlot, numRows, destSlot, recordIds);
114:
115: doAction(t, destPage, lop);
116: }
117:
118: public void actionInvalidatePage(RawTransaction t, BasePage page)
119: throws StandardException {
120:
121: InvalidatePageOperation lop = new InvalidatePageOperation(page);
122: doAction(t, page, lop);
123: }
124:
125: public void actionInitPage(RawTransaction t, BasePage page,
126: int initFlag, int pageFormatId, long pageOffset)
127: throws StandardException {
128: InitPageOperation lop = new InitPageOperation(page, initFlag,
129: pageFormatId, pageOffset);
130:
131: doAction(t, page, lop);
132: }
133:
134: public void actionShrinkReservedSpace(RawTransaction t,
135: BasePage page, int slot, int recordId, int newValue,
136: int oldValue) throws StandardException {
137:
138: SetReservedSpaceOperation lop = new SetReservedSpaceOperation(
139: page, slot, recordId, newValue, oldValue);
140:
141: doAction(t, page, lop);
142: }
143:
144: private void doAction(RawTransaction t, BasePage page, Loggable lop)
145: throws StandardException {
146: long oldversion = 0; // sanity check
147: LogInstant oldLogInstant = null; // sanity check
148: if (SanityManager.DEBUG) {
149: oldLogInstant = page.getLastLogInstant();
150: oldversion = page.getPageVersion();
151: }
152:
153: // mark the page as pre-dirtied so that if a checkpoint happens after
154: // the log record is sent to the log stream, the cache cleaning will
155: // wait for this change.
156: page.preDirty();
157:
158: t.logAndDo(lop);
159:
160: if (SanityManager.DEBUG) {
161: // log instant may not supported by underlying log factory, in that
162: // case, it is expected to stay null
163: if (oldLogInstant != null
164: && page.getLastLogInstant() != null
165: && !oldLogInstant
166: .lessThan(page.getLastLogInstant()))
167: SanityManager.THROWASSERT("old log instant = "
168: + oldLogInstant + " lastlog = "
169: + page.getLastLogInstant());
170:
171: SanityManager
172: .ASSERT(oldversion == ((PageBasicOperation) lop)
173: .getPageVersion());
174: SanityManager.ASSERT(page.getPageVersion() > oldversion);
175: }
176:
177: }
178:
179: }
|