Package db

Class DBRecord

java.lang.Object
db.DBRecord
All Implemented Interfaces:
Comparable<DBRecord>
Direct Known Subclasses:
SparseRecord

public class DBRecord extends Object implements Comparable<DBRecord>
Record provides a portable container for data associated with a fixed schema. A record instance contains both a primary key and zero or more data fields.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    compareFieldTo(int columnIndex, Field value)
    Compare two field values.
    int
    compareTo(DBRecord otherRec)
    Compares the key associated with this record with the key of another record (obj).
    Obtain a copy of this record object.
    boolean
    Compare the content of two Records for equality.
    boolean
    fieldEquals(int columnIndex, Field field)
    Determine if the specified field equals the field associated with the specified columnIndex.
    byte[]
    getBinaryData(int colIndex)
    Get the binary data array for the specified field.
    boolean
    getBooleanValue(int colIndex)
    Get the boolean value for the specified field.
    byte
    getByteValue(int colIndex)
    Get the byte value for the specified field.
    int
    Get the number of columns contained within this record.
    getFieldValue(int columnIndex)
    Get a copy of the specified field value.
    int
    getIntValue(int colIndex)
    Get the integer value for the specified field.
    long
    Get the record primary key.
    Get the record primary key as a Field object.
    long
    getLongValue(int colIndex)
    Get the long value for the specified field.
    short
    getShortValue(int colIndex)
    Get the short value for the specified field.
    getString(int colIndex)
    Get the string value for the specified field.
    int
     
    boolean
    Determine if this record's schema is the same as another record's schema.
    boolean
    hasSameSchema(Schema otherSchema)
    Determine if this record's schema is compatible with the specified schema.
    protected void
     
    boolean
    Determine if data fields have been modified since the last write occurred.
    final int
    Get the stored record length.
    void
    read(Buffer buf, int offset)
    Read the record field data from the specified buffer and offset
    void
    setBinaryData(int colIndex, byte[] bytes)
    Set the binary data array for the specified field.
    void
    setBooleanValue(int colIndex, boolean value)
    Set the boolean value for the specified field.
    void
    setByteValue(int colIndex, byte value)
    Set the byte value for the specified field.
    void
    setField(int colIndex, Field value)
    Set the field value for the specified field.
    void
    setIntValue(int colIndex, int value)
    Set the integer value for the specified field.
    void
    setKey(long key)
    Set the primary key associated with this record.
    void
    Set the primary key associated with this record.
    void
    setLongValue(int colIndex, long value)
    Set the long value for the specified field.
    void
    setNull(int colIndex)
    Set the field to a null state.
    void
    setShortValue(int colIndex, short value)
    Set the short value for the specified field.
    void
    setString(int colIndex, String str)
    Set the string value for the specified field.
     
    void
    write(Buffer buf, int offset)
    Write the record fields to the specified buffer and offset.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • invalidateLength

      protected void invalidateLength()
    • setKey

      public void setKey(long key)
      Set the primary key associated with this record.
      Parameters:
      key - primary key
    • setKey

      public void setKey(Field key)
      Set the primary key associated with this record.
      Parameters:
      key - primary key
    • getKey

      public long getKey()
      Get the record primary key.
      Returns:
      primary key as long value.
    • getKeyField

      public Field getKeyField()
      Get the record primary key as a Field object.
      Returns:
      primary key as a field object.
    • hasSameSchema

      public boolean hasSameSchema(DBRecord otherRec)
      Determine if this record's schema is the same as another record's schema. This check factors column count and column field types only.
      Parameters:
      otherRec - another record
      Returns:
      true if records schemas are the same
    • hasSameSchema

      public boolean hasSameSchema(Schema otherSchema)
      Determine if this record's schema is compatible with the specified schema. This check factors column count and column field types only. Index and sparse column checks are not performed.
      Parameters:
      otherSchema - other schema
      Returns:
      true if records schemas are the same
    • getColumnCount

      public int getColumnCount()
      Get the number of columns contained within this record.
      Returns:
      number of field columns.
    • getFieldValue

      public Field getFieldValue(int columnIndex)
      Get a copy of the specified field value.
      Parameters:
      columnIndex - field index
      Returns:
      Field field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
    • setField

      public void setField(int colIndex, Field value)
      Set the field value for the specified field.
      Parameters:
      colIndex - field index
      value - field value (null permitted for sparse column only)
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalArgumentException - if value type does not match column field type.
    • fieldEquals

      public boolean fieldEquals(int columnIndex, Field field)
      Determine if the specified field equals the field associated with the specified columnIndex.
      Parameters:
      columnIndex - field index
      field - field value to compare with
      Returns:
      true if the fields are equal, else false.
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
    • compareFieldTo

      public int compareFieldTo(int columnIndex, Field value)
      Compare two field values.
      Parameters:
      columnIndex - the field index within this record
      value - another field value to compared
      Returns:
      0 if equals, a negative number if this record's field is less than the specified value, or a positive number if this record's field is greater than the specified value.
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
    • copy

      public DBRecord copy()
      Obtain a copy of this record object.
      Returns:
      Record
    • length

      public final int length()
      Get the stored record length. This method is used to determine the space required to store the data fields within this record when written to a standard Buffer.
      Returns:
      int stored record length
    • getLongValue

      public long getLongValue(int colIndex)
      Get the long value for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support long data access
    • setLongValue

      public void setLongValue(int colIndex, long value)
      Set the long value for the specified field.
      Parameters:
      colIndex - field index
      value - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support long data access
    • getIntValue

      public int getIntValue(int colIndex)
      Get the integer value for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support integer data access
    • setIntValue

      public void setIntValue(int colIndex, int value)
      Set the integer value for the specified field.
      Parameters:
      colIndex - field index
      value - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support integer data access
    • getShortValue

      public short getShortValue(int colIndex)
      Get the short value for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support short data access
    • setShortValue

      public void setShortValue(int colIndex, short value)
      Set the short value for the specified field.
      Parameters:
      colIndex - field index
      value - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support short data access
    • getByteValue

      public byte getByteValue(int colIndex)
      Get the byte value for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support byte data access
    • setByteValue

      public void setByteValue(int colIndex, byte value)
      Set the byte value for the specified field.
      Parameters:
      colIndex - field index
      value - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support byte data access
    • getBooleanValue

      public boolean getBooleanValue(int colIndex)
      Get the boolean value for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support boolean data access
    • setBooleanValue

      public void setBooleanValue(int colIndex, boolean value)
      Set the boolean value for the specified field.
      Parameters:
      colIndex - field index
      value - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support boolean data access
    • getBinaryData

      public byte[] getBinaryData(int colIndex)
      Get the binary data array for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field data
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support binary data access
    • setBinaryData

      public void setBinaryData(int colIndex, byte[] bytes)
      Set the binary data array for the specified field.
      Parameters:
      colIndex - field index
      bytes - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support binary data access or incorrect number of bytes provided
    • setNull

      public void setNull(int colIndex)
      Set the field to a null state. For a non-sparse fixed-length column field this will set the the value to zero and the null state will not be persisted when stored.
      Parameters:
      colIndex - field index
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
    • getString

      public String getString(int colIndex)
      Get the string value for the specified field.
      Parameters:
      colIndex - field index
      Returns:
      field data
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support string data access
    • setString

      public void setString(int colIndex, String str)
      Set the string value for the specified field.
      Parameters:
      colIndex - field index
      str - field value
      Throws:
      IndexOutOfBoundsException - if invalid columnIndex is specified
      IllegalFieldAccessException - if field does support string data access
    • write

      public void write(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException
      Write the record fields to the specified buffer and offset.
      Parameters:
      buf - data buffer
      offset - buffer offset
      Throws:
      IndexOutOfBoundsException - if invalid offset is specified
      IOException - thrown if IO error occurs
    • read

      public void read(Buffer buf, int offset) throws IndexOutOfBoundsException, IOException
      Read the record field data from the specified buffer and offset
      Parameters:
      buf - data buffer
      offset - buffer offset
      Throws:
      IndexOutOfBoundsException - if invalid offset is specified
      IOException - thrown if IO error occurs
    • isDirty

      public boolean isDirty()
      Determine if data fields have been modified since the last write occurred.
      Returns:
      true if the field data has not been saved, else false.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Compare the content of two Records for equality.
      Overrides:
      equals in class Object
      See Also:
    • compareTo

      public int compareTo(DBRecord otherRec)
      Compares the key associated with this record with the key of another record (obj).
      Specified by:
      compareTo in interface Comparable<DBRecord>
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object