ewe.database
Class DatabaseObject

java.lang.Object
  extended byewe.database.DatabaseObject
All Implemented Interfaces:
Database, DatabaseTypes, HasProperties
Direct Known Subclasses:
RecordDatabaseObject

public abstract class DatabaseObject
extends Object
implements Database

A building block for a Database. It handles everything to do with storing fields and sorts.


Nested Class Summary
protected  class DatabaseObject.MetaData
           
 
Field Summary
protected  DatabaseEntry buffer
           
protected  ByteArray byteArray
           
protected  DataValidator dataValidator
           
protected  DataProcessor decryptor
           
protected  DataProcessor encryptor
           
protected  boolean encryptorNotSet
           
protected  WeakSet entries
           
protected  RandomAccessFile file
           
protected  WeakSet foundEntries
           
protected  int INDEX_FLAG_DO_REINDEX
           
protected  MetaFlag indexFlag
           
protected  IntArray intArray
           
protected  Lock 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
           
 
Fields inherited from interface ewe.database.Database
CreatedSortName, FIELD_MODIFIER_INTEGER_AUTO_INCREMENT, ModifiedBySortName, ModifiedSortName, OidSortName, SYNC_SLOW, SYNC_STORE_CREATION_DATE, SYNC_STORE_MODIFICATION_DATE, SYNC_STORE_MODIFIED_BY, SyncSortName
 
Fields inherited from interface ewe.database.DatabaseTypes
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, 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 Summary
DatabaseObject()
           
 
Method Summary
 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  ewe.database.DatabaseIndex createIndex(Handle h, IndexEntry ie)
           
protected  ewe.database.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  ewe.database.DatabaseIndex doOpenIndex(Handle h, IndexEntry ie)
           
protected  ewe.database.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  ewe.database.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()
           
 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)
          These deal with fields and sorts and specs.
protected  long getNewOID()
           
 Reflect 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.
 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  ewe.database.DatabaseIndex makeNewIndex(String name)
           
protected  void markForReIndex(boolean needReIndex)
           
 void modifyField(int fieldID, int modifier, Object modifierData)
          Modify a field in some way.
protected  ewe.database.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.
 Stream openStreamForReading(String name)
          Open a Stream into the database to read some sort of meta-data.
 Stream openStreamForReplacing(String name)
          Open a Stream into the database to save some sort of meta-data.
 Stream 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  ewe.database.DatabaseIndex registerIndex(ewe.database.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.
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, ewe.database.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)
           
 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.
 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 objectOrClass, String sorts, int operation)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 
Methods inherited from interface ewe.database.Database
close, countDeletedEntries, delete, deleteMetaData, entries, eraseDeletedEntries, eraseDeletedEntry, getDeletedEntries, getDeletedEntry, getMetaData, getModifiedTime, metaDataLength, readMetaData, readMetaDataInt, rename, setModifiedTime, writeMetaData, writeMetaDataInt
 

Field Detail

file

protected RandomAccessFile file

stream

protected DatabaseStream stream

decryptor

protected DataProcessor decryptor

encryptor

protected DataProcessor encryptor

myLocale

protected Locale myLocale

byteArray

protected ByteArray byteArray

foundEntries

protected WeakSet foundEntries

entries

protected WeakSet entries

now

protected Time now

lock

protected Lock lock

buffer

protected DatabaseEntry buffer

openMode

protected String openMode

openIndexes

protected Hashtable openIndexes

openModifiers

protected Vector openModifiers

dataValidator

protected DataValidator dataValidator

encryptorNotSet

protected boolean encryptorNotSet

INDEX_FLAG_DO_REINDEX

protected final int INDEX_FLAG_DO_REINDEX
See Also:
Constant Field Values

indexFlag

protected MetaFlag indexFlag

SETFIELDS_MODE_SET

protected static final int SETFIELDS_MODE_SET
See Also:
Constant Field Values

SETFIELDS_MODE_ENSURE

protected static final int SETFIELDS_MODE_ENSURE
See Also:
Constant Field Values

SETFIELDS_MODE_OVERRIDE

protected static final int SETFIELDS_MODE_OVERRIDE
See Also:
Constant Field Values

intArray

protected IntArray intArray
Constructor Detail

DatabaseObject

public DatabaseObject()
Method Detail

getEntriesCount

public abstract long getEntriesCount()
                              throws IOException
Description copied from interface: Database
This will return the number of entries in the database if known. If it is unknown it will return -1 and you can call either estimateEntriesCount() or countEntries() to to get an entry count.

Specified by:
getEntriesCount in interface Database
Returns:
the number of entries in the database if known, or -1 if unknown.
Throws:
IOException - on error.

isOpenForReadWrite

public boolean isOpenForReadWrite()
Description copied from interface: Database
This should return true if the Database is open in read/write mode, or false if it is open in read-only mode.

Specified by:
isOpenForReadWrite in interface Database

getProperties

public PropertyList getProperties()
Description copied from interface: HasProperties
Get the PropertyList object associated with this object.

Specified by:
getProperties in interface HasProperties

useEncryption

public boolean useEncryption(DataProcessor decryptor,
                             DataProcessor encryptor)
                      throws IOException,
                             IllegalArgumentException
