de.enough.polish.android.rms
Class SqlRecordEnumeration

java.lang.Object
  extended by de.enough.polish.android.rms.SqlRecordEnumeration
All Implemented Interfaces:
RecordEnumeration

public class SqlRecordEnumeration
extends Object
implements RecordEnumeration


Constructor Summary
SqlRecordEnumeration(RecordStore recordStore, RecordFilter filter, RecordComparator comparator, boolean keepUpdated)
           
 
Method Summary
 void destroy()
          Frees internal resources used by this RecordEnumeration.
 boolean hasNextElement()
          Returns true if more elements exist in the next direction.
 boolean hasPreviousElement()
          Returns true if more elements exist in the previous direction.
 boolean isKeptUpdated()
          Returns true if the enumeration keeps its enumeration current with any changes in the records.
 void keepUpdated(boolean keepUpdated2)
          Used to set whether the enumeration will be keep its internal index up to date with the record store record additions/deletions/changes.
 byte[] nextRecord()
          Returns a copy of the next record in this enumeration, where next is defined by the comparator and/or filter supplied in the constructor of this enumerator.
 int nextRecordId()
          Returns the recordId of the next record in this enumeration, where next is defined by the comparator and/or filter supplied in the constructor of this enumerator.
 int numRecords()
          Returns the number of records available in this enumeration's set.
 byte[] previousRecord()
          Returns a copy of the previous record in this enumeration, where previous is defined by the comparator and/or filter supplied in the constructor of this enumerator.
 int previousRecordId()
          Returns the recordId of the previous record in this enumeration, where previous is defined by the comparator and/or filter supplied in the constructor of this enumerator.
 void rebuild()
          Request that the enumeration be updated to reflect the current record set.
 void reset()
          Returns the enumeration index to the same state as right after the enumeration was created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlRecordEnumeration

public SqlRecordEnumeration(RecordStore recordStore,
                            RecordFilter filter,
                            RecordComparator comparator,
                            boolean keepUpdated)
Method Detail

destroy

public void destroy()
Description copied from interface: RecordEnumeration
Frees internal resources used by this RecordEnumeration. MIDlets should call this method when they are done using a RecordEnumeration. If a MIDlet tries to use a RecordEnumeration after this method has been called, it will throw a IllegalStateException. Note that this method is used for manually aiding in the minimization of immediate resource requirements when this enumeration is no longer needed.

Specified by:
destroy in interface RecordEnumeration

hasNextElement

public boolean hasNextElement()
Description copied from interface: RecordEnumeration
Returns true if more elements exist in the next direction.

Specified by:
hasNextElement in interface RecordEnumeration
Returns:
true if more elements exist in the next direction

hasPreviousElement

public boolean hasPreviousElement()
Description copied from interface: RecordEnumeration
Returns true if more elements exist in the previous direction.

Specified by:
hasPreviousElement in interface RecordEnumeration
Returns:
true if more elements exist in the previous direction

isKeptUpdated

public boolean isKeptUpdated()
Description copied from interface: RecordEnumeration
Returns true if the enumeration keeps its enumeration current with any changes in the records.

Specified by:
isKeptUpdated in interface RecordEnumeration
Returns:
true if the enumeration keeps its enumeration current with any changes in the records

keepUpdated

public void keepUpdated(boolean keepUpdated2)
Description copied from interface: RecordEnumeration
Used to set whether the enumeration will be keep its internal index up to date with the record store record additions/deletions/changes. Note that this should be used carefully due to the potential performance problems associated with maintaining the enumeration with every change.

Specified by:
keepUpdated in interface RecordEnumeration
Parameters:
keepUpdated2 - - if true, the enumerator will keep its enumeration current with any changes in the records of the record store. Use with caution as there are possible performance consequences. Calling keepUpdated(true) has the same effect as calling RecordEnumeration.rebuild: the enumeration will be updated to reflect the current record set. If false the enumeration will not be kept current and may return recordIds for records that have been deleted or miss records that are added later. It may also return records out of order that have been modified after the enumeration was built. Note that any changes to records in the record store are accurately reflected when the record is later retrieved, either directly or through the enumeration. The thing that is risked by setting this parameter false is the filtering and sorting order of the enumeration when records are modified, added, or deleted.
See Also:
RecordEnumeration.rebuild()

