org.h2.store
Class DataPage

java.lang.Object
  extended by org.h2.store.DataPage
Direct Known Subclasses:
Data

public class DataPage
extends java.lang.Object

A data page is a byte buffer that contains persistent data of a row or index page.


Field Summary
protected  byte[] data
          The data itself.
protected  DataHandler handler
          The data handler responsible for lob objects.
static int LENGTH_FILLER
          The space required for the checksum and additional fillers.
static int LENGTH_INT
          The length of an integer value.
static int LENGTH_LONG
          The length of a long value.
protected  int pos
          The current write or read position.
 
Constructor Summary
protected DataPage(DataHandler handler, byte[] data)
           
 
Method Summary
 void check(int len)
          Test if the checksum is correct.
 void checkCapacity(int plus)
          Check if there is still enough capacity in the buffer.
static DataPage create(DataHandler handler, byte[] buff)
          Create a new data page using the given data for the given handler.
static DataPage create(DataHandler handler, int capacity)
          Create a new data page for the given handler.
 void fill(int len)
          Increase the size to the given length.
 void fillAligned()
          Fill up the buffer with empty space and an (initially empty) checksum until the size is a multiple of Constants.FILE_BLOCK_SIZE.
 byte[] getBytes()
          Get the byte array used for this page.
 int getStringLen(java.lang.String s)
          Get the length of a String value.
 int getValueLen(Value v)
          Calculate the number of bytes required to encode the given value.
 int length()
          Get the current write position of this data page, which is the current length.
 void read(byte[] buff, int off, int len)
          Copy a number of bytes to the given buffer from the current position.
 int readByte()
          Read one single byte.
 DataPage readDataPageNoSize()
          Read a data page from this page.
 int readInt()
          Read an integer at the current position.
 long readLong()
          Read a long value.
 int readShortInt()
          Read an short integer at the current position.
 java.lang.String readString()
          Read a String value.
 Value readValue()
          Read a value.
 void reset()
          Set the position to 0.
 void setInt(int pos, int x)
          Update an integer at the given position.
 void setPos(int pos)
          Set the current read / write position.
 void updateChecksum()
          Calculate the checksum and write.
 void write(byte[] buff, int off, int len)
          Append a number of bytes to this data page.
 void writeByte(byte x)
          Append one single byte.
 void writeDataPageNoSize(DataPage page)
          Append the contents of the given data page to this page.
 void writeInt(int x)
          Write an integer at the current position.
 void writeLong(long x)
          Append a long value.
 void writeShortInt(int x)
          Write a short integer at the current position.
 void writeString(java.lang.String s)
          Write a String value.
 void writeValue(Value v)
          Append a value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LENGTH_FILLER

public static final int LENGTH_FILLER
The space required for the checksum and additional fillers.

See Also:
Constant Field Values

LENGTH_INT

public static final int LENGTH_INT
The length of an integer value.

See Also:
Constant Field Values

LENGTH_LONG

public static final int LENGTH_LONG
The length of a long value.

See Also:
Constant Field Values

handler

protected DataHandler handler
The data handler responsible for lob objects.


data

protected byte[] data
The data itself.


pos

protected int pos
The current write or read position.

Constructor Detail

DataPage

protected DataPage(DataHandler handler,
                   byte[] data)
Method Detail

updateChecksum

public void updateChecksum()
Calculate the checksum and write.


check

public void check(int len)
           throws java.sql.SQLException
Test if the checksum is correct.

Parameters:
len - the number of bytes
Throws:
java.sql.SQLException - if the checksum does not match

setInt

public void setInt(int pos,
                   int x)
Update an integer at the given position. The current position is not change.

Parameters:
pos - the position
x - the value

writeInt

public void writeInt(int x)
Write an integer at the current position. The current position is incremented.

Parameters:
x - the value

readInt

public int readInt()
Read an integer at the current position. The current position is incremented.

Returns:
the value

getStringLen

public int getStringLen(java.lang.String s)
Get the length of a String value.

Parameters:
s - the value
Returns:
the length

readString

public java.lang.String readString()
Read a String value. The current position is incremented.

Returns:
the value

writeString

public void writeString(java.lang.String s)
Write a String value. The current position is incremented.

Parameters:
s - the value

fill

public void fill(int len)
Increase the size to the given length. The current position is set to the given value.

Parameters:
len - the new length

create

public static DataPage create(DataHandler handler,
                              int capacity)
Create a new data page for the given handler. The handler will decide what type of buffer is created.

Parameters:
handler - the data handler
capacity - the initial capacity of the buffer
Returns:
the data page

create

public static DataPage create(DataHandler handler,
                              byte[] buff)
Create a new data page using the given data for the given handler. The handler will decide what type of buffer is created.

Parameters:
handler - the data handler
buff - the data
Returns:
the data page

checkCapacity

public void checkCapacity(int plus)
Check if there is still enough capacity in the buffer. This method extends the buffer if required.

Parameters:
plus - the number of additional bytes required

length

public int length()
Get the current write position of this data page, which is the current length.

Returns:
the length

getBytes

public byte[] getBytes()
Get the byte array used for this page.

Returns:
the byte array

reset

public void reset()
Set the position to 0.


writeDataPageNoSize

public void writeDataPageNoSize(DataPage page)
Append the contents of the given data page to this page. The filler is not appended.

Parameters:
page - the page that will be appended

readDataPageNoSize

public DataPage readDataPageNoSize()
Read a data page from this page. The data from the current position to the end of the page is copied.

Returns:
the new page

write

public void write(byte[] buff,
                  int off,
                  int len)
Append a number of bytes to this data page.

Parameters:
buff - the data
off - the offset in the data
len - the length in bytes

read

public void read(byte[] buff,
                 int off,
                 int len)
Copy a number of bytes to the given buffer from the current position. The current position is incremented accordingly.

Parameters:
buff - the output buffer
off - the offset in the output buffer
len - the number of bytes to copy

writeByte

public void writeByte(byte x)
Append one single byte.

Parameters:
x - the value

readByte

public int readByte()
Read one single byte.

Returns:
the value

readLong

public long readLong()
Read a long value. This method reads two int values and combines them.

Returns:
the long value

writeLong

public void writeLong(long x)
Append a long value. This method writes two int values.

Parameters:
x - the value

writeValue

public void writeValue(Value v)
                throws java.sql.SQLException
Append a value.

Parameters:
v - the value
Throws:
java.sql.SQLException

getValueLen

public int getValueLen(Value v)
                throws java.sql.SQLException
Calculate the number of bytes required to encode the given value.

Parameters:
v - the value
Returns:
the number of bytes required to store this value
Throws:
java.sql.SQLException

readValue

public Value readValue()
                throws java.sql.SQLException
Read a value.

Returns:
the value
Throws:
java.sql.SQLException

fillAligned

public void fillAligned()
Fill up the buffer with empty space and an (initially empty) checksum until the size is a multiple of Constants.FILE_BLOCK_SIZE.


setPos

public void setPos(int pos)
Set the current read / write position.

Parameters:
pos - the new position

writeShortInt

public void writeShortInt(int x)
Write a short integer at the current position. The current position is incremented.

Parameters:
x - the value

readShortInt

public int readShortInt()
Read an short integer at the current position. The current position is incremented.

Returns:
the value