Description copied from interface: Database
Use this when opening the database and accessing the data. The specified decryptor/encryptor must match those used when the setEncryption() method was used to set the encryption for the database. The Database may validate the data at this point and may throw an IOException if it is determined that these are invalid for the database.

Specified by:
useEncryption in interface Database
Parameters:
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.
Throws:
IOException
IllegalArgumentException

usePassword

public boolean usePassword(Object obj)
Description copied from interface: Database
Use this when opening the database and accessing the data. The specified password must match those used when the setPassword() method was used to set the encryption for the database. The Database may validate the data at this point and may throw an IOException if it is determined that the password is invalid for the database.

Specified by:
usePassword in interface Database

setEncryption

public void setEncryption(DataProcessor decryptor,
                          DataProcessor encryptor)
                   throws IllegalArgumentException,
                          IOException
Description copied from interface: Database
Use this when the Database is initialized to set the decryptor and encryptor for the data. It must be used before any data is added. Once it has been set it cannot be changed later.

Specified by:
setEncryption in interface Database
Throws:
IllegalArgumentException
IOException

setPassword

public void setPassword(String password)
                 throws IllegalArgumentException,
                        IOException
Description copied from interface: Database
Use this when the Database is initialized to set the encryption key for the database.

Specified by:
setPassword in interface Database
Parameters:
password - a string to be used as the password. Choose a mix of numeric and letters for better security.
Throws:
IOException
IllegalArgumentException

getLocale

public Locale getLocale()
Description copied from interface: Database
Set the locale being used with the Database.

Specified by:
getLocale in interface Database

setLocale

public void setLocale(Locale locale)
Description copied from interface: Database
Set the locale to be used with the Database.

Specified by:
setLocale in interface Database

makeNewData

protected abstract DatabaseEntry makeNewData()

makeNewFoundEntries

protected abstract FoundEntries makeNewFoundEntries()

makeNewIndex

protected abstract ewe.database.DatabaseIndex makeNewIndex(String name)

registerNewFoundEntries

protected FoundEntries registerNewFoundEntries(FoundEntries fe)

registerIndex

protected ewe.database.DatabaseIndex registerIndex(ewe.database.DatabaseIndex index,
                                                   String name)
                                            throws IOException
Throws:
IOException

findOpenIndex

protected ewe.database.DatabaseIndex findOpenIndex(String indexName)

getEmptyEntries

public FoundEntries getEmptyEntries()
Description copied from interface: Database
This returns an empty FoundEntries object for this Database

Specified by:
getEmptyEntries in interface Database

getNewData

public DatabaseEntry getNewData()
Description copied from interface: Database
Return an empty DatabaseEntry to be used with this database. This method may be used in "Append" mode to get a DatabaseEntry which you can use to append entries to the database.

Specified by:
getNewData in interface Database

getMyFoundEntries

protected Iterator getMyFoundEntries()

getMyDatabaseEntries

protected Iterator getMyDatabaseEntries()

hasFoundEntries

protected boolean hasFoundEntries()

hasDatabaseEntries

protected boolean hasDatabaseEntries()

toCriteria

public int[] toCriteria(int sortID)
                 throws IllegalArgumentException
Description copied from interface: Database
Convert the sortID to a Criteria array, used by a number of Database functions.

Specified by:
toCriteria in interface Database
Throws:
IllegalArgumentException

getNewMetaData

protected abstract DatabaseObject.MetaData getNewMetaData(String name)
                                                   throws IOException
These deal with fields and sorts and specs.

Throws:
IOException

openStreamForWriting

public Stream openStreamForWriting(String name,
                                   boolean append)
                            throws IOException
Description copied from interface: Database
Open a Stream into the database to save some sort of meta-data. Calling this method does not guarantee a consistent state if an error occurs. That is to say, if an error occurs before close() is called on the Stream, then it is possible that incomplete data will be saved.

Specified by:
openStreamForWriting in interface Database
Parameters:
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.
Returns:
A Stream that you can write meta-data to.
Throws:
IOException - if an error occurs.

openStreamForReplacing

public Stream openStreamForReplacing(String name)
                              throws IOException
Description copied from interface: Database
Open a Stream into the database to save some sort of meta-data. Calling this method will guarantee a consistent state if an error occurs. That is to say, if an error occurs before close() is called on the Stream, then the new data is lost and the original data (if present) will still be accessible for reading the next time the Database is opened. If the close() method completes successfully, then the new data will then be available for reading.

Specified by:
openStreamForReplacing in interface Database
Parameters:
name - The name of the meta-data Stream.
Returns:
A Stream that you can write meta-data to.
Throws:
IOException - if an error occurs.

openStreamForReading

public Stream openStreamForReading(String name)
                            throws IOException
Description copied from interface: Database
Open a Stream into the database to read some sort of meta-data.

Specified by:
openStreamForReading in interface Database
Parameters:
name - The name of the meta-data Stream.
Returns:
A Stream that you can write meta-data to.
Throws:
IOException - if an error occurs or if the Stream does not exist.

deleteStream

public boolean deleteStream(String name)
                     throws IOException
Description copied from interface: Database
Delete a Stream from the Database.

