org.apache.derby.impl.store.raw.data
Class InsertOperation

java.lang.Object
  extended byorg.apache.derby.impl.store.raw.data.PageBasicOperation
      extended byorg.apache.derby.impl.store.raw.data.LogicalPageOperation
          extended byorg.apache.derby.impl.store.raw.data.InsertOperation
All Implemented Interfaces:
java.io.Externalizable, Formatable, Loggable, LogicalUndoable, RePreparable, java.io.Serializable, TypedFormat, Undoable

public final class InsertOperation
extends LogicalPageOperation

Represents an insert of a record onto a page.

See Also:
Page.insertAtSlot(int, java.lang.Object[], org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.store.access.conglomerate.LogicalUndo, byte, int), Serialized Form
Format IDLOGOP_INSERT the formatId is written by FormatIdOutputStream when this object is written out by writeObject
Purposeinsert a row onto a page
Upgrade
Disk LayoutLogicalPageOperation the superclass doMeSlot(CompressedInt) which slot to operate on insertFlat(byte) to undo with purge or with delete OptionalData The after image of the row to be inserted.

Field Summary
protected  int doMeSlot
           
protected  byte insertFlag
           
protected  ByteArray preparedLog
           
protected  int startColumn
          next column that need to be inserted.
 
Fields inherited from class org.apache.derby.impl.store.raw.data.LogicalPageOperation
recordId, undo
 
Fields inherited from class org.apache.derby.impl.store.raw.data.PageBasicOperation
containerHdl, foundHere, page
 
Fields inherited from interface org.apache.derby.iapi.store.raw.Loggable
ABORT, BI_LOG, CHECKSUM, COMMIT, COMPENSATION, FILE_RESOURCE, FIRST, LAST, PREPARE, RAWSTORE, XA_NEEDLOCK
 
Constructor Summary
InsertOperation()
           
InsertOperation(RawTransaction t, BasePage page, int slot, int recordId, java.lang.Object[] row, FormatableBitSet validColumns, LogicalUndo undo, byte insertFlag, int startColumn, boolean isLongColumn, int realStartColumn, DynamicByteArrayOutputStream logBuffer, int realSpaceOnPage, int overflowThreshold)
           
 
Method Summary
 void doMe(Transaction xact, LogInstant instant, LimitObjectInput in)
          Apply the change indicated by this operation and optional data.
 int getNextStartColumn()
           
 ByteArray getPreparedLog()
          The log operations are responsible to create the ByteArray, and the log operations should write out any optional data for the change to the ByteArray.
 int getTypeFormatId()
          Return my format identifier.
 void readExternal(java.io.ObjectInput in)
          Read this in
 void restoreLoggedRow(java.lang.Object[] row, LimitObjectInput in)
          Restore the row stored in the optional data of the log record.
 void restoreMe(Transaction xact, BasePage undoPage, LogInstant CLRinstant, LimitObjectInput in)
          restore the before image of the page
 java.lang.String toString()
          DEBUG: Print self.
 void undoMe(Transaction xact, BasePage undoPage, int undoRecordId, LogInstant CLRInstant, LimitObjectInput in)
          Undo the insert by simply marking the just inserted record as deleted.
 void writeExternal(java.io.ObjectOutput out)
          Write this out.
private  void writeOptionalDataToBuffer(RawTransaction t, DynamicByteArrayOutputStream logBuffer, java.lang.Object[] row, FormatableBitSet validColumns, boolean isLongColumn, int realStartColumn, int realSpaceOnPage, int overflowThreshold)
          Writes out the row that is to be inserted as the optional data.
 
Methods inherited from class org.apache.derby.impl.store.raw.data.LogicalPageOperation
generateUndo, getContainer, getRecordHandle, reclaimPrepareLocks, resetRecordHandle
 
Methods inherited from class org.apache.derby.impl.store.raw.data.PageBasicOperation
findpage, getPage, getPageForLoadTran, getPageId, getPageVersion, group, needsRedo, releaseResource, resetPageNumber
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.store.raw.Loggable
group, needsRedo, releaseResource
 

Field Detail

doMeSlot

protected int doMeSlot

insertFlag

protected byte insertFlag

startColumn

protected transient int startColumn
next column that need to be inserted.


preparedLog

protected transient ByteArray preparedLog
Constructor Detail

InsertOperation

public InsertOperation(RawTransaction t,
                       BasePage page,
                       int slot,
                       int recordId,
                       java.lang.Object[] row,
                       FormatableBitSet validColumns,
                       LogicalUndo undo,
                       byte insertFlag,
                       int startColumn,
                       boolean isLongColumn,
                       int realStartColumn,
                       DynamicByteArrayOutputStream logBuffer,
                       int realSpaceOnPage,
                       int overflowThreshold)
                throws StandardException

InsertOperation

