Top Description Inners Fields Constructors Methods
org.apache.derby.impl.store.raw.data

public final Class StoredRecordHeader

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.store.raw.PageKey, .RecordHandle, java.io.IOException, .EOFException, .OutputStream, org.apache.derby.iapi.services.io.CompressedNumber

A class StoredPage uses to cache record headers by passing instances to BasePage, and to write stored versions of record headers. Format

1 byte          - status
compressed int  - record identifier

compressed long - overflow page } only if hasOverflow() is true
compressed int  - overflow id   }     "        "           "

compressed int  - first field   } only if hasFirstField set - otherwise 0

compressed int  - number of fields in this portion - only if hasOverflow()
                            is false OR hasFirstField is true - otherwise 0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
StoredRecordHeader.OverflowInfo

Class which holds the fields overflowId, overflowPage and firstField, which are not needed when there is no overflow.

Field Summary

Modifier and TypeField and Description
protected RecordHandle
handle

A record handle that can represent the record, may be null.

protected int
id

Actual identifier of the record MT - Mutable

public static final int
MAX_OVERFLOW_ONLY_REC_SIZE

maximum length for row containing just an overflow pointer.

protected int
numberFields

number of fields in the row.

private StoredRecordHeader.OverflowInfo
private static final byte
RECORD_DELETED

Status bits for the record header: RECORD_DELETED - used to indicate the record has been deleted RECORD_OVERFLOW - used to indicate the record has been overflowed, it will point to the overflow page and ID RECORD_HAS_FIRST_FIELD - used to indicate that firstField is stored.

private static final byte
private static final byte
private static final byte
private byte
status

Status of the record.

Constructor Summary

AccessConstructor and Description
public
StoredRecordHeader()

Constructors for This class:

public
StoredRecordHeader(int id, int numberFields)

public
StoredRecordHeader(byte[] data, int offset)

public

Method Summary

Modifier and TypeMethod and Description
public int
protected RecordHandle
getHandle(PageKey pageId, int current_slot)

Get a record handle for the record.

public final int
getId()

Get the record identifier MT - thread safe

public int
public int
public long
public static final int

Returns:

length of encoded record id on disk.
getStoredSizeRecordId
(int record_id)

Return length on disk of the record id portion of the record header Record id is part of the record header and is stored in an internal compressed format.

protected final boolean
public final boolean
public final boolean
isDeleted()

Get the deleted state of the record.

public void
private void
read(byte[] data, int offset)

private int
readFirstField(byte[] data, int offset)

private void
readNumberFields(byte[] data, int offset)

private int
readOverFlowId(byte[] data, int offset)

private int
readOverFlowPage(byte[] data, int offset)

public int
setDeleted(boolean deleteTrue)

Set the deleted state of the record.

public void
setFirstField(int firstField)

public final void
setId(int id)

public final void
setNumberFields(int numberFields)

public void
public void
public int

Returns:

The length of the record header.
size
()

return the size of the record header.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public int
write(OutputStream out)

Public Methods implmenting read/write of Storable Interface:

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

handleback to summary
protected RecordHandle handle

A record handle that can represent the record, may be null.

idback to summary
protected int id

Actual identifier of the record
MT - Mutable

MAX_OVERFLOW_ONLY_REC_SIZEback to summary
public static final int MAX_OVERFLOW_ONLY_REC_SIZE

maximum length for row containing just an overflow pointer.

The maximum stored length of a row that just contains an overflow pointer is 17 bytes: stored sizeof(status byte) : 1 + stored sizeof(record id) : 4 + max stored size overflow page ptr: 8 + max stored size overflow record id: 4

numberFieldsback to summary
protected int numberFields

number of fields in the row.

overflowback to summary
private StoredRecordHeader.OverflowInfo overflow
RECORD_DELETEDback to summary
private static final byte RECORD_DELETED

Status bits for the record header: RECORD_DELETED - used to indicate the record has been deleted RECORD_OVERFLOW - used to indicate the record has been overflowed, it will point to the overflow page and ID RECORD_HAS_FIRST_FIELD - used to indicate that firstField is stored. When RECORD_OVERFLOW and RECORD_HAS_FIRST_FIELD both are set, part of record is on the page, the record header also stores the overflow pointer to the next part of the record. RECORD_VALID_MASK - A mask of valid bits that can be set currently, such that the following assert can be made: ASSERT((status & ~RECORD_VALID_MASK) == 0))

RECORD_HAS_FIRST_FIELDback to summary
private static final byte RECORD_HAS_FIRST_FIELD
RECORD_OVERFLOWback to summary
private static final byte RECORD_OVERFLOW
RECORD_VALID_MASKback to summary
private static final byte RECORD_VALID_MASK
statusback to summary
private byte status

Status of the record. See above for description of fields: RECORD_DELETED RECORD_OVERFLOW RECORD_HAS_FIRST_FIELD RECORD_VALID_MASK
MT - Mutable - single thread required.