Specified by:
deleteStream in interface Database
Parameters:
name - The name of the meta-data Stream.
Returns:
true if the stream was found and deleted, false if it was not found.
Throws:
IOException - if an error occurs.

getStreamLength

public long getStreamLength(String name)
                     throws IOException
Description copied from interface: Database
Returns the length of a meta-data Stream stored in the Database, or -1 if the named Stream does not exist. You can use this method to test for the existance of a Stream.

Specified by:
getStreamLength in interface Database
Parameters:
name - the name of the Stream.
Returns:
the length of a meta-data Stream stored in the Database, or -1 if the named Stream
Throws:
IOException - if an error occurs.

getMetaData

protected byte[] getMetaData(String name)
                      throws IOException
Throws:
IOException

setMetaData

protected void setMetaData(String name,
                           byte[] data)
                    throws IOException
Throws:
IOException

overwriteMetaData

protected void overwriteMetaData(String name,
                                 byte[] data)
                          throws IOException
Throws:
IOException

findField

protected FieldSortEntry findField(int fieldID)

findSort

protected FieldSortEntry findSort(int fieldID)

setObjectClass

public void setObjectClass(Object objectOrClass)
                    throws IllegalArgumentException
This is used to set the class of the object used for data transfer to and from the table. If you call setFields(Object objectOrClass,String fields) then you do not need to call this method as it will be done for you.

Specified by:
setObjectClass in interface Database
Parameters:
objectOrClass -
Throws:
IllegalArgumentException

getObjectClass

public Reflect getObjectClass()
Description copied from interface: Database
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.

Specified by:
getObjectClass in interface Database
Returns:

setSorts

public int[] setSorts(Object objectOrClass)
               throws IllegalArgumentException
Description copied from interface: Database
Set the sorts of the Database as specified by the object provided. The object must declare a public variable named "_sorts" of type String.

Specified by:
setSorts in interface Database
Parameters:
objectOrClass - the Class of the object or an instance of the object.
Returns:
an array if IDs, one for each sort.
Throws:
IllegalArgumentException - if a sort conflicts with an already saved sort.

setSorts

public int[] setSorts(Object objectOrClass,
                      String sorts)
               throws IllegalArgumentException
Description copied from interface: Database
Set the sorts of the Database as specified by the object provided.

Specified by:
setSorts in interface Database
Parameters:
objectOrClass - the Class of the object or an instance of the object.
sorts - a String specifying the sort criteria to use.
Returns:
an array if IDs, one for each sort.
Throws:
IllegalArgumentException - if a sort conflicts with an already saved sort.

ensureSorts

public int[] ensureSorts(Object objectOrClass,
                         String sorts)
                  throws IllegalArgumentException
Description copied from interface: Database
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. This means that this method can be called repeatedly with the same data without causing an error.

Specified by:
ensureSorts in interface Database
Parameters:
objectOrClass - the Class of the object or an instance of the object.
sorts - a String specifying the sort criteria to use.
Returns:
an array if IDs, one for each sort.
Throws:
IllegalArgumentException

overrideSorts

public int[] overrideSorts(Object objectOrClass,
                           String sorts)
                    throws IllegalArgumentException
Description copied from interface: Database
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.

Specified by:
overrideSorts in interface Database
Parameters:
objectOrClass - the Class of the object or an instance of the object.
sorts - a String specifying the sort criteria to use.
Returns:
an array if IDs, one for each sort.
Throws:
IllegalArgumentException

setSorts

public int[] setSorts(Object objectOrClass,
                      String sorts,
                      int operation)
               throws IllegalArgumentException
Throws:
IllegalArgumentException

setFields

public int[] setFields(Object objectOrClass)
                throws IllegalArgumentException
Set the fields for the DataTable, which must match fields in the objectOrClass transfer object.

Specified by:
setFields in interface Database
Parameters:
objectOrClass - The object or class of the object to be used for data transfer.
Returns:
an array of integers representing the field IDs.
Throws:
IllegalArgumentException

setFields

public int[] setFields(Object objectOrClass,
                       String fields)
                throws IllegalArgumentException
Set the fields for the DataTable, which must match fields in the objectOrClass transfer object.

Specified by:
setFields in interface Database
Parameters:
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:
  • int
  • long
  • double
  • boolean
  • String
  • Date
  • byte []
Returns:
an array of integers representing the field IDs.
Throws:
IllegalArgumentException

setFields

public int[] setFields(Object objectOrClass,
                       String fields,
                       String headers)
                throws IllegalArgumentException
Set the fields for the DataTable, which must match fields in the objectOrClassOrReflect transfer object.

Specified by:
setFields in interface Database
Parameters:
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:
  • int
  • long
  • double
  • boolean
  • String
  • Date
  • byte []
headers - An optional comma separated list of headers.
Returns:
an array of integers representing the field IDs.
Throws:
IllegalArgumentException

ensureFields

public int[] ensureFields(Object objectOrClass,
                          String fields,
                          String headers)
                   throws IllegalArgumentException
Description copied from interface: Database
Similar to setFields() except that no error is thrown if any fields of the same name and type already exist. This means that this method can be called repeatedly with the same data without causing an error.