public InsertOperation()
Method Detail

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Write this out.

Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class LogicalPageOperation
Throws:
java.io.IOException - error writing to log stream

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Read this in

Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class LogicalPageOperation
Throws:
java.io.IOException - error reading from log stream
java.lang.ClassNotFoundException - log stream corrupted

getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Returns:
The identifier. (A UUID stuffed in an array of 16 bytes).

doMe

public void doMe(Transaction xact,
                 LogInstant instant,
                 LimitObjectInput in)
          throws StandardException,
                 java.io.IOException
Description copied from interface: Loggable
Apply the change indicated by this operation and optional data. If this method fail, the system will be shut down because the log record has already been written to disk. Moreover, the log record will be replayed during recovery and this doMe method will be called on the same page again, so if it fails again, recovery will fail and the database cannot be started. So it is very important to make sure that every resource you need, such as disk space, has been acquired before the logAndDo method is called!
This method cannot acquire any resource (like latching of a page) since it is called underneath the logging system, ie., the log record has already been written to the log stream.

The available() method of in indicates how much data can be read, i.e. how much was originally written.

Parameters:
xact - the Transaction
instant - the log instant of this operation
in - optional data
Throws:
java.io.IOException - Can be thrown by any of the methods of ObjectInput.
StandardException - Standard Cloudscape policy.
See Also:
Loggable.doMe(org.apache.derby.iapi.store.raw.Transaction, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.services.io.LimitObjectInput)

undoMe

public void undoMe(Transaction xact,
                   BasePage undoPage,
                   int undoRecordId,
                   LogInstant CLRInstant,
                   LimitObjectInput in)
            throws StandardException,
                   java.io.IOException
Undo the insert by simply marking the just inserted record as deleted. All logical undo logic has already been taken care of by generateUndo.

Specified by:
undoMe in class LogicalPageOperation
Parameters:
xact - the Transaction doing the rollback
undoPage - the page to rollback changes on
undoRecordId - the recordId to rollback changes on
CLRInstant - the log instant of this (PageUndo) operation
in - optional data for the rollback operation
Throws:
java.io.IOException - Can be thrown by any of the methods of ObjectInput.
StandardException - Standard Cloudscape policy.
See Also:
LogicalPageOperation.undoMe(org.apache.derby.iapi.store.raw.Transaction, org.apache.derby.impl.store.raw.data.BasePage, int, org.apache.derby.iapi.store.raw.log.LogInstant, org.apache.derby.iapi.services.io.LimitObjectInput)

restoreLoggedRow

public void restoreLoggedRow(java.lang.Object[] row,
                             LimitObjectInput in)
                      throws StandardException,
                             java.io.IOException
Restore the row stored in the optional data of the log record.

Parameters:
row - an IN/OUT parameter, caller passed in the row with the correct column number and type, the log operation will restore the row with the optional data stored in the log record.
Throws:
java.io.IOException - error reading from log stream
StandardException - Standard Cloudscape error policy
See Also:
LogicalUndo

restoreMe

public void restoreMe(Transaction xact,
                      BasePage undoPage,
                      LogInstant CLRinstant,
                      LimitObjectInput in)
               throws StandardException,
                      java.io.IOException
restore the before image of the page

Specified by:
restoreMe in class PageBasicOperation
Parameters:
xact - the Transaction doing the rollback
undoPage - the page to rollback changes on
CLRinstant - the log instant of this (PageUndo) operation
in - optional data for the rollback operation
Throws:
StandardException - Standard Cloudscape Error Policy
java.io.IOException - problem reading the complete log record from the input stream

getPreparedLog

public ByteArray getPreparedLog()
Description copied from interface: Loggable
The log operations are responsible to create the ByteArray, and the log operations should write out any optional data for the change to the ByteArray. The ByteArray can be prepared when the log operation is constructed, or it can be prepared when getPreparedLog() is called. Called by the log manager to allow the log operation to pass the buffer which contains optional data that will be available in to doMe() methods.

Specified by:
getPreparedLog in interface Loggable
Overrides:
getPreparedLog in class PageBasicOperation

getNextStartColumn

public int getNextStartColumn()

writeOptionalDataToBuffer

private void writeOptionalDataToBuffer(RawTransaction t,
                                       DynamicByteArrayOutputStream logBuffer,
                                       java.lang.Object[] row,
                                       FormatableBitSet validColumns,
                                       boolean isLongColumn,
                                       int realStartColumn,
                                       int realSpaceOnPage,
                                       int overflowThreshold)
                                throws StandardException,
                                       java.io.IOException
Writes out the row that is to be inserted as the optional data.

Throws:
java.io.IOException - Can be thrown by any of the methods of ObjectOutput
StandardException - Standard Cloudscape policy.

toString

public java.lang.String toString()
DEBUG: Print self.

Overrides:
toString in class PageBasicOperation

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.