Package uk.co.sculptor.kflibjava
Class KeyedFile
java.lang.Object
uk.co.sculptor.kflibjava.KeyedFile
- All Implemented Interfaces:
AutoCloseable
Represents the KeyedFile object that contains all the indexes and fields.
Note: This class implements theAutoCloseable
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
Modifier and TypeClassDescriptionstatic 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 TypeMethodDescriptionvoid
Turn batch read mode off.void
Turn batch read mode on.boolean
check()
Check if record read and if update mode locked.void
Clear records in read-ahead buffer.void
Initialise record buffer.void
close()
Close All the objects hanging from the KeyedFile and close the key file on the server.void
Close file handles.int
count()
Count the number of records/keys in a file/index.void
Delete the current record which must have been read and locked.void
find()
Find first record with matching key, locking the record and not waiting when the record is in use.void
findu()
Find first record with matching key not locking the record.void
findw()
Find first record with matching key, locking the record and waiting when the record is in use.void
flush()
Flush file.int
Returns KeyedFile errNumFinds the specified field and returns the Field object that represents the specified field.Returns KeyedFile filelock flagReturns KeyedFile fileNameFinds the specified index and returns the FileIndex object that represents the specified index.Returns KeyedFile indexlock flagint
Returns KeyedFile main index keylenReturns KeyedFile mirrorKfStatgetMode()
Returns KeyedFile mode flagReturns KeyedFile options flagsint
Returns KeyedFile reclenReturns KeyedFile recordlock flagint
Returns KeyedFile syserrvoid
insert()
Insert a new record.boolean
Returns KeyedFile handlesClosedboolean
Returns KeyedFile indexOnly flagvoid
lockFile
(KeyedFile.LockMode lockMode) Lock file.void
match()
Find next record with matching key, locking the record and not waiting when the record is in use.void
matchu()
Find next record with matching key not locking the record.void
matchw()
Find next record with matching key, locking the record and waiting when the record is in use.void
mirror()
Mirror the KeyedFile update to an existing table in the mirrored database or create if not presentvoid
mirror
(KeyedFile.Mode mode) Mirror the KeyedFilevoid
next()
Read next record, locking the record and not waiting when the record is in use.void
nextKey()
Read next key.void
nextSeq()
Read next sequential record, locking the record and not waiting when the record is in use.void
nextSequ()
Read next sequential record not locking the record.void
nextSeqw()
Read next sequential record, locking the record and waiting when the record is in use.void
nextu()
Read next record not locking the record.void
nextw()
Read next record, locking the record and waiting when the record is in use.void
prev()
Read previous record, locking the record and not waiting when the record is in use.void
prevKey()
Read previous key.void
prevu()
Read previous record not locking the record.void
prevw()
Read previous record, locking the record and waiting when the record is in use.void
read()
Read record for given key, locking the record and not waiting when the record is in use.void
readKey()
Read key.void
readLock()
Read lock a file.void
readu()
Read record for given key not locking the record.void
readw()
Read record for given key, locking the record and waiting when the record is in use.void
rewind()
Rewind (initialise the record buffer)void
testKey()
Test key exists.void
unlock()
Unlock file or record if locked.void
Unlock record if locked.void
wind()
Wind (initialise the record contents)void
write()
Write back and unlock recordvoid
writel()
Write back and lock record.void
Write lock a file.
-
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
Close All the objects hanging from the KeyedFile and close the key file on the server.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol or on the server closing process.
-
closeHandles
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
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
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
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
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
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
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
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
Returns KeyedFile filelock flag- Returns:
- filelock flag
-
getFileName
Returns KeyedFile fileName- Returns:
- fileName
-
getIndex
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
Returns KeyedFile indexlock flag- Returns:
- indexlock flag
-
getKeyLength
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
Returns KeyedFile mirrorKfStat- Returns:
- mirrorKfStat
-
getMode
Returns KeyedFile mode flag- Returns:
- mode flag
-
getOptions
Returns KeyedFile options flags- Returns:
- options flags
-
getRecordLength
public int getRecordLength()Returns KeyedFile reclen- Returns:
- reclen
-
getRecordlock
Returns KeyedFile recordlock flag- Returns:
- recordlock flag
-
getSyserr
public int getSyserr()Returns KeyedFile syserr- Returns:
- syserr
-
insert
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
-