Specified by:
ensureFields in interface Database
Parameters:
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.
Throws:
IllegalArgumentException

overrideFields

public int[] overrideFields(Object objectOrClass,
                            String fields,
                            String headers)
                     throws IllegalArgumentException
Description copied from interface: Database
Similar to setFields() except that no error is thrown if any fields of the same name and type already exist. This means that this method can be called repeatedly with the same data without causing an error. This will also override any previous fields with the same name and different type.

Specified by:
overrideFields in interface Database
Parameters:
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.
Throws:
IllegalArgumentException

setFields

protected int[] setFields(Object objectOrClass,
                          String fields,
                          String headers,
                          int mode)
                   throws IllegalArgumentException
Throws:
IllegalArgumentException

findField

public int findField(String fieldName)
Find the FieldID of a named field. This is NOT case sensistive.

Specified by:
findField in interface Database
Parameters:
fieldName - The name of the field.
Returns:
The field id, or 0 if not found.

getField

public int getField(String fieldName)
             throws IllegalArgumentException
Similar to findField(), find the FieldID of a named field. This is NOT case sensistive.

Parameters:
fieldName - The name of the field.
Returns:
The field id.
Throws:
IllegalArgumentException - if the field is not found.

findFields

public int[] findFields(String[] fieldNames)
Get an array of fieldIds for an array of field names.

Specified by:
findFields in interface Database

findFields

public int[] findFields(String fieldNames)
Get an array of fieldIds for a comma separated list of field names.

Specified by:
findFields in interface Database

getFieldName

public String getFieldName(int fieldID)
Description copied from interface: Database
Get the name for a specified field ID.

Specified by:
getFieldName in interface Database

getFieldHeader

public String getFieldHeader(int fieldID)
Description copied from interface: Database
Get the header for a specified field ID.

Specified by:
getFieldHeader in interface Database

setFieldHeader

public boolean setFieldHeader(int fieldID,
                              String newHeader)
Description copied from interface: Database
Set the header for a specified field ID.

Specified by:
setFieldHeader in interface Database
Returns:
true if successful.

getSortName

public String getSortName(int sortID)
Description copied from interface: Database
Get the name of a Sort.

Specified by:
getSortName in interface Database

getSortFields

public int[] getSortFields(int sortID)
Description copied from interface: Database
Get the fields by which the Sort will sort.

Specified by:
getSortFields in interface Database
Returns:
an array of 1 or more fields to sort by.

getSortOptions

public int getSortOptions(int sortID)
Description copied from interface: Database
Get the options associated with the sortID.

Specified by:
getSortOptions in interface Database

getFieldType

public int getFieldType(int fieldID)
Description copied from interface: Database
Get the type of a field.

Specified by:
getFieldType in interface Database

getFields

public int[] getFields()
Description copied from interface: Database
Get the IDs of all the fields.

Specified by:
getFields in interface Database

getSorts

public int[] getSorts()
Description copied from interface: Database
Get the IDs of all the sorts.

Specified by:
getSorts in interface Database

addField

public int addField(String fieldName,
                    int fieldType)
             throws IllegalArgumentException
Add a new field. This will return the ID of the new field or throw an exception on failure. This will method will fail if: 1. An invalid fieldType is specified. 2. An already used fieldName is specified. 3. There are already the maximum of MAX_ID fields.

Specified by:
addField in interface Database
Parameters:
fieldName - The name of the new field.
fieldType - The type of the new field.
Returns:
the ID of the newly added field.
Throws:
IllegalArgumentException

findSort

public int findSort(String sortName)
Description copied from interface: Database
Get the ID of a named sort criteria.

Specified by:
findSort in interface Database
Parameters:
sortName - The name of the sort criteria.
Returns:
The ID of the sort criteria or 0 if it is not found.

addSort

public int addSort(String sortName,
                   int options,
                   int field)
            throws IllegalArgumentException
Create a new sort criteria. Returns the ID of the new sort.

Specified by:
addSort in interface Database
Throws:
IllegalArgumentException

addSort

public int addSort(String sortName,
                   int options,
                   int field1,
                   int field2,
                   int field3,
                   int field4)
            throws IllegalArgumentException
Create a new sort criteria allowing you to specify up to four fields. Set any unused sort fields to zero. Returns the ID of the new sort.

Specified by:
addSort in interface Database
Throws:
IllegalArgumentException

addSort

public int addSort(String sortName,
                   int options,
                   String fieldList)
            throws IllegalArgumentException
Create a new sort criteria allowing you to specify up to four fields.

Specified by:
addSort in interface Database
Parameters:
sortName - The name of the sort.
options - Sorting options.
fieldList - A comma separated field list.
Returns:
The ID of the new sort.
Throws:
IllegalArgumentException - if any of the fields could not be found, or if too many fields are specified.

removeField

public 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. This does not happen with addField().

Specified by:
removeField in interface Database
Parameters:
fieldID - the ID of the field to remove.

removeSort

public void removeSort(int sortID)
Description copied from interface: Database
Remove a Sort.

Specified by:
removeSort in interface Database
Parameters:
sortID - the ID of the sort to remove.

findIndex

