Sunday, April 22, 2007

JAVA 認證心得 -- SCMAD (6)

MIDP Persistent Storage

##CONTINUE##

  • Public static RecordStore

openRecordStore (String recordName, boolean create)

openRecordStore (String recordName, boolean create, int authmode, boolean writable)

openRecordStore (String recordName, String vendor, String suite)

Ø Created if one is not already available

Ø Name cannot exceed 32 characters

Ø if recordStoreName is invalid throw an IllegalArgumentException

  • Authmode

Ø AUTHMODE_PRIVATE

1. means only the MIDlet suite that created the RecordStore can access the RecordStore.

2. Authorization to allow access only to the current MIDlet suite.

3. it has a value of 0.

Ø AUTHMODE_ANY

1. Authorization to allow access to any MIDlet suites.

2. it has a value of 1

  • The owning MIDlet suite can always access the RecordStore and can set the authentication mode.
  • The record id is always a positive integer beginning from 1
  • Interface RecordListener

    void recordAdded(RecordStore store, int recordId)

    void recordChanged(RecordStore store, int recordId)

    void recordDeleted(RecordStore store, int recordId)

  • RecordStore.addRecordListener(RecordListener listener) can be used to register a listener to a RecordStore. Any number of listeners can be added to the RecordStore within memory limits
  • A record store is not thread-safe.
  • IllegalArgumentException exception will be thrown if the name passed while creating a record store is longer than 32 characters.
  • Interface RecordFilter

    - Boolean matches(byte[] candidate)

  • A record store is uniquely identified using a combination of its name and the MIDlet-Name and MIDlet-Vendor attribute values of the MIDlet that created the store.
  • A DataInputStream is used in conjunction with the ByteArrayInputStream to read various data types from a record in a record store while reading a record.
  • RecordComparator.compare()

    EQUIVALENT, PRECEDES, FOLLOWS

  • RecordEnumeration.destroy()
  • RecordEnumeration.reset() return the enumeration index to the same state as right after the enumeration was created.
  • RecordEnumeration.rebulid() recreation the internal indexes of the enumeration.
  • public interface RecordEnumeration

    An interface representing a bidirectional record store Record enumerator. The RecordEnumeration logically maintains a sequence of the recordId's of the records in a record store. The enumerator will iterate over all (or a subset, if an optional record filter has been supplied) of the records in an order determined by an optional record comparator.

  • public interface RecordFilter

    An interface defining a filter which examines a record to see if it matches (based on an application-defined criteria). The application implements the match() method to select records to be returned by the RecordEnumeration. Returns true if the candidate record is selected by the RecordFilter. This interface is used in the record store for searching or subsetting records. For example:

    RecordFilter f = new DateRecordFilter();

    if (f.matches(recordStore.getRecord(theRecordID)) == true)

    DoSomethingUseful(theRecordID);

Read more!

No comments: