com.objectwave.persist.file
Class RecordHeader

java.lang.Object
  |
  +--com.objectwave.persist.file.RecordHeader

public class RecordHeader
extends java.lang.Object

Version:
$Id: RecordHeader.java,v 2.1 2002/03/23 13:42:10 dave_hoag Exp $
Author:
Dave Hoag

Nested Class Summary
static class RecordHeader.Test
          Unit tests.
 
Method Summary
static RecordHeader create(java.io.RandomAccessFile file)
          Create instances from the RandomAccessFile
 long getBytesToNextRecord()
           
 byte[] getData(java.io.RandomAccessFile file)
          Get the data from the file.
 java.lang.String getPrimaryKey()
          The pkey read from the record, or null if this record is not valid.
static RecordHeader insert(java.lang.String primaryKeyField, java.io.RandomAccessFile file, byte[] data)
          Write a new record the random access file.
 void invalidate(java.io.RandomAccessFile file)
           
 boolean isValid()
           
 void setPrimaryKey(java.lang.String value)
           
 void skip(java.io.RandomAccessFile file)
          Move the FilePointer by the appropriate amount to skip this record.
 void update(java.io.RandomAccessFile file, byte[] data)
          A 'db' update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static RecordHeader create(java.io.RandomAccessFile file)
                           throws java.io.IOException
Create instances from the RandomAccessFile

Parameters:
file - RandomAccessFile The file upon which to write.
Returns:
RecordHeader A new instance read from the provided file
Throws:
java.io.IOException

insert

public static RecordHeader insert(java.lang.String primaryKeyField,
                                  java.io.RandomAccessFile file,
                                  byte[] data)
                           throws java.io.IOException
Write a new record the random access file.

Parameters:
primaryKeyField - Some string value that will uniquely identify this row.
file - RandomAccessFile The file upon which to write.
data - byte [] The data from the persistent object.
Returns:
Throws:
java.io.IOException

setPrimaryKey

public void setPrimaryKey(java.lang.String value)
Parameters:
value - The new PrimaryKey value

getData

public byte[] getData(java.io.RandomAccessFile file)
               throws java.io.IOException
Get the data from the file. Assumes pointer of file is at start of data.

Parameters:
file - RandomAccessFile The file upon which to get the data.
Returns:
The Data value
Throws:
java.io.IOException

isValid

public boolean isValid()
Returns:
boolean

getPrimaryKey

public java.lang.String getPrimaryKey()
The pkey read from the record, or null if this record is not valid.

Returns:
The PrimaryKey value

getBytesToNextRecord

public long getBytesToNextRecord()
Returns:
The BytesToNextRecord value

skip

public void skip(java.io.RandomAccessFile file)
          throws java.io.IOException
Move the FilePointer by the appropriate amount to skip this record.

Parameters:
file - RandomAccessFile The file upon which to skip.
Throws:
java.io.IOException

update

public void update(java.io.RandomAccessFile file,
                   byte[] data)
            throws java.io.EOFException,
                   java.io.IOException
A 'db' update. If the record can not be updated an exception is generated and the record is invalidated.

Parameters:
file - RandomAccessFile The file upon which to write.
data -
Throws:
java.io.EOFException - - If trying to write more data than is allowed in the current record.
java.io.IOException

invalidate

public void invalidate(java.io.RandomAccessFile file)
                throws java.io.IOException
Parameters:
file - RandomAccessFile The file upon which to write.
Throws:
java.io.IOException