protected IndexEntry findIndex(String name,
                               int sortID)

findIndex

protected IndexEntry findIndex(int sortID,
                               Comparer c)

indexBy

public boolean indexBy(Handle h,
                       Class comparer,
                       String name)
                throws IOException,
                       IllegalArgumentException
This tells the Database to keep an index using a particular Comparer class and distinct name. If an index of the same name is already being kept then this will simply return true immediately. Otherwise the index will be created.

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.

Specified by:
indexBy in interface Database
Parameters:
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.
Returns:
true if the operation completed successfully, false if it was aborted.
Throws:
IOException - If an IO error occured using the database.
IllegalArgumentException - if the comparer or name is invalid.

indexBy

public boolean indexBy(Handle h,
                       int sortID,
                       String name)
                throws IllegalArgumentException,
                       IOException
Description copied from interface: Database
This tells the Database to keep an index for a particular sort ID and optional distinct name. If an index of the same name and sortID is already being kept then this will simply return true immediately. Otherwise the index will be created.

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.

Specified by:
indexBy in interface Database
Parameters:
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.
Returns:
true if the operation completed successfully, false if it was aborted.
Throws:
IllegalArgumentException - if the sort ID is invalid.
IOException - If an IO error occured using the database.

indexBy

public void indexBy(int sortID)
             throws IOException
Description copied from interface: Database
This is a convenience method for the other indexBy method. It will simply call indexBy(Handle h, int sortID, String name) using a null "h" and "name" parameters.

Specified by:
indexBy in interface Database
Parameters:
sortID - A valid sort ID for the database.
Returns:
true if the operation completed successfully, false if it was aborted.
Throws:
IOException - If an IO error occured using the database.

isIndexedBy

public boolean isIndexedBy(int sortID)
Description copied from interface: Database
This returns if the Database has at least one index that uses the specified sort ID.

Specified by:
isIndexedBy in interface Database

getIndexes

public IndexEntry[] getIndexes()
Description copied from interface: Database
This returns all the indexes used by the Database. You can use getIndexSort(String indexName) to find out which sort ID is being used by each of the indexes returned.

Specified by:
getIndexes in interface Database
Returns:
An array of index names.

getIndexSort

public int getIndexSort(String indexName)

createIndex

protected ewe.database.DatabaseIndex createIndex(Handle h,
                                                 String name)
                                          throws IllegalArgumentException,
                                                 IOException
Throws:
IllegalArgumentException
IOException

saveIndex

protected boolean saveIndex(Handle h,
                            ewe.database.DatabaseIndex di)
                     throws IOException
Throws:
IOException

createIndex

protected ewe.database.DatabaseIndex createIndex(Handle h,
                                                 IndexEntry ie)
                                          throws IllegalArgumentException,
                                                 IOException
Throws:
IllegalArgumentException
IOException

doReIndex

protected boolean doReIndex(Handle h)
                     throws IOException
Throws:
IOException

openIndex

protected ewe.database.DatabaseIndex openIndex(Handle h,
                                               IndexEntry ie)
                                        throws IllegalArgumentException,
                                               IOException
Throws:
IllegalArgumentException
IOException

doOpenIndex

protected ewe.database.DatabaseIndex doOpenIndex(Handle h,
                                                 String name)
                                          throws IllegalArgumentException,
                                                 IOException
Throws:
IllegalArgumentException
IOException

doOpenIndex

protected ewe.database.DatabaseIndex doOpenIndex(Handle h,
                                                 IndexEntry ie)
                                          throws IllegalArgumentException,
                                                 IOException
Throws:
IllegalArgumentException
IOException

recordIndexChange

protected void recordIndexChange(FoundEntriesObject obj,
                                 byte[] toRecord,
                                 int offset,
                                 int length)

getNewOID

protected long getNewOID()
                  throws IOException
Throws:
IOException

getIdentifier

public int getIdentifier()
                  throws IOException
Description copied from interface: Database
Get a unique identifier for this database - used for synchronizing.

Specified by:
getIdentifier in interface Database
Throws:
IOException

setSynchronizedTime

public void setSynchronizedTime(int remoteDatabaseID,
                                Time syncTime)
                         throws IOException
Specified by:
setSynchronizedTime in interface Database
Throws:
IOException

getSynchronizedTime

public Time getSynchronizedTime(int remoteDatabaseID)
                         throws IOException
Specified by:
getSynchronizedTime in interface Database
Throws:
IOException

updateTypes

protected void updateTypes(FieldSortEntry fse)

save

public void save()
          throws IOException
Description copied from interface: Database
Save the Database specs to permanent storage. Call this after changing fields and sorts.

Specified by:
save in interface Database
Throws:
IOException - if an error occurs.

getNewDataObject

public Object getNewDataObject()
                        throws IllegalStateException
Create and return a new instance of the object class assigned to the database.

Specified by:
getNewDataObject in interface Database
Returns:
a new instance of the object class assigned to the database.
Throws:
IllegalStateException - if no object class is specified or the object could not be instantiated.

isInstanceOfDataObject

public boolean isInstanceOfDataObject(Object data)
Return if the specified object is an instance of the data transfer object assigned in setObjectClass();

