public abstract class DatabaseObject extends Object implements Database
| Modifier and Type | Class and Description |
|---|---|
protected class |
DatabaseObject.MetaData |
| Modifier and Type | Field and Description |
|---|---|
protected DatabaseEntry |
buffer |
protected ByteArray |
byteArray |
protected DataValidator |
dataValidator |
protected DataProcessor |
decryptor |
protected DataProcessor |
encryptor |
protected boolean |
encryptorNotSet |
protected WeakSet |
entries |
protected FileRandomStream |
file |
protected WeakSet |
foundEntries |
protected int |
INDEX_FLAG_DO_REINDEX |
protected MetaFlag |
indexFlag |
protected IntArray |
intArray |
protected Gate |
lock |
protected Locale |
myLocale |
protected Time |
now |
protected Hashtable |
openIndexes |
protected String |
openMode |
protected Vector |
openModifiers |
protected static int |
SETFIELDS_MODE_ENSURE |
protected static int |
SETFIELDS_MODE_OVERRIDE |
protected static int |
SETFIELDS_MODE_SET |
protected DatabaseStream |
stream |
protected StringCollator |
stringCollator |
CreatedSortName, FIELD_MODIFIER_INTEGER_AUTO_INCREMENT, ModifiedBySortName, ModifiedSortName, OidSortName, SYNC_SLOW, SYNC_STORE_CREATION_DATE, SYNC_STORE_MODIFICATION_DATE, SYNC_STORE_MODIFIED_BY, SyncSortNameBOOLEAN, 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 |
|---|
DatabaseObject() |
| Modifier and Type | Method and Description |
|---|---|
int |
addField(String fieldName,
int fieldType)
Add a new field.
|
int |
addSort(String sortName,
int options,
int field)
Create a new sort criteria.
|
int |
addSort(String sortName,
int options,
int field1,
int field2,
int field3,
int field4)
Create a new sort criteria allowing you to specify up to four fields.
|
int |
addSort(String sortName,
int options,
String fieldList)
Create a new sort criteria allowing you to specify up to four fields.
|
void |
addSpecialField(int id)
Use this to add one of the reserved fields (the XXXX_FIELD) values.
|
void |
append(DatabaseEntry de)
Use this method in "Append" mode to add a data item to the Databse.
|
void |
change()
Mark the Database as having been changed in some way.
|
void |
closeLookup()
This is used with enableLookupMode() - it tells the database that data reading is complete
and the underlying file may be closed.
|
Handle |
countEntries()
If getEntriesCount() returns -1, indicating that the number of entries is unknown,
then this method will count the entries by counting each one if necessary.
|
protected eve.database.implement.DatabaseIndex |
createIndex(Handle h,
IndexEntry ie) |
protected eve.database.implement.DatabaseIndex |
createIndex(Handle h,
String name) |
boolean |
deleteStream(String name)
Delete a Stream from the Database.
|
protected void |
dispatchEvent(int type) |
protected void |
doAppend(DatabaseEntry de) |
protected boolean |
doEnableLookupMode()
This should check if the underlying stream supports temporary closing/re-opening.
|
protected abstract void |
doErase(DatabaseEntryObject entry) |
protected long |
doEstimateEntriesCount()
Override this to do an estimate on the number of entries if you can't tell the
exact number of entries.
|
protected abstract void |
doLoad(DatabaseEntryObject entry) |
protected abstract void |
doMarkAsDeleted(DatabaseEntryObject entry) |
protected void |
doOpenCloseLookup(boolean isOpen)
This should temporarily close or re-open the underlying data.
|
protected eve.database.implement.DatabaseIndex |
doOpenIndex(Handle h,
IndexEntry ie) |
protected eve.database.implement.DatabaseIndex |
doOpenIndex(Handle h,
String name) |
protected boolean |
doReIndex(Handle h) |
protected abstract boolean |
doStore(DatabaseEntryObject entry)
Return true if the entry is a new entry, false if not.
|
boolean |
enableLookupMode()
This method tells the database that it will be used for read-only lookups and that it can
close its underlying file if it wishes - and later re-open it when lookups are done without
re-reading the database info.
|
boolean |
enableSynchronization(Handle h,
int syncOptions)
This tells the database to include the OID_FIELD, FLAGS_FIELD, CREATED_FIELD and MODIFIED_FIELD
information with each record so that it can be synchronized with a other databases.
|
void |
enableSynchronization(int syncOptions)
This tells the database to include the OID_FIELD, FLAGS_FIELD, CREATED_FIELD and MODIFIED_FIELD
information with each record so that it can be synchronized with a other databases.
|
int[] |
ensureFields(Object objectOrClass,
String fields,
String headers)
Similar to setFields() except that no error is thrown if any fields
of the same name and type already exist.
|
int[] |
ensureSorts(Object objectOrClass,
String sorts)
This works the same as setSorts() except that no error is thrown if
any of the sorts already exists and has the same criteria of the already declared sort.
|
Iterator |
entries(Object searchData,
Comparer comparer)
This returns an Iterator that you can use to go through the entries in
the database.
|
Iterator |
entries(ObjectFinder finder)
This returns an Iterator that you can use to go through the entries in
the database.
|
long |
estimateEntriesCount()
If getEntriesCount() returns -1, indicating that the number of entries is unknown,
then this method will attempt to estimate the entries count via a quick non-blocking method
without resorting to counting each entry.
|
protected FieldSortEntry |
findField(int fieldID) |
int |
findField(String fieldName)
Find the FieldID of a named field.
|
int[] |
findFields(String fieldNames)
Get an array of fieldIds for a comma separated list of field names.
|
int[] |
findFields(String[] fieldNames)
Get an array of fieldIds for an array of field names.
|
protected IndexEntry |
findIndex(int sortID,
Comparer c) |
protected IndexEntry |
findIndex(String name,
int sortID) |
protected eve.database.implement.DatabaseIndex |
findOpenIndex(String indexName) |
protected FieldSortEntry |
findSort(int fieldID) |
int |
findSort(String sortName)
Get the ID of a named sort criteria.
|
protected abstract FoundEntries |
getAllFoundEntries(Handle h) |
long |
getCurrentState()
Get the current changed state of the Database.
|
protected Object |
getData(DatabaseEntry ded,
Object data)
Gets the fields from the DatabaseEntry to the fields in the data object - which must not be null.
|
long[] |
getDeletedSince(Time t)
Get the OIDs of all entries deleted after the specified time (but not AT the
specified time).
|
FoundEntries |
getEmptyEntries()
This returns an empty FoundEntries object for this Database
|
FoundEntries |
getEntries()
Get an unsorted FoundEntries representing all the entries in the database.
|
FoundEntries |
getEntries(int sortID)
Get all the entries in the Database sorted by the specified sort ID.
|
abstract long |
getEntriesCount()
This will return the number of entries in the database if known.
|
EventDispatcher |
getEventDispatcher()
Get an EventDispatcher which you can use to attach EventListeners to, for
listening to the events being generated by the Database.
|
int |
getField(String fieldName)
Similar to findField(), find the FieldID of a named field.
|
String |
getFieldHeader(int fieldID)
Get the header for a specified field ID.
|
String |
getFieldName(int fieldID)
Get the name for a specified field ID.
|
int[] |
getFields()
Get the IDs of all the fields.
|
int |
getFieldType(int fieldID)
Get the type of a field.
|
Handle |
getFoundEntries(Comparer comparer)
Get all the entries in the Database sorted by the specified Comparer in a new thread.
|
FoundEntries |
getFoundEntries(Handle h,
Comparer comparer)
Get all the entries in the Database sorted by the specific comparer.
|
FoundEntries |
getFoundEntries(Handle h,
int sortID)
Get all the entries in the Database sorted by the specified sort ID.
|
FoundEntries |
getFoundEntries(Handle h,
int sortID,
EntrySelector selector)
Get a subset of the entries in the Database sorted by the specific sort ID and
which the EntrySelector considers to be equal to the searchData.
|
protected FoundEntries |
getFoundEntries(Handle h,
int sortId,
EntrySelector selector,
ObjectFinder finder) |
protected FoundEntries |
getFoundEntries(Handle h,
int sortId,
EntrySelector selector,
ObjectFinder finder,
Comparer c,
boolean useIndexes)
Override this to locate the found entries in your own way.
|
FoundEntries |
getFoundEntries(Handle h,
int sortID,
Object primarySearchFields)
Get a subset of the entries in the Database sorted by the specific sort ID and
which match the primarySearchFields data.
|
FoundEntries |
getFoundEntries(Handle h,
int sortID,
ObjectFinder finder)
Get a subset of the entries in the Database sorted by the specific sort ID and
which the ObjectFinder considers to be what is being looked for.
|
FoundEntries |
getFoundEntries(Handle h,
String indexName)
Get all the entries in the database sorted according to the specified index.
|
Handle |
getFoundEntries(int sortID)
Get all the entries in the Database sorted by the specified sort ID in a new thread.
|
Handle |
getFoundEntries(int sortID,
EntrySelector selector)
Get a subset the entries in the Database sorted by the specified sort ID in a new thread.
|
Handle |
getFoundEntries(int sortID,
Object primarySearchFields)
Get a subset of the entries in the Database sorted by the specific sort ID and
which match the primarySearchFields data in a new thread.
|
Handle |
getFoundEntries(int sortID,
ObjectFinder finder)
Get a subset of the entries in the Database sorted by the specific sort ID and
which the ObjectFinder considers to be what is being looked for in a new thread.
|
Handle |
getFoundEntries(String indexName)
Get all the entries in the Database sorted by the specified index in a new thread.
|
protected FoundEntries |
getFoundEntriesForIndex(Handle h,
IndexEntry ie) |
int |
getIdentifier()
Get a unique identifier for this database - used for synchronizing.
|
IndexEntry[] |
getIndexes()
This returns all the indexes used by the Database.
|
int |
getIndexSort(String indexName) |
Locale |
getLocale()
Set the locale being used with the Database.
|
protected byte[] |
getMetaData(String name) |
protected Iterator |
getMyDatabaseEntries() |
protected Iterator |
getMyFoundEntries() |
String |
getName() |
DatabaseEntry |
getNewData()
Return an empty DatabaseEntry to be used with this database.
|
Object |
getNewDataObject()
Create and return a new instance of the object class assigned to the
database.
|
protected abstract DatabaseObject.MetaData |
getNewMetaData(String name) |
protected long |
getNewOID() |
Class |
getObjectClass()
If setObjectClass() was used on the database to specify a Java class to
be used as a data interface, then this will return a Reflect object
representing that class.
|
PropertyList |
getProperties()
Get the PropertyList object associated with this object.
|
int[] |
getSortFields(int sortID)
Get the fields by which the Sort will sort.
|
String |
getSortName(int sortID)
Get the name of a Sort.
|
int |
getSortOptions(int sortID)
Get the options associated with the sortID.
|
int[] |
getSorts()
Get the IDs of all the sorts.
|
long |
getStreamLength(String name)
Returns the length of a meta-data Stream stored in the Database, or -1 if the named Stream
does not exist.
|
StringCollator |
getStringCollator()
Return the Collator used by the database to sort and search for Strings.
|
Time |
getSynchronizedTime(int remoteDatabaseID) |
Time |
getTimeOfDeletion(long oid,
Time dest)
Return the time of deletion of the specified OID.
|
boolean |
hasChangedSince(long previousState)
Return if the Database has changed since the previous state.
|
protected boolean |
hasDatabaseEntries() |
protected boolean |
hasField(int fieldID) |
protected boolean |
hasFoundEntries() |
boolean |
indexBy(Handle h,
Class comparer,
String name)
This tells the Database to keep an index using a particular Comparer class and
distinct name.
|
boolean |
indexBy(Handle h,
int sortID,
String name)
This tells the Database to keep an index for a particular sort ID and optional
distinct name.
|
void |
indexBy(int sortID)
This is a convenience method for the other indexBy method.
|
boolean |
isIndexedBy(int sortID)
This returns if the Database has at least one index that uses the specified sort ID.
|
boolean |
isInstanceOfDataObject(Object data)
Return if the specified object is an instance of the data transfer object
assigned in setObjectClass();
|
boolean |
isOpenForReadWrite()
This should return true if the Database is open in read/write mode, or false
if it is open in read-only mode.
|
protected void |
load(String mode,
boolean ignoreInconsistentState)
This should be called when the Database is opened.
|
protected abstract DatabaseEntry |
makeNewData() |
protected abstract FoundEntries |
makeNewFoundEntries() |
protected abstract eve.database.implement.DatabaseIndex |
makeNewIndex(String name) |
protected void |
markForReIndex(boolean needReIndex) |
void |
modifyField(int fieldID,
int modifier,
Object modifierData)
Modify a field in some way.
|
protected eve.database.implement.DatabaseIndex |
openIndex(Handle h,
IndexEntry ie) |
void |
openLookup()
This is used with enableLookupMode() - it tells the database that data is about to be read in
and if the underlying file is closed - then it should be re-opened and kept open until closeLookup()
is called.
|
InputStream |
openStreamForReading(String name)
Open a Stream into the database to read some sort of meta-data.
|
OutputStream |
openStreamForReplacing(String name)
Open a Stream into the database to save some sort of meta-data.
|
OutputStream |
openStreamForWriting(String name,
boolean append)
Open a Stream into the database to save some sort of meta-data.
|
int[] |
overrideFields(Object objectOrClass,
String fields,
String headers)
Similar to setFields() except that no error is thrown if any fields
of the same name and type already exist.
|
int[] |
overrideSorts(Object objectOrClass,
String sorts)
This works the same as setSorts() except that no error is thrown if
any of the sorts already exists and has the same criteria of the already declared sort,
and also any old sorts of the same name will be replaced by the new sort.
|
protected void |
overwriteMetaData(String name,
byte[] data) |
protected void |
recordIndexChange(FoundEntriesObject obj,
byte[] toRecord,
int offset,
int length) |
protected eve.database.implement.DatabaseIndex |
registerIndex(eve.database.implement.DatabaseIndex index,
String name) |
protected FoundEntries |
registerNewFoundEntries(FoundEntries fe) |
boolean |
reIndex(Handle h)
In "Append" mode, after all the data has been added, call this method to re-index the
database.
|
void |
removeField(int fieldID)
Note that if this DataTable is a live one (i.e. it exists within an open database), then
calling this method may take time as all of the records in the table will have this
field removed from them.
|
protected abstract void |
removeFieldIDs(int fieldID) |
void |
removeSort(int sortID)
Remove a Sort.
|
void |
save()
Save the Database specs to permanent storage.
|
protected boolean |
saveIndex(Handle h,
eve.database.implement.DatabaseIndex di) |
protected void |
setData(DatabaseEntry ded,
Object data)
Sets the fields in the DatabaseEntry from the fields in the data object - which must not be null.
|
void |
setDataValidator(DataValidator validator)
Set a DataValidator to validate data before it is saved in the Database.
|
void |
setEncryption(DataProcessor decryptor,
DataProcessor encryptor)
Use this when the Database is initialized to set the decryptor and encryptor
for the data.
|
boolean |
setFieldHeader(int fieldID,
String newHeader)
Set the header for a specified field ID.
|
int[] |
setFields(Object objectOrClass)
Set the fields for the DataTable, which must match fields in the objectOrClass
transfer object.
|
int[] |
setFields(Object objectOrClass,
String fields)
Set the fields for the DataTable, which must match fields in the objectOrClass
transfer object.
|
int[] |
setFields(Object objectOrClass,
String fields,
String headers)
Set the fields for the DataTable, which must match fields in the objectOrClassOrReflect
transfer object.
|
protected int[] |
setFields(Object objectOrClass,
String fields,
String headers,
int mode) |
protected void |
setKey(DataProcessor processor,
Object key) |
void |
setLocale(Locale locale)
Set the locale to be used with the Database.
|
protected void |
setMetaData(String name,
byte[] data) |
void |
setObjectClass(Object objectOrClass)
This is used to set the class of the object used for data transfer to
and from the table.
|
int |
setOptions(int optionsToSet,
int optionsToClear)
Set/Clear/Retrieve Database options.
|
void |
setPassword(String password)
Use this when the Database is initialized to set the encryption key for the database.
|
int[] |
setSorts(Object objectOrClass)
Set the sorts of the Database as specified by the object provided.
|
int[] |
setSorts(Object objectOrClass,
String sorts)
Set the sorts of the Database as specified by the object provided.
|
int[] |
setSorts(Object dataObject,
String sorts,
int operation) |
void |
setStringCollator(StringCollator collator)
Set the Collator used by the database to sort and search for Strings.
|
void |
setSynchronizedTime(int remoteDatabaseID,
Time syncTime) |
int[] |
toCriteria(int sortID)
Convert the sortID to a Criteria array, used by a number of
Database functions.
|
protected void |
updateTypes(FieldSortEntry fse) |
boolean |
useEncryption(DataProcessor decryptor,
DataProcessor encryptor)
Use this when opening the database and accessing the data.
|
boolean |
usePassword(Object obj)
Use this when opening the database and accessing the data.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclose, countDeletedEntries, delete, deleteMetaData, entries, eraseDeletedEntries, eraseDeletedEntry, getDeletedEntries, getDeletedEntry, getMetaData, getModifiedTime, metaDataLength, readMetaData, readMetaDataInt, rename, setModifiedTime, writeMetaData, writeMetaDataIntprotected FileRandomStream file
protected DatabaseStream stream
protected DataProcessor decryptor
protected DataProcessor encryptor
protected Locale myLocale
protected ByteArray byteArray
protected WeakSet foundEntries
protected WeakSet entries
protected Time now
protected Gate lock
protected DatabaseEntry buffer
protected String openMode
protected Hashtable openIndexes
protected Vector openModifiers
protected DataValidator dataValidator
protected boolean encryptorNotSet
protected final int INDEX_FLAG_DO_REINDEX
protected MetaFlag indexFlag
protected StringCollator stringCollator
protected static final int SETFIELDS_MODE_SET
protected static final int SETFIELDS_MODE_ENSURE
protected static final int SETFIELDS_MODE_OVERRIDE
protected IntArray intArray
public StringCollator getStringCollator()
DatabasegetStringCollator in interface Databasepublic void setStringCollator(StringCollator collator)
DatabasesetStringCollator in interface Databasepublic abstract long getEntriesCount()
throws IOException
DatabasegetEntriesCount in interface DatabaseIOException - on error.public boolean isOpenForReadWrite()
DatabaseisOpenForReadWrite in interface Databasepublic PropertyList getProperties()
HasPropertiesgetProperties in interface HasPropertiesprotected void setKey(DataProcessor processor, Object key)
public boolean useEncryption(DataProcessor decryptor, DataProcessor encryptor) throws IOException, IllegalArgumentException
DatabaseuseEncryption in interface Databasedecryptor - The decryptor. Necessary for reading and writing if the Database is encrypted.encryptor - The encryptor. Necessary for writing only if the Database is encrypted.IOExceptionIllegalArgumentExceptionpublic boolean usePassword(Object obj)
DatabaseusePassword in interface Databasepublic void setEncryption(DataProcessor decryptor, DataProcessor encryptor) throws IllegalArgumentException, IOException
DatabasesetEncryption in interface DatabaseIllegalArgumentExceptionIOExceptionpublic void setPassword(String password) throws IllegalArgumentException, IOException
DatabasesetPassword in interface Databasepassword - a string to be used as the password. Choose a mix of numeric and letters
for better security.IllegalArgumentExceptionIOExceptionpublic Locale getLocale()
Databasepublic void setLocale(Locale locale)
Databaseprotected abstract DatabaseEntry makeNewData()
protected abstract FoundEntries makeNewFoundEntries()
protected abstract eve.database.implement.DatabaseIndex makeNewIndex(String name)
protected FoundEntries registerNewFoundEntries(FoundEntries fe)
protected eve.database.implement.DatabaseIndex findOpenIndex(String indexName)
public FoundEntries getEmptyEntries()
DatabasegetEmptyEntries in interface Databasepublic DatabaseEntry getNewData()
DatabasegetNewData in interface Databaseprotected Iterator getMyFoundEntries()
protected Iterator getMyDatabaseEntries()
protected boolean hasFoundEntries()
protected boolean hasDatabaseEntries()
public int[] toCriteria(int sortID)
throws IllegalArgumentException
DatabasetoCriteria in interface DatabaseIllegalArgumentExceptionprotected abstract DatabaseObject.MetaData getNewMetaData(String name) throws IOException
IOExceptionprotected eve.database.implement.DatabaseIndex registerIndex(eve.database.implement.DatabaseIndex index,
String name)
throws IOException
IOExceptionpublic OutputStream openStreamForWriting(String name, boolean append) throws IOException
DatabaseopenStreamForWriting in interface Databasename - The name of the meta-data Stream.append - Set this true if you want to add to the data already stored in the stream.IOException - if an error occurs.public OutputStream openStreamForReplacing(String name) throws IOException
DatabaseopenStreamForReplacing in interface Databasename - The name of the meta-data Stream.IOException - if an error occurs.public InputStream openStreamForReading(String name) throws IOException
DatabaseopenStreamForReading in interface Databasename - The name of the meta-data Stream.IOException - if an error occurs or if the Stream does not exist.public boolean deleteStream(String name) throws IOException
DatabasedeleteStream in interface Databasename - The name of the meta-data Stream.IOException - if an error occurs.public long getStreamLength(String name) throws IOException
DatabasegetStreamLength in interface Databasename - the name of the Stream.IOException - if an error occurs.protected byte[] getMetaData(String name) throws IOException
IOExceptionprotected void setMetaData(String name, byte[] data) throws IOException
IOExceptionprotected void overwriteMetaData(String name, byte[] data) throws IOException
IOExceptionprotected FieldSortEntry findField(int fieldID)
protected FieldSortEntry findSort(int fieldID)
public void setObjectClass(Object objectOrClass) throws IllegalArgumentException
setObjectClass in interface DatabaseobjectOrClass - IllegalArgumentExceptionpublic Class getObjectClass()
DatabasegetObjectClass in interface Databasepublic int[] setSorts(Object objectOrClass) throws IllegalArgumentException
DatabasesetSorts in interface DatabaseobjectOrClass - the Class of the object or an instance of the object.IllegalArgumentException - if a sort conflicts with an already saved sort.public int[] setSorts(Object objectOrClass, String sorts) throws IllegalArgumentException
DatabasesetSorts in interface DatabaseobjectOrClass - the Class of the object or an instance of the object.sorts - a String specifying the sort criteria to use.IllegalArgumentException - if a sort conflicts with an already saved sort.public int[] ensureSorts(Object objectOrClass, String sorts) throws IllegalArgumentException
DatabaseensureSorts in interface DatabaseobjectOrClass - the Class of the object or an instance of the object.sorts - a String specifying the sort criteria to use.IllegalArgumentExceptionpublic int[] overrideSorts(Object objectOrClass, String sorts) throws IllegalArgumentException
DatabaseoverrideSorts in interface DatabaseobjectOrClass - the Class of the object or an instance of the object.sorts - a String specifying the sort criteria to use.IllegalArgumentExceptionpublic int[] setSorts(Object dataObject, String sorts, int operation) throws IllegalArgumentException
IllegalArgumentExceptionpublic int[] setFields(Object objectOrClass) throws IllegalArgumentException
setFields in interface DatabaseobjectOrClass - The object or class of the object to be used for data transfer.IllegalArgumentExceptionpublic int[] setFields(Object objectOrClass, String fields) throws IllegalArgumentException
setFields in interface DatabaseobjectOrClass - The object or class of the object to be used for data transfer.fields - A comma separated list of fields. The types of these fields must be one of:
IllegalArgumentExceptionpublic int[] setFields(Object objectOrClass, String fields, String headers) throws IllegalArgumentException
setFields in interface DatabaseobjectOrClass - The object or class of the object to be used for data transfer.fields - A comma separated list of fields. The types of these fields must be one of:
headers - An optional comma separated list of headers.IllegalArgumentExceptionpublic int[] ensureFields(Object objectOrClass, String fields, String headers) throws IllegalArgumentException
DatabaseensureFields in interface DatabaseobjectOrClass - The object or class of the object to be used for data transfer.fields - A comma separated list of fields.headers - An optional comma separated list of headers.IllegalArgumentExceptionpublic int[] overrideFields(Object objectOrClass, String fields, String headers) throws IllegalArgumentException
DatabaseoverrideFields in interface DatabaseobjectOrClass - The object or class of the object to be used for data transfer.fields - A comma separated list of fields.headers - An optional comma separated list of headers.IllegalArgumentExceptionprotected int[] setFields(Object objectOrClass, String fields, String headers, int mode) throws IllegalArgumentException
IllegalArgumentExceptionpublic int findField(String fieldName)
public int getField(String fieldName) throws IllegalArgumentException
fieldName - The name of the field.IllegalArgumentException - if the field is not found.public int[] findFields(String[] fieldNames)
findFields in interface Databasepublic int[] findFields(String fieldNames)
findFields in interface Databasepublic String getFieldName(int fieldID)
DatabasegetFieldName in interface Databasepublic String getFieldHeader(int fieldID)
DatabasegetFieldHeader in interface Databasepublic boolean setFieldHeader(int fieldID,
String newHeader)
DatabasesetFieldHeader in interface Databasepublic String getSortName(int sortID)
DatabasegetSortName in interface Databasepublic int[] getSortFields(int sortID)
DatabasegetSortFields in interface Databasepublic int getSortOptions(int sortID)
DatabasegetSortOptions in interface Databasepublic int getFieldType(int fieldID)
DatabasegetFieldType in interface Databasepublic int setOptions(int optionsToSet,
int optionsToClear)
DatabasesetOptions in interface DatabaseoptionsToSet - any of the DatabaseTypes.OPTION_XXXX values OR'ed together.optionsToClear - any of the DatabaseTypes.OPTION_XXXX values OR'ed together.public int[] getFields()
Databasepublic int[] getSorts()
Databasepublic int addField(String fieldName, int fieldType) throws IllegalArgumentException
addField in interface DatabasefieldName - The name of the new field.fieldType - The type of the new field.IllegalArgumentExceptionpublic int findSort(String sortName)
Databasepublic int addSort(String sortName, int options, int field) throws IllegalArgumentException
addSort in interface DatabaseIllegalArgumentExceptionpublic int addSort(String sortName, int options, int field1, int field2, int field3, int field4) throws IllegalArgumentException
addSort in interface DatabasesortName - The name of the sort.options - Sorting options.field1 - the id of the field for the first (primary) sort criteria.field2 - the id of the field for the second sort criteria - set to 0 for no more fields.field3 - the id of the field for the third sort criteria - set to 0 for no more fields.field4 - the id of the field for the fourth sort criteria - set to 0 for no more fields.IllegalArgumentExceptionpublic int addSort(String sortName, int options, String fieldList) throws IllegalArgumentException
addSort in interface DatabasesortName - The name of the sort.options - Sorting options.fieldList - A comma separated field list.IllegalArgumentException - if any of the fields could not be found, or if too many
fields are specified.public void removeField(int fieldID)
removeField in interface DatabasefieldID - the ID of the field to remove.public void removeSort(int sortID)
DatabaseremoveSort in interface DatabasesortID - the ID of the sort to remove.protected IndexEntry findIndex(String name, int sortID)
protected IndexEntry findIndex(int sortID, Comparer c)
public boolean indexBy(Handle h, Class comparer, String name) throws IOException, IllegalArgumentException
Creating a new index will usually involve sorting all the entries of the database so this may take some time to complete and you can monitor and abort the operation using the Handle parameter.
indexBy in interface Databaseh - An optional handle that you can use to monitor and control any index creation
operation.comparer - A valid sort ID for the database.name - A distinct name for the index, which must not be null.IOException - If an IO error occured using the database.IllegalArgumentException - if the comparer or name is invalid.public boolean indexBy(Handle h, int sortID, String name) throws IllegalArgumentException, IOException
DatabaseCreating a new index will usually involve sorting all the entries of the database so this may take some time to complete and you can monitor and abort the operation using the Handle parameter.
indexBy in interface Databaseh - An optional handle that you can use to monitor and control any index creation
operation.sortID - A valid sort ID for the database.name - A distinct name for the index. If it is null then the same name as the sort ID
will be used.IllegalArgumentException - if the sort ID is invalid.IOException - If an IO error occured using the database.public void indexBy(int sortID)
throws IOException
DatabaseindexBy in interface DatabasesortID - A valid sort ID for the database.IOException - If an IO error occured using the database.public boolean isIndexedBy(int sortID)
DatabaseisIndexedBy in interface Databasepublic IndexEntry[] getIndexes()
DatabasegetIndexes in interface Databasepublic int getIndexSort(String indexName)
protected eve.database.implement.DatabaseIndex createIndex(Handle h, String name) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionprotected boolean saveIndex(Handle h, eve.database.implement.DatabaseIndex di) throws IOException
IOExceptionprotected eve.database.implement.DatabaseIndex createIndex(Handle h, IndexEntry ie) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionprotected boolean doReIndex(Handle h) throws IOException
IOExceptionprotected eve.database.implement.DatabaseIndex openIndex(Handle h, IndexEntry ie) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionprotected eve.database.implement.DatabaseIndex doOpenIndex(Handle h, String name) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionprotected eve.database.implement.DatabaseIndex doOpenIndex(Handle h, IndexEntry ie) throws IllegalArgumentException, IOException
IllegalArgumentExceptionIOExceptionprotected void recordIndexChange(FoundEntriesObject obj, byte[] toRecord, int offset, int length)
protected long getNewOID()
throws IOException
IOExceptionpublic int getIdentifier()
throws IOException
DatabasegetIdentifier in interface DatabaseIOExceptionpublic void setSynchronizedTime(int remoteDatabaseID,
Time syncTime)
throws IOException
setSynchronizedTime in interface DatabaseIOExceptionpublic Time getSynchronizedTime(int remoteDatabaseID) throws IOException
getSynchronizedTime in interface DatabaseIOExceptionprotected void updateTypes(FieldSortEntry fse)
public void save()
throws IOException
Databasesave in interface DatabaseIOException - if an error occurs.public Object getNewDataObject() throws IllegalStateException
getNewDataObject in interface DatabaseIllegalStateException - if no object class is specified or the
object could not be instantiated.public boolean isInstanceOfDataObject(Object data)
isInstanceOfDataObject in interface Databasedata - the object to check.public void setDataValidator(DataValidator validator)
DatabasesetDataValidator in interface Databasevalidator - A validator or null to clear the validator.public void modifyField(int fieldID,
int modifier,
Object modifierData)
throws IllegalArgumentException,
IOException
DatabasemodifyField in interface DatabasefieldID - The id of the field to modify.modifier - one of the FIELD_MODIFIER_XXX values appropriate for the field type.modifierData - Some data dependent on the field modifier used.IllegalArgumentException - if the modifier is not appropriate for the field or
if the data is not the correct type for the modifier.IOExceptionprotected void load(String mode, boolean ignoreInconsistentState) throws IOException, InconsistentDatabaseStateException
protected boolean hasField(int fieldID)
public String getName()
protected abstract boolean doStore(DatabaseEntryObject entry) throws IOException
IOExceptionprotected abstract void doLoad(DatabaseEntryObject entry) throws IOException, IllegalStateException
IOExceptionIllegalStateExceptionprotected abstract void doMarkAsDeleted(DatabaseEntryObject entry) throws IOException
IOExceptionprotected abstract void doErase(DatabaseEntryObject entry) throws IOException
IOExceptionprotected abstract void removeFieldIDs(int fieldID)
throws IOException
IOExceptionpublic Time getTimeOfDeletion(long oid, Time dest) throws IOException
DatabasegetTimeOfDeletion in interface Databaseoid - The OID of the deleted entry.dest - an optional destination time. If this is null the a new Time will
be created.IOExceptionpublic long[] getDeletedSince(Time t) throws IOException
getDeletedSince in interface DatabaseIOExceptionpublic void addSpecialField(int id)
throws IllegalArgumentException
DatabaseaddSpecialField in interface DatabaseIllegalArgumentExceptionpublic boolean enableSynchronization(Handle h, int syncOptions) throws IOException
DatabaseenableSynchronization in interface DatabasesyncOptions - any of the SYNC_XXX values ORed together.IOExceptionpublic void enableSynchronization(int syncOptions)
throws IOException
DatabaseenableSynchronization in interface DatabasesyncOptions - any of the SYNC_XXX values ORed together.IOExceptionprotected void setData(DatabaseEntry ded, Object data)
ded - The DatabaseEntry to set.data - The data object, which must be of the type objectClass or an exception will be thrown.protected Object getData(DatabaseEntry ded, Object data)
ded - The DatabaseEntry to set.data - The data object, which must be of the type objectClass or an exception will be thrown.public Iterator entries(Object searchData, Comparer comparer) throws IOException
DatabaseThe getNext() method of the returned iterator may throw a DatabaseIOException if there is an IO error when retrieving the next entry.
entries in interface DatabaseIOExceptionpublic Iterator entries(ObjectFinder finder) throws IOException
DatabaseThe getNext() method of the returned iterator may throw a DatabaseIOException if there is an IO error when retrieving the next entry.
entries in interface DatabaseIOExceptionprotected long doEstimateEntriesCount()
throws IOException
IOExceptionpublic long estimateEntriesCount()
throws IOException
DatabaseestimateEntriesCount in interface DatabaseIOException - on error.public Handle countEntries()
DatabasecountEntries in interface Databaseprotected abstract FoundEntries getAllFoundEntries(Handle h) throws IOException
IOExceptionprotected FoundEntries getFoundEntries(Handle h, int sortId, EntrySelector selector, ObjectFinder finder, Comparer c, boolean useIndexes) throws IOException
IOExceptionprotected FoundEntries getFoundEntries(Handle h, int sortId, EntrySelector selector, ObjectFinder finder) throws IOException
IOExceptionprotected FoundEntries getFoundEntriesForIndex(Handle h, IndexEntry ie) throws IOException
IOExceptionpublic FoundEntries getFoundEntries(Handle h, Comparer comparer) throws IOException
DatabasegetFoundEntries in interface Databaseh - an optional Handle used to monitor and possibly abort the process.comparer - This is used to sort the entries.IOExceptionpublic Handle getFoundEntries(int sortID)
DatabasegetFoundEntries in interface DatabasesortID - The sortID to use. If this is 0 the entries are not sorted.public Handle getFoundEntries(int sortID, EntrySelector selector)
DatabasegetFoundEntries in interface DatabasesortID - The sortID to use. If this is 0 the entries are not sorted.selector - An object used to select the data according to certain criteria.public Handle getFoundEntries(int sortID, Object primarySearchFields)
DatabasegetFoundEntries in interface DatabasesortID - The sortID to use. If this is 0 the entries are not sorted.primarySearchFields - data that will be used to select entries in the Database.public Handle getFoundEntries(int sortID, ObjectFinder finder)
DatabasegetFoundEntries in interface DatabasesortID - The sortID to use. If this is 0 the entries are not sorted.finder - This object will have its lookingFor(Object obj) method called for each
entry in the database. If the finder returns true, then that entry will be placed in the FoundEntries
returned.public Handle getFoundEntries(Comparer comparer)
DatabasegetFoundEntries in interface Databasecomparer - This is used to sort the entries.public FoundEntries getFoundEntries(Handle h, String indexName) throws IOException, IllegalArgumentException
DatabasegetFoundEntries in interface Databaseh - an optional Handle used to monitor and possibly abort the process.indexName - a valid index name.IOExceptionIllegalArgumentExceptionpublic Handle getFoundEntries(String indexName)
DatabasegetFoundEntries in interface DatabaseindexName - a valid index name.public FoundEntries getEntries() throws IOException
DatabasegetEntries in interface DatabaseIOExceptionpublic FoundEntries getEntries(int sortID) throws IOException
DatabasegetEntries in interface DatabasesortID - The sortID to use. If this is 0 the entries are not sorted.IOExceptionpublic FoundEntries getFoundEntries(Handle h, int sortID, ObjectFinder finder) throws IOException
DatabasegetFoundEntries in interface Databaseh - an optional Handle used to monitor and possibly abort the process.sortID - The sortID to use. If this is 0 the entries are not sorted.finder - This object will have its lookingFor(Object obj) method called for each
entry in the database. If the finder returns true, then that entry will be placed in the FoundEntries
returned.IOExceptionpublic FoundEntries getFoundEntries(Handle h, int sortID, EntrySelector selector) throws IOException
DatabasegetFoundEntries in interface Databaseh - an optional Handle used to monitor and possibly abort the process.sortID - The sortID to use. If this is 0 the entries are not sorted.selector - An object used to select the data according to certain criteria.IOExceptionpublic FoundEntries getFoundEntries(Handle h, int sortID) throws IOException
DatabasegetFoundEntries in interface Databaseh - a handle that other threads can use to monitor the operation progress.sortID - The sortID to use. If this is 0 the entries are not sorted.IOExceptionpublic FoundEntries getFoundEntries(Handle h, int sortID, Object primarySearchFields) throws IOException
DatabasegetFoundEntries in interface Databaseh - an optional Handle used to monitor and possibly abort the process.sortID - The sortID to use. If this is 0 the entries are not sorted.primarySearchFields - data that will be used to select entries in the Database.IOExceptionpublic long getCurrentState()
DatabasegetCurrentState in interface Databasepublic boolean hasChangedSince(long previousState)
DatabasehasChangedSince in interface Databasepublic void change()
Databasepublic EventDispatcher getEventDispatcher()
DatabasegetEventDispatcher in interface Databaseprotected void dispatchEvent(int type)
protected boolean doEnableLookupMode()
throws IOException
IOException - if an error occured which renders the Database unusable.protected void doOpenCloseLookup(boolean isOpen)
throws IOException
isOpen - true to reopen the underlying data, false to close it.IOException - if an error occured which renders the Database unusable.public boolean enableLookupMode()
throws IOException
Not all Databases may support this and if it does not, it will return false - although normal database operations will not be affected. In other words - if this method returns false, the application can continue as if it returned true - but its operations will not be optimized in this way.
enableLookupMode in interface DatabaseIOException - if an IO error occurs.public void openLookup()
throws IOException
openLookup in interface DatabaseIOException - if an IO error occurs.public void closeLookup()
throws IOException
closeLookup in interface DatabaseIOException - if an IO error occurs.protected void markForReIndex(boolean needReIndex)
throws IOException
IOExceptionpublic boolean reIndex(Handle h) throws IOException
DatabaseIf you close the database without doing reIndex, it will be reIndexed automatically the next time it is opened.
reIndex in interface Databaseh - a Handle that can be used to monitor or abort the operation.IOException - if there was an error writing to the database.public void append(DatabaseEntry de) throws IOException
Databaseappend in interface DatabaseIOExceptionprotected void doAppend(DatabaseEntry de) throws IOException
IOException