Constructor Detail

StoredRecordHeaderback to summary
public StoredRecordHeader()

Constructors for This class:

StoredRecordHeaderback to summary
public StoredRecordHeader(int id, int numberFields)
StoredRecordHeaderback to summary
public StoredRecordHeader(byte[] data, int offset)
StoredRecordHeaderback to summary
public StoredRecordHeader(StoredRecordHeader loadTargetFrom)

Method Detail

getFirstFieldback to summary
public int getFirstField()
getHandleback to summary
protected RecordHandle getHandle(PageKey pageId, int current_slot)

Get a record handle for the record.


MT - single thread required

getIdback to summary
public final int getId()

Get the record identifier
MT - thread safe

getNumberFieldsback to summary
public int getNumberFields()
getOverflowIdback to summary
public int getOverflowId()
getOverflowPageback to summary
public long getOverflowPage()
getStoredSizeRecordIdback to summary
public static final int getStoredSizeRecordId(int record_id)

Return length on disk of the record id portion of the record header Record id is part of the record header and is stored in an internal compressed format. The length of this format depends on the value of the record id.

Returns:int

length of encoded record id on disk.

hasFirstFieldback to summary
protected final boolean hasFirstField()
hasOverflowback to summary
public final boolean hasOverflow()
isDeletedback to summary
public final boolean isDeleted()

Get the deleted state of the record.


MT - single thread required

readback to summary
public void read(ObjectInput in) throws IOException
readback to summary
private void read(byte[] data, int offset)
readFirstFieldback to summary
private int readFirstField(byte[] data, int offset)
readNumberFieldsback to summary
private void readNumberFields(byte[] data, int offset)
readOverFlowIdback to summary
private int readOverFlowId(byte[] data, int offset)
readOverFlowPageback to summary
private int readOverFlowPage(byte[] data, int offset)
setDeletedback to summary
public int setDeleted(boolean deleteTrue)

Set the deleted state of the record.

return 1, if delete status from not deleted to deleted return -1, if delete status from deleted to not deleted return 0, if status unchanged.
MT - single thread required

setFirstFieldback to summary
public void setFirstField(int firstField)
setIdback to summary
public final void setId(int id)
setNumberFieldsback to summary
public final void setNumberFields(int numberFields)
setOverflowDetailsback to summary
public void setOverflowDetails(RecordHandle overflowHandle)
setOverflowFieldsback to summary
public void setOverflowFields(StoredRecordHeader loadFromTarget)
sizeback to summary
public int size()

return the size of the record header.

Calculates the size of the record header, mostly used to allow a reader to skip over the record header and position on the 1st field of the record.

This low level routine is performance critical to processing lots of rows, so calls to CompressNumber have been hand inlined.

Returns:int

The length of the record header.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

writeback to summary
public int write(OutputStream out) throws IOException

Public Methods implmenting read/write of Storable Interface:

org.apache.derby.impl.store.raw.data back to summary

private Class StoredRecordHeader.OverflowInfo

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.derby.impl.store.raw.data.StoredRecordHeader.OverflowInfo

Class which holds the fields overflowId, overflowPage and firstField, which are not needed when there is no overflow. These fields are factored out to save Java heap space (see DERBY-3130).

Field Summary

Modifier and TypeField and Description
private int
firstField

If (hasFirstField()) then this field is the number of the column in the orginal row which is now stored as the first field in this row.

private int
overflowId

If (hasOverflow()) then this is the id of the row on page overflowPage where the next portion of the row can be found.

private long
overflowPage

If (hasOverflow()) then this is the page where where the next portion of the row can be found.

Constructor Summary

AccessConstructor and Description
private
OverflowInfo()

Create an empty OverflowInfo object.

private
OverflowInfo(StoredRecordHeader.OverflowInfo from)

Create a copy of a OverflowInfo object.

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

firstFieldback to summary
private int firstField

If (hasFirstField()) then this field is the number of the column in the orginal row which is now stored as the first field in this row. This row is 2nd through N'th portion of a long row. For example if a row has its first 3 fields on page 0 and its next 3 fields on page 1, then the record header of the row portion on page 1 will have hasFirstField() set to true, and the value would be 4, indicating that the 4th field of the row is stored as the 1st field of the partial row portion stored on page 1.

overflowIdback to summary
private int overflowId

If (hasOverflow()) then this is the id of the row on page overflowPage where the next portion of the row can be found. In this case there are no "real" fields on this page. This situation comes about if a row has been updated such that the real first field no longer fits on the head page.

overflowPageback to summary
private long overflowPage

If (hasOverflow()) then this is the page where where the next portion of the row can be found. In this case there are no "real" fields on this page.

Constructor Detail

OverflowInfoback to summary
private OverflowInfo()

Create an empty OverflowInfo object.

OverflowInfoback to summary
private OverflowInfo(StoredRecordHeader.OverflowInfo from)

Create a copy of a OverflowInfo object.