Specified by:
isInstanceOfDataObject in interface Database
Parameters:
data - the object to check.
Returns:
true if the specified object is an instance of the data transfer object assigned in setObjectClass();

setDataValidator

public void setDataValidator(DataValidator validator)
Description copied from interface: Database
Set a DataValidator to validate data before it is saved in the Database. Call save() on the Database to save the validator.

Specified by:
setDataValidator in interface Database
Parameters:
validator - A validator or null to clear the validator.

modifyField

public void modifyField(int fieldID,
                        int modifier,
                        Object modifierData)
                 throws IllegalArgumentException,
                        IOException
Description copied from interface: Database
Modify a field in some way.

Specified by:
modifyField in interface Database
Parameters:
fieldID - The id of the field to modify.
modifier - one of the FIELD_MODIFIER_XXX values appropriate for the field type.
modifierData - Some data dependant on the field modifier used.
Throws:
IllegalArgumentException - if the modifier is not appropriate for the field or if the data is not the correct type for the modifier.
IOException

load

protected void load(String mode,
                    boolean ignoreInconsistentState)
             throws IOException,
                    InconsistentDatabaseStateException
This should be called when the Database is opened.

Throws:
IOException
InconsistentDatabaseStateException

hasField

protected boolean hasField(int fieldID)

doStore

protected abstract boolean doStore(DatabaseEntryObject entry)
                            throws IOException
Return true if the entry is a new entry, false if not.

Throws:
IOException

doLoad

protected abstract void doLoad(DatabaseEntryObject entry)
                        throws IOException,
                               IllegalStateException
Throws:
IOException
IllegalStateException

doMarkAsDeleted

protected abstract void doMarkAsDeleted(DatabaseEntryObject entry)
                                 throws IOException
Throws:
IOException

doErase

protected abstract void doErase(DatabaseEntryObject entry)
                         throws IOException
Throws:
IOException

removeFieldIDs

protected abstract void removeFieldIDs(int fieldID)
                                throws IOException
Throws:
IOException

getTimeOfDeletion

public Time getTimeOfDeletion(long oid,
                              Time dest)
                       throws IOException
Description copied from interface: Database
Return the time of deletion of the specified OID.

Specified by:
getTimeOfDeletion in interface Database
Parameters:
oid - The OID of the deleted entry.
dest - an optional destination time. If this is null the a new Time will be created.
Returns:
the time of deletion or null if the OID was not found in the deleted list.
Throws:
IOException

getDeletedSince

public long[] getDeletedSince(Time t)
                       throws IOException
Get the OIDs of all entries deleted after the specified time (but not AT the specified time).

Specified by:
getDeletedSince in interface Database
Throws:
IOException

addSpecialField

public void addSpecialField(int id)
                     throws IllegalArgumentException
Description copied from interface: Database
Use this to add one of the reserved fields (the XXXX_FIELD) values.

Specified by:
addSpecialField in interface Database
Throws:
IllegalArgumentException

enableSynchronization

public boolean enableSynchronization(Handle h,
                                     int syncOptions)
                              throws IOException
Description copied from interface: Database
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. This is only guaranteed to work when you first initialize a Database. Some implementations may allow you to do this even if records already exists, but if it does not then an IOException will be thrown. This will save the database.

Specified by:
enableSynchronization in interface Database
Throws:
IOException

enableSynchronization

public void enableSynchronization(int syncOptions)
                           throws IOException
Description copied from interface: Database
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. This is only guaranteed to work when you first initialize a Database. Some implementations may allow you to do this even if records already exists, but if it does not then an IOException will be thrown. This will save the database.

Specified by:
enableSynchronization in interface Database
Throws:
IOException

setData

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.

Parameters:
ded - The DatabaseEntry to set.
data - The data object, which must be of the type objectClass or an exception will be thrown.

getData

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.

Parameters:
ded - The DatabaseEntry to set.
data - The data object, which must be of the type objectClass or an exception will be thrown.

entries

public Iterator entries(Object searchData,
                        Comparer comparer)
                 throws IOException
Description copied from interface: Database
This returns an Iterator that you can use to go through the entries in the database. Only the entries that the Comparer returns 0 for when comparing the entry with the searchData will be provided by the getNext() method of the iterator.

The getNext() method of the returned iterator may throw a DatabaseIOException if there is an IO error when retrieving the next entry.

Specified by:
entries in interface Database
Throws:
IOException

entries

public Iterator entries(ObjectFinder finder)
                 throws IOException
Description copied from interface: Database
This returns an Iterator that you can use to go through the entries in the database. Only the entries that the ObjectFinder returns true for lookingFor() will be provided by the getNext() method of the iterator.

The getNext() method of the returned iterator may throw a DatabaseIOException if there is an IO error when retrieving the next entry.

Specified by:
entries in interface Database
Throws:
IOException

doEstimateEntriesCount

protected long doEstimateEntriesCount()
                               throws IOException
Override this to do an estimate on the number of entries if you can't tell the exact number of entries.

Throws:
IOException

estimateEntriesCount

public long estimateEntriesCount()
                          throws IOException
Description copied from interface: Database
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. This method may also return -1, indicating that the database cannot even estimate the number of entries and a countEntries() will need to be done if you want any indication of the size of the database.

