Class KeyedFile

java.lang.Object
uk.co.sculptor.kflibjava.KeyedFile
All Implemented Interfaces:
AutoCloseable

public class KeyedFile extends Object implements AutoCloseable

Represents the KeyedFile object that contains all the indexes and fields.

Note: This class implements the AutoCloseable interface, meaning that an object may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.
Author:
Marcos Gutierrez Batz
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    KeyedFile batch type enumerator used to know which kind of information is in the batch buffer.
    static enum 
    KeyedFile operation status values.
    static enum 
    KeyedFile lock mode enumerator.
    static enum 
    KeyedFile open mode enumerator.
    static enum 
    KeyedFile option enumerator.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Turn batch read mode off.
    void
    Turn batch read mode on.
    boolean
    Check if record read and if update mode locked.
    void
    Clear records in read-ahead buffer.
    void
    Initialise record buffer.
    void
    Close All the objects hanging from the KeyedFile and close the key file on the server.
    void
    Close file handles.
    int
    Count the number of records/keys in a file/index.
    void
    Delete the current record which must have been read and locked.
    void
    Find first record with matching key, locking the record and not waiting when the record is in use.
    void
    Find first record with matching key not locking the record.
    void
    Find first record with matching key, locking the record and waiting when the record is in use.
    void
    Flush file.
    int
    Returns KeyedFile errNum
    getField(String fieldName)
    Finds the specified field and returns the Field object that represents the specified field.
    Returns KeyedFile filelock flag
    Returns KeyedFile fileName
    getIndex(String indexName)
    Finds the specified index and returns the FileIndex object that represents the specified index.
    Returns KeyedFile indexlock flag
    int
    Returns KeyedFile main index keylen
    Returns KeyedFile mirrorKfStat
    Returns KeyedFile mode flag
    Returns KeyedFile options flags
    int
    Returns KeyedFile reclen
    Returns KeyedFile recordlock flag
    int
    Returns KeyedFile syserr
    void
    Insert a new record.
    boolean
    Returns KeyedFile handlesClosed
    boolean
    Returns KeyedFile indexOnly flag
    void
    Lock file.
    void
    Find next record with matching key, locking the record and not waiting when the record is in use.
    void
    Find next record with matching key not locking the record.
    void
    Find next record with matching key, locking the record and waiting when the record is in use.
    void
    Mirror the KeyedFile update to an existing table in the mirrored database or create if not present
    void
    Mirror the KeyedFile
    void
    Read next record, locking the record and not waiting when the record is in use.
    void
    Read next key.
    void
    Read next sequential record, locking the record and not waiting when the record is in use.
    void
    Read next sequential record not locking the record.
    void
    Read next sequential record, locking the record and waiting when the record is in use.
    void
    Read next record not locking the record.
    void
    Read next record, locking the record and waiting when the record is in use.
    void
    Read previous record, locking the record and not waiting when the record is in use.
    void
    Read previous key.
    void
    Read previous record not locking the record.
    void
    Read previous record, locking the record and waiting when the record is in use.
    void
    Read record for given key, locking the record and not waiting when the record is in use.
    void
    Read key.
    void
    Read lock a file.
    void
    Read record for given key not locking the record.
    void
    Read record for given key, locking the record and waiting when the record is in use.
    void
    Rewind (initialise the record buffer)
    void
    Test key exists.
    void
    Unlock file or record if locked.
    void
    Unlock record if locked.
    void
    Wind (initialise the record contents)
    void
    Write back and unlock record
    void
    Write back and lock record.
    void
    Write lock a file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • batchReadOff

      public void batchReadOff()
      Turn batch read mode off.
    • batchReadOn

      public void batchReadOn()
      Turn batch read mode on.
    • check

      public boolean check()
      Check if record read and if update mode locked.
      Returns:
      True when record and if update mode locked
    • clearBatch

      public void clearBatch()
      Clear records in read-ahead buffer.
    • clearData

      public void clearData()
      Initialise record buffer.
    • close

      public void close() throws IOException, KfException
      Close All the objects hanging from the KeyedFile and close the key file on the server.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • closeHandles

      public void closeHandles() throws IOException, KfException
      Close file handles.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • count

      public int count() throws IOException, KfException
      Count the number of records/keys in a file/index.
      Returns:
      The number of records.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • deleteRecord

      public void deleteRecord() throws IOException, KfException
      Delete the current record which must have been read and locked.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • find

      public void find() throws IOException, KfException
      Find first record with matching key, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • findu

      public void findu() throws IOException, KfException
      Find first record with matching key not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • findw

      public void findw() throws IOException, KfException
      Find first record with matching key, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • flush

      public void flush() throws IOException, KfException
      Flush file.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • getErrNum

      public int getErrNum()
      Returns KeyedFile errNum
      Returns:
      errNum
    • getField

      public Field getField(String fieldName)
      Finds the specified field and returns the Field object that represents the specified field.
      Parameters:
      fieldName - the field we want to get.
      Returns:
      The specified Field or null if not found.
    • getFileLock

      public KeyedFile.LockMode getFileLock()
      Returns KeyedFile filelock flag
      Returns:
      filelock flag
    • getFileName

      public String getFileName()
      Returns KeyedFile fileName
      Returns:
      fileName
    • getIndex

      public FileIndex getIndex(String indexName)
      Finds the specified index and returns the FileIndex object that represents the specified index.
      Parameters:
      indexName - the index we want to get.
      Returns:
      The specified FileIndex or null if not found.
    • getIndexLock

      public KeyedFile.LockMode getIndexLock()
      Returns KeyedFile indexlock flag
      Returns:
      indexlock flag
    • getKeyLength

      public int getKeyLength() throws KfException
      Returns KeyedFile main index keylen
      Returns:
      The main index keylen
      Throws:
      KfException - When a main index is not defined (it'll mean an internal error or call the function after a close()
    • getMirrorKfStat

      public KeyedFile.KfStat getMirrorKfStat()
      Returns KeyedFile mirrorKfStat
      Returns:
      mirrorKfStat
    • getMode

      public KeyedFile.Mode getMode()
      Returns KeyedFile mode flag
      Returns:
      mode flag
    • getOptions

      public EnumSet<KeyedFile.Option> getOptions()
      Returns KeyedFile options flags
      Returns:
      options flags
    • getRecordLength

      public int getRecordLength()
      Returns KeyedFile reclen
      Returns:
      reclen
    • getRecordlock

      public KeyedFile.LockMode getRecordlock()
      Returns KeyedFile recordlock flag
      Returns:
      recordlock flag
    • getSyserr

      public int getSyserr()
      Returns KeyedFile syserr
      Returns:
      syserr
    • insert

      public void insert() throws IOException, KfException
      Insert a new record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • isHandlesClosed

      public boolean isHandlesClosed()
      Returns KeyedFile handlesClosed
      Returns:
      the handlesClosed
    • isIndexOnly

      public boolean isIndexOnly()
      Returns KeyedFile indexOnly flag
      Returns:
      indexOnly flag
    • lockFile

      public void lockFile(KeyedFile.LockMode lockMode) throws IOException, KfException
      Lock file.
      Parameters:
      lockMode - Locking mode to apply.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • match

      public void match() throws IOException, KfException
      Find next record with matching key, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • matchu

      public void matchu() throws IOException, KfException
      Find next record with matching key not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • matchw

      public void matchw() throws IOException, KfException
      Find next record with matching key, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • mirror

      public void mirror() throws IOException, KfException
      Mirror the KeyedFile update to an existing table in the mirrored database or create if not present
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol.
    • mirror

      public void mirror(KeyedFile.Mode mode) throws IOException, KfException
      Mirror the KeyedFile
      Parameters:
      mode - Mirror mode:
      • Mode.READ: Stop any existing mirror operations with this file
      • Mode.CREATE: Create or recreate a matching table in the mirrored database
      • Mode.UPDATE: to update an existing table in the mirrored database or create if not present
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol.
    • next

      public void next() throws IOException, KfException
      Read next record, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • nextKey

      public void nextKey() throws IOException, KfException
      Read next key.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • nextSeq

      public void nextSeq() throws IOException, KfException
      Read next sequential record, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • nextSequ

      public void nextSequ() throws IOException, KfException
      Read next sequential record not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • nextSeqw

      public void nextSeqw() throws IOException, KfException
      Read next sequential record, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • nextu

      public void nextu() throws IOException, KfException
      Read next record not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • nextw

      public void nextw() throws IOException, KfException
      Read next record, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • prev

      public void prev() throws IOException, KfException
      Read previous record, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • prevKey

      public void prevKey() throws IOException, KfException
      Read previous key.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • prevu

      public void prevu() throws IOException, KfException
      Read previous record not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • prevw

      public void prevw() throws IOException, KfException
      Read previous record, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • read

      public void read() throws IOException, KfException
      Read record for given key, locking the record and not waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • readKey

      public void readKey() throws IOException, KfException
      Read key.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • readLock

      public void readLock() throws IOException, KfException
      Read lock a file.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • readu

      public void readu() throws IOException, KfException
      Read record for given key not locking the record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • readw

      public void readw() throws IOException, KfException
      Read record for given key, locking the record and waiting when the record is in use.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • rewind

      public void rewind()
      Rewind (initialise the record buffer)
    • testKey

      public void testKey() throws IOException, KfException
      Test key exists.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • unlock

      public void unlock() throws IOException, KfException
      Unlock file or record if locked.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • unlockRecord

      public void unlockRecord() throws IOException, KfException
      Unlock record if locked. Keep file lock.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • wind

      public void wind()
      Wind (initialise the record contents)
    • write

      public void write() throws IOException, KfException
      Write back and unlock record
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • writel

      public void writel() throws IOException, KfException
      Write back and lock record.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.
    • writeLock

      public void writeLock() throws IOException, KfException
      Write lock a file.
      Throws:
      IOException - Any error received by writing/reading the socket.
      KfException - Any error on the KfServer protocol or on the server closing process.