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, 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 |
---|
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, wait
close, countDeletedEntries, delete, deleteMetaData, entries, eraseDeletedEntries, eraseDeletedEntry, getDeletedEntries, getDeletedEntry, getMetaData, getModifiedTime, metaDataLength, readMetaData, readMetaDataInt, rename, setModifiedTime, writeMetaData, writeMetaDataInt
protected 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()
Database
getStringCollator
in interface Database
public void setStringCollator(StringCollator collator)
Database
setStringCollator
in interface Database
public abstract long getEntriesCount() throws IOException
Database
getEntriesCount
in interface Database
IOException
- on error.public boolean isOpenForReadWrite()
Database
isOpenForReadWrite
in interface Database
public PropertyList getProperties()
HasProperties
getProperties
in interface HasProperties
protected void setKey(DataProcessor processor, Object key)
public boolean useEncryption(DataProcessor decryptor, DataProcessor encryptor) throws IOException, IllegalArgumentException
Database
useEncryption
in interface Database
decryptor
- The decryptor. Necessary for reading and writing if the Database is encrypted.encryptor
- The encryptor. Necessary for writing only if the Database is encrypted.IOException
IllegalArgumentException
public boolean usePassword(Object obj)
Database
usePassword
in interface Database
public void setEncryption(DataProcessor decryptor, DataProcessor encryptor) throws IllegalArgumentException, IOException
Database
setEncryption
in interface Database
IllegalArgumentException
IOException
public void setPassword(String password) throws IllegalArgumentException, IOException
Database
setPassword
in interface Database
password
- a string to be used as the password. Choose a mix of numeric and letters
for better security.IllegalArgumentException
IOException
public Locale getLocale()
Database
public void setLocale(Locale locale)
Database
protected 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()
Database
getEmptyEntries
in interface Database
public DatabaseEntry getNewData()
Database
getNewData
in interface Database
protected Iterator getMyFoundEntries()
protected Iterator getMyDatabaseEntries()
protected boolean hasFoundEntries()
protected boolean hasDatabaseEntries()
public int[] toCriteria(int sortID) throws IllegalArgumentException
Database
toCriteria
in interface Database
IllegalArgumentException
protected abstract DatabaseObject.MetaData getNewMetaData(String name) throws IOException
IOException
protected eve.database.implement.DatabaseIndex registerIndex(eve.database.implement.DatabaseIndex index, String name) throws IOException
IOException
public OutputStream openStreamForWriting(String name, boolean append) throws IOException
Database
openStreamForWriting
in interface Database
name
- 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
Database
openStreamForReplacing
in interface Database
name
- The name of the meta-data Stream.IOException
- if an error occurs.public InputStream openStreamForReading(String name) throws IOException
Database
openStreamForReading
in interface Database
name
- 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
Database
deleteStream
in interface Database
name
- The name of the meta-data Stream.IOException
- if an error occurs.public long getStreamLength(String name) throws IOException
Database
getStreamLength
in interface Database
name
- the name of the Stream.IOException
- if an error occurs.protected byte[] getMetaData(String name) throws IOException
IOException
protected void setMetaData(String name, byte[] data) throws IOException
IOException
protected void overwriteMetaData(String name, byte[] data) throws IOException
IOException
protected FieldSortEntry findField(int fieldID)
protected FieldSortEntry findSort(int fieldID)
public void setObjectClass(Object objectOrClass) throws IllegalArgumentException
setObjectClass
in interface Database
objectOrClass
- IllegalArgumentException
public Class getObjectClass()
Database
getObjectClass
in interface Database
public int[] setSorts(Object objectOrClass) throws IllegalArgumentException
Database
setSorts
in interface Database
objectOrClass
- 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
Database
setSorts
in interface Database
objectOrClass
- 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
Database
ensureSorts
in interface Database
objectOrClass
- the Class of the object or an instance of the object.sorts
- a String specifying the sort criteria to use.IllegalArgumentException
public int[] overrideSorts(Object objectOrClass, String sorts) throws IllegalArgumentException
Database
overrideSorts
in interface Database
objectOrClass
- the Class of the object or an instance of the object.sorts
- a String specifying the sort criteria to use.IllegalArgumentException
public int[] setSorts(Object dataObject, String sorts, int operation) throws IllegalArgumentException
IllegalArgumentException
public int[] setFields(Object objectOrClass) throws IllegalArgumentException
setFields
in interface Database
objectOrClass
- The object or class of the object to be used for data transfer.IllegalArgumentException
public int[] setFields(Object objectOrClass, String fields) throws IllegalArgumentException
setFields
in interface Database
objectOrClass
- 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:
IllegalArgumentException
public int[] setFields(Object objectOrClass, String fields, String headers) throws IllegalArgumentException
setFields
in interface Database
objectOrClass
- 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.IllegalArgumentException
public int[] ensureFields(Object objectOrClass, String fields, String headers) throws IllegalArgumentException
Database
ensureFields
in interface Database
objectOrClass
- 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.IllegalArgumentException
public int[] overrideFields(Object objectOrClass, String fields, String headers) throws IllegalArgumentException
Database
overrideFields
in interface Database
objectOrClass
- 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.IllegalArgumentException
protected int[] setFields(Object objectOrClass, String fields, String headers, int mode) throws IllegalArgumentException
IllegalArgumentException
public 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 Database
public int[] findFields(String fieldNames)
findFields
in interface Database
public String getFieldName(int fieldID)
Database
getFieldName
in interface Database
public String getFieldHeader(int fieldID)
Database
getFieldHeader
in interface Database
public boolean setFieldHeader(int fieldID, String newHeader)
Database
setFieldHeader
in interface Database
public String getSortName(int sortID)
Database
getSortName
in interface Database
public int[] getSortFields(int sortID)
Database
getSortFields
in interface Database
public int getSortOptions(int sortID)
Database
getSortOptions
in interface Database
public int getFieldType(int fieldID)
Database
getFieldType
in interface Database
public int setOptions(int optionsToSet, int optionsToClear)
Database
setOptions
in interface Database
optionsToSet
- any of the DatabaseTypes.OPTION_XXXX values OR'ed together.optionsToClear
- any of the DatabaseTypes.OPTION_XXXX values OR'ed together.public int[] getFields()
Database
public int[] getSorts()
Database
public int addField(String fieldName, int fieldType) throws IllegalArgumentException
addField
in interface Database
fieldName
- The name of the new field.fieldType
- The type of the new field.IllegalArgumentException
public int findSort(String sortName)
Database
public int addSort(String sortName, int options, int field) throws IllegalArgumentException
addSort
in interface Database
IllegalArgumentException
public int addSort(String sortName, int options, int field1, int field2, int field3, int field4) throws IllegalArgumentException
addSort
in interface Database
sortName
- 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.IllegalArgumentException
public int addSort(String sortName, int options, String fieldList) throws IllegalArgumentException
addSort
in interface Database
sortName
- 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 Database
fieldID
- the ID of the field to remove.public void removeSort(int sortID)
Database
removeSort
in interface Database
sortID
- 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 Database
h
- 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
Database
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 Database
h
- 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
Database
indexBy
in interface Database
sortID
- A valid sort ID for the database.IOException
- If an IO error occured using the database.public boolean isIndexedBy(int sortID)
Database
isIndexedBy
in interface Database
public IndexEntry[] getIndexes()
Database
getIndexes
in interface Database
public int getIndexSort(String indexName)
protected eve.database.implement.DatabaseIndex createIndex(Handle h, String name) throws IllegalArgumentException, IOException
IllegalArgumentException
IOException
protected boolean saveIndex(Handle h, eve.database.implement.DatabaseIndex di) throws IOException
IOException
protected eve.database.implement.DatabaseIndex createIndex(Handle h, IndexEntry ie) throws IllegalArgumentException, IOException
IllegalArgumentException
IOException
protected boolean doReIndex(Handle h) throws IOException
IOException
protected eve.database.implement.DatabaseIndex openIndex(Handle h, IndexEntry ie) throws IllegalArgumentException, IOException
IllegalArgumentException
IOException
protected eve.database.implement.DatabaseIndex doOpenIndex(Handle h, String name) throws IllegalArgumentException, IOException
IllegalArgumentException
IOException
protected eve.database.implement.DatabaseIndex doOpenIndex(Handle h, IndexEntry ie) throws IllegalArgumentException, IOException
IllegalArgumentException
IOException
protected void recordIndexChange(FoundEntriesObject obj, byte[] toRecord, int offset, int length)
protected long getNewOID() throws IOException
IOException
public int getIdentifier() throws IOException
Database
getIdentifier
in interface Database
IOException
public void setSynchronizedTime(int remoteDatabaseID, Time syncTime) throws IOException
setSynchronizedTime
in interface Database
IOException
public Time getSynchronizedTime(int remoteDatabaseID) throws IOException
getSynchronizedTime
in interface Database
IOException
protected void updateTypes(FieldSortEntry fse)
public void save() throws IOException
Database
save
in interface Database
IOException
- if an error occurs.public Object getNewDataObject() throws IllegalStateException
getNewDataObject
in interface Database
IllegalStateException
- if no object class is specified or the
object could not be instantiated.public boolean isInstanceOfDataObject(Object data)
isInstanceOfDataObject
in interface Database
data
- the object to check.public void setDataValidator(DataValidator validator)
Database
setDataValidator
in interface Database
validator
- A validator or null to clear the validator.public void modifyField(int fieldID, int modifier, Object modifierData) throws IllegalArgumentException, IOException
Database
modifyField
in interface Database
fieldID
- 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.IOException
protected 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
IOException
protected abstract void doLoad(DatabaseEntryObject entry) throws IOException, IllegalStateException
IOException
IllegalStateException
protected abstract void doMarkAsDeleted(DatabaseEntryObject entry) throws IOException
IOException
protected abstract void doErase(DatabaseEntryObject entry) throws IOException
IOException
protected abstract void removeFieldIDs(int fieldID) throws IOException
IOException
public Time getTimeOfDeletion(long oid, Time dest) throws IOException
Database
getTimeOfDeletion
in interface Database
oid
- The OID of the deleted entry.dest
- an optional destination time. If this is null the a new Time will
be created.IOException
public long[] getDeletedSince(Time t) throws IOException
getDeletedSince
in interface Database
IOException
public void addSpecialField(int id) throws IllegalArgumentException
Database
addSpecialField
in interface Database
IllegalArgumentException
public boolean enableSynchronization(Handle h, int syncOptions) throws IOException
Database
enableSynchronization
in interface Database
syncOptions
- any of the SYNC_XXX values ORed together.IOException
public void enableSynchronization(int syncOptions) throws IOException
Database
enableSynchronization
in interface Database
syncOptions
- any of the SYNC_XXX values ORed together.IOException
protected 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
Database
The getNext() method of the returned iterator may throw a DatabaseIOException if there is an IO error when retrieving the next entry.
entries
in interface Database
IOException
public Iterator entries(ObjectFinder finder) throws IOException
Database
The getNext() method of the returned iterator may throw a DatabaseIOException if there is an IO error when retrieving the next entry.
entries
in interface Database
IOException
protected long doEstimateEntriesCount() throws IOException
IOException
public long estimateEntriesCount() throws IOException
Database
estimateEntriesCount
in interface Database
IOException
- on error.public Handle countEntries()
Database
countEntries
in interface Database
protected abstract FoundEntries getAllFoundEntries(Handle h) throws IOException
IOException
protected FoundEntries getFoundEntries(Handle h, int sortId, EntrySelector selector, ObjectFinder finder, Comparer c, boolean useIndexes) throws IOException
IOException
protected FoundEntries getFoundEntries(Handle h, int sortId, EntrySelector selector, ObjectFinder finder) throws IOException
IOException
protected FoundEntries getFoundEntriesForIndex(Handle h, IndexEntry ie) throws IOException
IOException
public FoundEntries getFoundEntries(Handle h, Comparer comparer) throws IOException
Database
getFoundEntries
in interface Database
h
- an optional Handle used to monitor and possibly abort the process.comparer
- This is used to sort the entries.IOException
public Handle getFoundEntries(int sortID)
Database
getFoundEntries
in interface Database
sortID
- The sortID to use. If this is 0 the entries are not sorted.public Handle getFoundEntries(int sortID, EntrySelector selector)
Database
getFoundEntries
in interface Database
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.public Handle getFoundEntries(int sortID, Object primarySearchFields)
Database
getFoundEntries
in interface Database
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.public Handle getFoundEntries(int sortID, ObjectFinder finder)
Database
getFoundEntries
in interface Database
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.public Handle getFoundEntries(Comparer comparer)
Database
getFoundEntries
in interface Database
comparer
- This is used to sort the entries.public FoundEntries getFoundEntries(Handle h, String indexName) throws IOException, IllegalArgumentException
Database
getFoundEntries
in interface Database
h
- an optional Handle used to monitor and possibly abort the process.indexName
- a valid index name.IOException
IllegalArgumentException
public Handle getFoundEntries(String indexName)
Database
getFoundEntries
in interface Database
indexName
- a valid index name.public FoundEntries getEntries() throws IOException
Database
getEntries
in interface Database
IOException
public FoundEntries getEntries(int sortID) throws IOException
Database
getEntries
in interface Database
sortID
- The sortID to use. If this is 0 the entries are not sorted.IOException
public FoundEntries getFoundEntries(Handle h, int sortID, ObjectFinder finder) throws IOException
Database
getFoundEntries
in interface Database
h
- 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.IOException
public FoundEntries getFoundEntries(Handle h, int sortID, EntrySelector selector) throws IOException
Database
getFoundEntries
in interface Database
h
- 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.IOException
public FoundEntries getFoundEntries(Handle h, int sortID) throws IOException
Database
getFoundEntries
in interface Database
h
- 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.IOException
public FoundEntries getFoundEntries(Handle h, int sortID, Object primarySearchFields) throws IOException
Database
getFoundEntries
in interface Database
h
- 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.IOException
public long getCurrentState()
Database
getCurrentState
in interface Database
public boolean hasChangedSince(long previousState)
Database
hasChangedSince
in interface Database
public void change()
Database
public EventDispatcher getEventDispatcher()
Database
getEventDispatcher
in interface Database
protected 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 Database
IOException
- if an IO error occurs.public void openLookup() throws IOException
openLookup
in interface Database
IOException
- if an IO error occurs.public void closeLookup() throws IOException
closeLookup
in interface Database
IOException
- if an IO error occurs.protected void markForReIndex(boolean needReIndex) throws IOException
IOException
public boolean reIndex(Handle h) throws IOException
Database
If you close the database without doing reIndex, it will be reIndexed automatically the next time it is opened.
reIndex
in interface Database
h
- 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
Database
append
in interface Database
IOException
protected void doAppend(DatabaseEntry de) throws IOException
IOException