Specified by:
estimateEntriesCount in interface Database
Returns:
the estimate of the number of entries in the database, or the exact number if it is known, or -1 if it cannot even estimate the number of entries.
Throws:
IOException - on error.

countEntries

public Handle countEntries()
Description copied from interface: Database
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. Since this may take some time it is done in a separate thread and a Handle is returned that can monitor and stop the count if necessary. On completion the handle's returnValue will be an ewe.sys.Long() object holding the count of the entries.

Specified by:
countEntries in interface Database
Returns:
a Handle which you can monitor and stop the count. On successful completion the returnValue will hold the number of entries.

getAllFoundEntries

protected abstract FoundEntries getAllFoundEntries(Handle h)
                                            throws IOException
Throws:
IOException

getFoundEntries

protected FoundEntries getFoundEntries(Handle h,
                                       int sortId,
                                       EntrySelector selector,
                                       ObjectFinder finder,
                                       Comparer c,
                                       boolean useIndexes)
                                throws IOException
Override this to locate the found entries in your own way. By default this will first create a FoundEntries containing ALL the entries and then sort them, and then either search or filter it and return the subset.

Throws:
IOException

getFoundEntries

protected FoundEntries getFoundEntries(Handle h,
                                       int sortId,
                                       EntrySelector selector,
                                       ObjectFinder finder)
                                throws IOException
Throws:
IOException

getFoundEntriesForIndex

protected FoundEntries getFoundEntriesForIndex(Handle h,
                                               IndexEntry ie)
                                        throws IOException
Throws:
IOException

getFoundEntries

public FoundEntries getFoundEntries(Handle h,
                                    Comparer comparer)
                             throws IOException
Description copied from interface: Database
Get all the entries in the Database sorted by the specific comparer.

Specified by:
getFoundEntries in interface Database
Parameters:
h - an optional Handle used to monitor and possibly abort the process.
comparer - This is used to sort the entries.
Returns:
A new FoundEntries object containing the entries sorted according to the comparer. If the handle is stopped then null will be returned.
Throws:
IOException

getFoundEntries

public Handle getFoundEntries(int sortID)
Description copied from interface: Database
Get all the entries in the Database sorted by the specified sort ID in a new thread.

Specified by:
getFoundEntries in interface Database
Parameters:
sortID - The sortID to use. If this is 0 the entries are not sorted.
Returns:
a Handle that can be used to monitor and abort the process. When the Handle reports Success, the returnValue of the Handle will hold a new FoundEntries object containing the found and sorted entries.

getFoundEntries

public Handle getFoundEntries(int sortID,
                              EntrySelector selector)
Description copied from interface: Database
Get a subset the entries in the Database sorted by the specified sort ID in a new thread.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
a Handle that can be used to monitor and abort the process. When the Handle reports Success, the returnValue of the Handle will hold a new FoundEntries object containing the found and sorted entries.

getFoundEntries

public Handle getFoundEntries(int sortID,
                              Object primarySearchFields)
Description copied from interface: Database
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.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
a Handle that can be used to monitor and abort the process. When the Handle reports Success, the returnValue of the Handle will hold a new FoundEntries object containing the found and sorted entries.

getFoundEntries

public Handle getFoundEntries(int sortID,
                              ObjectFinder finder)
Description copied from interface: Database
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.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
a Handle that can be used to monitor and abort the process. When the Handle reports Success, the returnValue of the Handle will hold a new FoundEntries object containing the found and sorted entries.

getFoundEntries

public Handle getFoundEntries(Comparer comparer)
Description copied from interface: Database
Get all the entries in the Database sorted by the specified Comparer in a new thread.

Specified by:
getFoundEntries in interface Database
Parameters:
comparer - This is used to sort the entries.
Returns:
a Handle that can be used to monitor and abort the process. When the Handle reports Success, the returnValue of the Handle will hold a new FoundEntries object containing the found and sorted entries.

getFoundEntries

public FoundEntries getFoundEntries(Handle h,
                                    String indexName)
                             throws IOException,
                                    IllegalArgumentException
Description copied from interface: Database
Get all the entries in the database sorted according to the specified index.

Specified by:
getFoundEntries in interface Database
Parameters:
h - an optional Handle used to monitor and possibly abort the process.
indexName - a valid index name.
Returns:
A new FoundEntries object containing the entries sorted according to the index. If the handle is stopped then null will be returned.
Throws:
IOException
IllegalArgumentException

getFoundEntries

public Handle getFoundEntries(String indexName)
Description copied from interface: Database
Get all the entries in the Database sorted by the specified index in a new thread.

Specified by:
getFoundEntries in interface Database
Parameters:
indexName - a valid index name.
Returns:
a Handle that can be used to monitor and abort the process. When the Handle reports Success, the returnValue of the Handle will hold a new FoundEntries object containing the sorted entries.

getEntries

public FoundEntries getEntries()
                        throws IOException
Description copied from interface: Database
Get an unsorted FoundEntries representing all the entries in the database.

Specified by:
getEntries in interface Database
Throws:
IOException

getEntries

public FoundEntries getEntries(int sortID)
                        throws IOException