nextRecord

public byte[] nextRecord()
                  throws InvalidRecordIDException,
                         RecordStoreNotOpenException,
                         RecordStoreException
Description copied from interface: RecordEnumeration
Returns a copy of the next record in this enumeration, where next is defined by the comparator and/or filter supplied in the constructor of this enumerator. The byte array returned is a copy of the record. Any changes made to this array will NOT be reflected in the record store. After calling this method, the enumeration is advanced to the next available record.

Specified by:
nextRecord in interface RecordEnumeration
Returns:
the next record in this enumeration
Throws:
InvalidRecordIDException - - when no more records are available. Subsequent calls to this method will continue to throw this exception until reset() has been called to reset the enumeration.
RecordStoreNotOpenException - - if the record store is not open
RecordStoreException - - if a general record store exception occurs

nextRecordId

public int nextRecordId()
                 throws InvalidRecordIDException
Description copied from interface: RecordEnumeration
Returns the recordId of the next record in this enumeration, where next is defined by the comparator and/or filter supplied in the constructor of this enumerator. After calling this method, the enumeration is advanced to the next available record.

Specified by:
nextRecordId in interface RecordEnumeration
Returns:
the recordId of the next record in this enumeration
Throws:
InvalidRecordIDException - - when no more records are available. Subsequent calls to this method will continue to throw this exception until reset() has been called to reset the enumeration.

numRecords

public int numRecords()
Description copied from interface: RecordEnumeration
Returns the number of records available in this enumeration's set. That is, the number of records that have matched the filter criterion. Note that this forces the RecordEnumeration to fully build the enumeration by applying the filter to all records, which may take a non-trivial amount of time if there are a lot of records in the record store.

Specified by:
numRecords in interface RecordEnumeration
Returns:
the number of records available in this enumeration's set. That is, the number of records that have matched the filter criterion.

previousRecord

public byte[] previousRecord()
                      throws InvalidRecordIDException,
                             RecordStoreNotOpenException,
                             RecordStoreException
Description copied from interface: RecordEnumeration
Returns a copy of the previous record in this enumeration, where previous is defined by the comparator and/or filter supplied in the constructor of this enumerator. The byte array returned is a copy of the record. Any changes made to this array will NOT be reflected in the record store. After calling this method, the enumeration is advanced to the next (previous) available record.

Specified by:
previousRecord in interface RecordEnumeration
Returns:
the previous record in this enumeration
Throws:
InvalidRecordIDException - - when no more records are available. Subsequent calls to this method will continue to throw this exception until reset() has been called to reset the enumeration.
RecordStoreNotOpenException - - if the record store is not open
RecordStoreException - - if a general record store exception occurs.

previousRecordId

public int previousRecordId()
                     throws InvalidRecordIDException
Description copied from interface: RecordEnumeration
Returns the recordId of the previous record in this enumeration, where previous is defined by the comparator and/or filter supplied in the constructor of this enumerator. After calling this method, the enumeration is advanced to the next (previous) available record.

Specified by:
previousRecordId in interface RecordEnumeration
Returns:
the recordId of the previous record in this enumeration
Throws:
InvalidRecordIDException - - when no more records are available. Subsequent calls to this method will continue to throw this exception until reset() has been called to reset the enumeration.

rebuild

public void rebuild()
Description copied from interface: RecordEnumeration
Request that the enumeration be updated to reflect the current record set. Useful for when a MIDlet makes a number of changes to the record store, and then wants an existing RecordEnumeration to enumerate the new changes.

Specified by:
rebuild in interface RecordEnumeration
See Also:
RecordEnumeration.keepUpdated(boolean)

reset

public void reset()
Description copied from interface: RecordEnumeration
Returns the enumeration index to the same state as right after the enumeration was created.

Specified by:
reset in interface RecordEnumeration