public class RecordFile extends RecordDatabaseObject
DatabaseObject.MetaData
Modifier and Type | Field and Description |
---|---|
Gate |
lock
Use this to synchronize operations on the RecordFile.
|
int |
minimumLines |
buffer, byteArray, dataValidator, decryptor, encryptor, encryptorNotSet, entries, file, foundEntries, INDEX_FLAG_DO_REINDEX, indexFlag, intArray, myLocale, now, openIndexes, openMode, openModifiers, SETFIELDS_MODE_ENSURE, SETFIELDS_MODE_OVERRIDE, SETFIELDS_MODE_SET, stream, stringCollator
CreatedSortName, FIELD_MODIFIER_INTEGER_AUTO_INCREMENT, ModifiedBySortName, ModifiedSortName, OidSortName, SYNC_SLOW, SYNC_STORE_CREATION_DATE, SYNC_STORE_MODIFICATION_DATE, SYNC_STORE_MODIFIED_BY, SyncSortName
BOOLEAN, BYTE_ARRAY, CREATED_FIELD, DATE, DATE_TIME, DECIMAL, DOUBLE, FIRST_SPECIAL_FIELD, FLAG_SYNCHRONIZED, FLAGS_FIELD, INTEGER, JAVA_OBJECT, LONG, MAX_ID, MODIFIED_BY_FIELD, MODIFIED_FIELD, NAME_FIELD, OBJECT_BYTES_FIELD, OBJECT_TEXT_FIELD, OID_FIELD, OPTION_ERROR_ON_NEED_REINDEX, PLAIN_DATE, PLAIN_TIME, reservedFieldHeaders, reservedFieldIDs, reservedFieldNames, reservedFieldTypes, SORT_DATE_ONLY, SORT_IGNORE_CASE, SORT_TIME_ONLY, SORT_UNKNOWN_IS_GREATER_THAN_KNOWN, SORT_UNKNOWN_IS_LESS_THAN_KNOWN, STRING, TIME, TIMESTAMP
Constructor and Description |
---|
RecordFile(DatabaseStream stream,
String mode)
Open a Record file using an already open DatabaseStream.
|
RecordFile(File file,
String mode)
Open a Record file using a specified File.
|
RecordFile(File file,
String mode,
boolean ignoreInconsistentState) |
RecordFile(RandomStream stream,
String mode)
Open a Record file using an already open RandomStream.
|
RecordFile(RandomStream stream,
String mode,
boolean ignoreInconsistentState) |
Modifier and Type | Method and Description |
---|---|
int |
addRecord(byte[] data,
int offset,
int length) |
int |
addRecord(byte[] data,
int offset,
int length,
boolean useFreeSpace)
Add the data as a new record.
|
void |
close()
Close the database.
|
int |
countDeletedEntries()
Returns the number of deleted records.
|
void |
delete()
Delete the database.
|
boolean |
deleteMetaData(String name) |
void |
deleteRecord(int location)
Delete the record at the specified location.
|
protected boolean |
doEnableLookupMode()
This should check if the underlying stream supports temporary closing/re-opening.
|
protected void |
doErase(int location,
boolean isDeleted) |
protected ByteArray |
doLoad(int location,
ByteArray dest) |
protected void |
doMarkAsDeleted(int location,
long OID,
long deleteTime) |
protected void |
doOpenCloseLookup(boolean isOpen)
This should temporarily close or re-open the underlying data.
|
protected int |
doSave(int location,
byte[] data,
int offset,
int length) |
void |
eraseDeletedEntries()
Free all the deleted records.
|
boolean |
eraseDeletedEntry(long oid)
Free a particular deleted entry.
|
protected boolean |
getAllRecords(Handle h,
int[] dest,
int offset,
int need)
Copy all the records into the array.
|
long[] |
getDeletedEntries()
Get an array of object IDs representing all the deleted entries.
|
DatabaseEntry |
getDeletedEntry(long oid,
DatabaseEntry dest)
Get the DatabaseEntry of the deleted OID.
|
long |
getEntriesCount()
This will return the number of entries in the database if known.
|
int |
getFirstEntry()
Retrieve the location of the first record.
|
byte[] |
getMetaData()
Read in the meta-data.
|
Object |
getMetaData(String name,
int length,
boolean mustExist) |
Time |
getModifiedTime()
Get the time of the last modification made to the database.
|
protected DatabaseObject.MetaData |
getNewMetaData(String name) |
int |
getNextEntry(int previous)
Retrieve the location of the normal record following the previous record.
|
void |
initialize()
Initialize the RecordFile - you do not need to call this for new RecordFiles, it is done
if a new RecordFile is created automatically.
|
int |
lengthOfRecord(int record)
Return the number of bytes needed to fetch a record.
|
protected eve.database.implement.DatabaseIndex |
makeNewIndex(String name) |
void |
markAsDeleted(int location,
long OID,
long deleteTime)
Delete the record, leaving behind a special deleted record marker.
|
int |
metaDataLength(String name)
Returns the length of the named MetaData (in bytes) in the DB.
|
int |
modifyRecord(int location,
byte[] data,
boolean useFreeSpace)
Modify the record data, returning a new location if the record had to be moved.
|
int |
modifyRecord(int location,
byte[] data,
int offset,
int length) |
int |
modifyRecord(int location,
byte[] data,
int offset,
int length,
boolean useFreeSpace)
Modify the record data, returning a new location if the record had to be moved.
|
void |
readMetaData(Object metaLocation,
int metaOffset,
byte[] data,
int offset,
int length) |
int |
readMetaDataInt(Object metaLocation,
int offset) |
byte[] |
readRecord(int record)
Read in and return the record data.
|
int |
readRecord(int record,
byte[] dest,
int offset)
Read in the record data.
|
ByteArray |
readRecord(int record,
ByteArray dest)
Read the record data and append it to a ByteArray.
|
void |
removeFieldIDs(int fieldID) |
void |
rename(String newName)
Rename the database.
|
void |
setDatabaseStream(DatabaseStream stream,
String mode,
boolean ignoreInconsistentState) |
boolean |
setModifiedTime(Time t)
Set the time of the last modification made to the database.
|
void |
writeMetaData(Object metaLocation,
int metaOffset,
byte[] data,
int offset,
int length) |
void |
writeMetaDataInt(Object metaLocation,
int offset,
int value) |
doErase, doLoad, doMarkAsDeleted, doStore, entries, getAllEntries, getAllFoundEntries, makeNewData, makeNewFoundEntries
addField, addSort, addSort, addSort, addSpecialField, append, change, closeLookup, countEntries, createIndex, createIndex, deleteStream, dispatchEvent, doAppend, doEstimateEntriesCount, doOpenIndex, doOpenIndex, doReIndex, enableLookupMode, enableSynchronization, enableSynchronization, ensureFields, ensureSorts, entries, entries, estimateEntriesCount, findField, findField, findFields, findFields, findIndex, findIndex, findOpenIndex, findSort, findSort, getCurrentState, getData, getDeletedSince, getEmptyEntries, getEntries, getEntries, getEventDispatcher, getField, getFieldHeader, getFieldName, getFields, getFieldType, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntries, getFoundEntriesForIndex, getIdentifier, getIndexes, getIndexSort, getLocale, getMetaData, getMyDatabaseEntries, getMyFoundEntries, getName, getNewData, getNewDataObject, getNewOID, getObjectClass, getProperties, getSortFields, getSortName, getSortOptions, getSorts, getStreamLength, getStringCollator, getSynchronizedTime, getTimeOfDeletion, hasChangedSince, hasDatabaseEntries, hasField, hasFoundEntries, indexBy, indexBy, indexBy, isIndexedBy, isInstanceOfDataObject, isOpenForReadWrite, load, markForReIndex, modifyField, openIndex, openLookup, openStreamForReading, openStreamForReplacing, openStreamForWriting, overrideFields, overrideSorts, overwriteMetaData, recordIndexChange, registerIndex, registerNewFoundEntries, reIndex, removeField, removeSort, save, saveIndex, setData, setDataValidator, setEncryption, setFieldHeader, setFields, setFields, setFields, setFields, setKey, setLocale, setMetaData, setObjectClass, setOptions, setPassword, setSorts, setSorts, setSorts, setStringCollator, setSynchronizedTime, toCriteria, updateTypes, useEncryption, usePassword
public Gate lock
public final int minimumLines
public RecordFile(DatabaseStream stream, String mode) throws IOException, InconsistentDatabaseStateException
stream
- The alredy opened DatabaseStreammode
- the mode to use the RecordFile. This can be "r" or "rw" or "a" (for append only).
Note that you may have to open the DatabaseStream in "rw" mode even if you are only going
to access the records in read-only ("r") mode. This is because the safeWrite feature
of the DatabaseStream may require you always open in "rw" mode to ensure that incomplete
operations are completed.IOException
InconsistentDatabaseStateException
public RecordFile(RandomStream stream, String mode) throws IOException, InconsistentDatabaseStateException
stream
- The alredy opened RandomStream. This will be wrapped in a RandomAccessDatabaseStream
for use by the RecordFile.mode
- the mode to use the RecordFile. This can be "r" or "rw" or "a" (for append only).
Note that you may have to open the RandomStream in "rw" mode even if you are only going
to access the records in read-only ("r") mode. This is because the safeWrite feature
of the RandomAccessDatabaseStream may require you always open in "rw" mode to ensure that incomplete
operations are completed.IOException
InconsistentDatabaseStateException
public RecordFile(File file, String mode) throws IOException, InconsistentDatabaseStateException
file
- The file to open. If the file does not exist it will be created if the mode is "rw" or "a"mode
- the mode to use the RecordFile. This can be "r" or "rw" or "a" (for append only).IOException
InconsistentDatabaseStateException
public RecordFile(RandomStream stream, String mode, boolean ignoreInconsistentState) throws IOException, InconsistentDatabaseStateException
public RecordFile(File file, String mode, boolean ignoreInconsistentState) throws IOException, InconsistentDatabaseStateException
public void setDatabaseStream(DatabaseStream stream, String mode, boolean ignoreInconsistentState) throws IOException
IOException
protected boolean doEnableLookupMode() throws IOException
DatabaseObject
doEnableLookupMode
in class DatabaseObject
IOException
- if an error occured which renders the Database unusable.protected void doOpenCloseLookup(boolean isOpen) throws IOException
DatabaseObject
doOpenCloseLookup
in class DatabaseObject
isOpen
- true to reopen the underlying data, false to close it.IOException
- if an error occured which renders the Database unusable.public void initialize() throws IOException
IOException
protected DatabaseObject.MetaData getNewMetaData(String name)
getNewMetaData
in class DatabaseObject
protected eve.database.implement.DatabaseIndex makeNewIndex(String name)
makeNewIndex
in class DatabaseObject
public void deleteRecord(int location) throws IOException
location
- The record location.IOException
public void markAsDeleted(int location, long OID, long deleteTime) throws IOException
location
- The record to delete.OID
- a unique ID to associate with the record.deleteTime
- a time stamp (from Time.getTime()) to associate with the deletion.IOException
- on error.DatabaseOperationException
- if the location is not a valid database record.public int countDeletedEntries() throws IOException
IOException
- on error.public void eraseDeletedEntries() throws IOException
IOException
public boolean eraseDeletedEntry(long oid) throws IOException
oid
- the OID of the deleted entry.IOException
public int modifyRecord(int location, byte[] data, int offset, int length, boolean useFreeSpace) throws IOException
location
- the location of the record.data
- The data bytes.offset
- The index of the first data byte.length
- The number of data bytes.useFreeSpace
- if this is false then it will be appended to the file without
any attempt to use space occupied by previously deleted records. This is the fastest
modify that you can do.IOException
public int addRecord(byte[] data, int offset, int length, boolean useFreeSpace) throws IOException
data
- The data bytes.offset
- The index of the first data byte.length
- The number of data bytes.useFreeSpace
- if this is false the record will be appended to the file without
any attempt to use space occupied by previously deleted records. This is the fastest
add that you can do.IOException
public int modifyRecord(int location, byte[] data, int offset, int length) throws IOException
IOException
public int addRecord(byte[] data, int offset, int length) throws IOException
IOException
public int modifyRecord(int location, byte[] data, boolean useFreeSpace) throws IOException
location
- the location of the record.data
- The data bytes.useFreeSpace
- if this is false and the record must be placed in a new location
because its data now exceeds its space allocation, then it will be appended to the file without
any attempt to use space occupied by previously deleted records. This is the fastest
add that you can do.IOException
public int lengthOfRecord(int record) throws IOException
record
- the record location.IOException
public int readRecord(int record, byte[] dest, int offset) throws IOException
record
- the record location.dest
- the destination for the data bytes.offset
- the location to read to.IOException
public byte[] readRecord(int record) throws IOException
record
- the record location.IOException
public ByteArray readRecord(int record, ByteArray dest) throws IOException
record
- the record to read.dest
- a destination ByteArray. This can be null in which case a new one will be created.IOException
public byte[] getMetaData() throws IOException
IOException
public int getFirstEntry() throws IOException
IOException
public int getNextEntry(int previous) throws IOException
getNextEntry
in class RecordDatabaseObject
previous
- The previous record. A value of zero will return the first record.IOException
protected boolean getAllRecords(Handle h, int[] dest, int offset, int need) throws IOException
getAllRecords
in class RecordDatabaseObject
dest
- the destination for the records.offset
- the location in the destination to write to.IOException
public void close() throws IOException
Database
IOException
- on error.public void delete() throws IOException
Database
IOException
- if the database could not be deleted.public void rename(String newName) throws IOException
Database
newName
- the new name for the database.IOException
- if the database could not be renamed.public long getEntriesCount() throws IOException
Database
getEntriesCount
in interface Database
getEntriesCount
in class DatabaseObject
IOException
- on error.public void removeFieldIDs(int fieldID) throws IOException
removeFieldIDs
in class RecordDatabaseObject
IOException
protected void doErase(int location, boolean isDeleted) throws IOException
doErase
in class RecordDatabaseObject
IOException
protected void doMarkAsDeleted(int location, long OID, long deleteTime) throws IOException
doMarkAsDeleted
in class RecordDatabaseObject
IOException
protected ByteArray doLoad(int location, ByteArray dest) throws IOException
doLoad
in class RecordDatabaseObject
IOException
protected int doSave(int location, byte[] data, int offset, int length) throws IOException
doSave
in class RecordDatabaseObject
IOException
public long[] getDeletedEntries() throws IOException
Database
IOException
public Time getModifiedTime() throws IOException
Database
IOException
- on error.public boolean setModifiedTime(Time t) throws IOException
Database
t
- the modified time.IOException
- on error.public Object getMetaData(String name, int length, boolean mustExist) throws IOException, IllegalArgumentException
IOException
IllegalArgumentException
public void readMetaData(Object metaLocation, int metaOffset, byte[] data, int offset, int length) throws IOException
IOException
public void writeMetaData(Object metaLocation, int metaOffset, byte[] data, int offset, int length) throws IOException
IOException
public boolean deleteMetaData(String name) throws IOException
IOException
public int metaDataLength(String name) throws IOException
Database
name
- the name of the MetaData.IOException
public int readMetaDataInt(Object metaLocation, int offset) throws IOException
IOException
public void writeMetaDataInt(Object metaLocation, int offset, int value) throws IOException
IOException
public DatabaseEntry getDeletedEntry(long oid, DatabaseEntry dest) throws IOException
Database
oid
- The OID to look for.IOException