Description copied from interface: Database
Get all the entries in the Database sorted by the specified sort ID.

Specified by:
getEntries in interface Database
Parameters:
sortID - The sortID to use. If this is 0 the entries are not sorted.
Returns:
A new FoundEntries object.
Throws:
IOException

getFoundEntries

public FoundEntries getFoundEntries(Handle h,
                                    int sortID,
                                    ObjectFinder finder)
                             throws IOException
Description copied from interface: Database
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.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
A new FoundEntries object containing references to only those entries that are considered to be what the finder is looking for. If the handle is stopped then null will be returned.
Throws:
IOException

getFoundEntries

public FoundEntries getFoundEntries(Handle h,
                                    int sortID,
                                    EntrySelector selector)
                             throws IOException
Description copied from interface: Database
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.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
A new FoundEntries object containing references to only those entries that are considered equal to the searchData by the comparer. If the handle is stopped then null will be returned.
Throws:
IOException

getFoundEntries

public FoundEntries getFoundEntries(Handle h,
                                    int sortID)
                             throws IOException
Description copied from interface: Database
Get all the entries in the Database sorted by the specified sort ID. This is done in the same thread as the calling thread, but uses a handle to report its progress to other threads. This allows you to put this call in its own thread while allowing other threads to run.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
A new FoundEntries object.
Throws:
IOException

getFoundEntries

public FoundEntries getFoundEntries(Handle h,
                                    int sortID,
                                    Object primarySearchFields)
                             throws IOException
Description copied from interface: Database
Get a subset of the entries in the Database sorted by the specific sort ID and which match the primarySearchFields data.

Specified by:
getFoundEntries in interface Database
Parameters:
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.
Returns:
A new FoundEntries object containing references to only those entries that are considered to match the search data. If the handle is stopped then null will be returned.
Throws:
IOException

getCurrentState

public long getCurrentState()
Description copied from interface: Database
Get the current changed state of the Database. You can check if the Database have been changed later by calling hasChangedSince().

Specified by:
getCurrentState in interface Database
Returns:
a reference to its current state.

hasChangedSince

public boolean hasChangedSince(long previousState)
Description copied from interface: Database
Return if the Database has changed since the previous state.

Specified by:
hasChangedSince in interface Database

change

public void change()
Description copied from interface: Database
Mark the Database as having been changed in some way.

Specified by:
change in interface Database

getEventDispatcher

public EventDispatcher getEventDispatcher()
Description copied from interface: Database
Get an EventDispatcher which you can use to attach EventListeners to, for listening to the events being generated by the Database.

Specified by:
getEventDispatcher in interface Database

dispatchEvent

protected void dispatchEvent(int type)

doEnableLookupMode

protected boolean doEnableLookupMode()
                              throws IOException
This should check if the underlying stream supports temporary closing/re-opening. If it does it should close it temporarily and return true. Otherwise it should return false. If this method returns true it will not be called again - even if enableLookupMode() is called again. This method is not called if the Database is opened in R/W mode.

Returns:
true if lookup mode was successfully done.
Throws:
IOException - if an error occured which renders the Database unusable.

doOpenCloseLookup

protected void doOpenCloseLookup(boolean isOpen)
                          throws IOException
This should temporarily close or re-open the underlying data. This will only be called if doEnableLookupMode() returned true.

Parameters:
isOpen - true to reopen the underlying data, false to close it.
Throws:
IOException - if an error occured which renders the Database unusable.

enableLookupMode

public boolean enableLookupMode()
                         throws IOException
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.

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.

Specified by:
enableLookupMode in interface Database
Returns:
true if this optimization is enabled, false if not.
Throws:
IOException - if an IO error occurs.

openLookup

public void openLookup()
                throws IOException
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. Each call to openLookup() should have a corresponding call to closeLookup().

Specified by:
openLookup in interface Database
Throws:
IOException - if an IO error occurs.

closeLookup

public void closeLookup()
                 throws IOException
This is used with enableLookupMode() - it tells the database that data reading is complete and the underlying file may be closed. Each call to openLookup() should have a corresponding call to closeLookup().

Specified by:
closeLookup in interface Database
Throws:
IOException - if an IO error occurs.

markForReIndex

protected void markForReIndex(boolean needReIndex)
                       throws IOException
Throws:
IOException

reIndex

public boolean reIndex(Handle h)
                throws IOException
Description copied from interface: Database
In "Append" mode, after all the data has been added, call this method to re-index the database.

If you close the database without doing reIndex, it will be reIndexed automatically the next time it is opened.

Specified by:
reIndex in interface Database
Parameters:
h - a Handle that can be used to monitor or abort the operation.
Returns:
true if the re-indexing ended successfully, false if it was aborted because the stop() method was called on the Handle h.
Throws:
IOException - if there was an error writing to the database.

append

public void append(DatabaseEntry de)
            throws IOException
Description copied from interface: Database
Use this method in "Append" mode to add a data item to the Databse. In "Append" mode you add data directly to the database and then do "reIndex()" at the end.

Specified by:
append in interface Database
Throws:
IOException

doAppend

protected void doAppend(DatabaseEntry de)
                 throws IOException
Throws:
IOException