FileDocCategorySizeDatePackage
TransactionStorageImpl.javaAPI DocphoneME MR2 API (J2ME)10194Wed May 02 18:00:44 BST 2007com.sun.j2me.payment

TransactionStorageImpl

public class TransactionStorageImpl extends Object
This class extends RMS API to implement blocked operations for Transaction Store The {@link com.sun.midp.rms.RecordStoreImpl} class is used to access Transaction Store The global native mutex is used to manage access to Transaction Store
see
RecordStoreImpl
version
1.1

Fields Summary
static final String
PAYMENT_FILE_NAME
The name of the RMS where to store the transaction records.
static final int
PAYMENT_SUITEID_NAME
The name of the SuiteId where to store the transaction records.
private boolean
isOpen
Indicates if a Storage is opened.
private RecordStoreImpl
store
Real Record Store.
Constructors Summary
TransactionStorageImpl(SecurityToken token, boolean create)
Constructor. Opens Transaction Store location and locks it If the Transaction Store is already locked the calling thread is blocking untill Transaction Store is unlocked

param
token security token for authorization
param
create if true, create the record store if it doesn't exist
exception
RecordStoreException if something goes wrong setting up the new RecordStore.
exception
RecordStoreNotFoundException if can't find the record store and create is set to false.
exception
RecordStoreFullException if there is no room in storage to create a new record store
see
com.sun.midp.rms.RecordStoreImpl#openRecordStore


                                                                                                                               
       
          
                
        lockStore();
        store = RecordStoreImpl.openRecordStore(token,
                PAYMENT_SUITEID_NAME, PAYMENT_FILE_NAME, create);
    
Methods Summary
intaddRecord(byte[] data)
Adds a new record into the Transaction Store

param
data the data to be stored in this record.
return
the recordId for the new record
exception
RecordStoreNotOpenException if the record store is not open
exception
RecordStoreException if a different record store-related exception occurred
exception
RecordStoreFullException if the operation cannot be completed because the record store has no more room
exception
SecurityException if the MIDlet has read-only access to the RecordStore
see
com.sun.midp.rms.RecordStoreImpl#addRecord

	checkOpen();
        return store.addRecord(data, 0, data.length);
    
private voidcheckOpen()
Throws a RecordStoreNotOpenException if the RecordStore is closed.

exception
RecordStoreNotOpenException if RecordStore is closed
see
com.sun.midp.rms.RecordStoreImpl#checkOpen

        if (!isOpen) {
            throw new RecordStoreNotOpenException();
        }
    
public voidcloseStore()
Close Transaction Store and unlocks it. All threads waiting for Transaction Store will be unblocked

exception
RecordStoreNotOpenException if the record store is not open
exception
RecordStoreException if a different record store-related exception occurred
see
com.sun.midp.rms.RecordStoreImpl#closeRecordStore

        checkOpen();
        try {
            store.closeRecordStore();
        } finally {
            unlockStore();
        }
    
voiddeleteRecord(int recordId)
Delete record from the Transaction Store.

param
recordId the ID of the record to delete
exception
RecordStoreNotOpenException if the record store is not open
exception
InvalidRecordIDException if the recordId is invalid
exception
RecordStoreException if a general record store exception occurs
see
com.sun.midp.rms.RecordStoreImpl#deleteRecord

	checkOpen();
        store.deleteRecord(recordId);
    
static voiddeleteStore(SecurityToken token)
Deletes Transaction Store

param
token security token for authorization
exception
RecordStoreException if a record store-related exception occurred
exception
RecordStoreNotFoundException if the record store could not be found
see
com.sun.midp.rms.RecordStoreImpl#deleteRecordStore

        RecordStoreImpl.deleteRecordStore(token,
                PAYMENT_SUITEID_NAME, PAYMENT_FILE_NAME);
    
private native voidfinalize()
Finalizes the store.

intgetNumRecords()
Returns the number of records currently in the Transaction Store.

return
the number of records currently in the record store
exception
RecordStoreNotOpenException if the record store is not open
see
com.sun.midp.rms.RecordStoreImpl#getNumRecords

	checkOpen();
        return store.getNumRecords();
    
public byte[]getRecord(int recordId)
Returns a copy of the data stored in the given record.

param
recordId the ID of the record to use in this operation
exception
RecordStoreNotOpenException if the record store is not open
exception
InvalidRecordIDException if the recordId is invalid
exception
RecordStoreException if a general record store exception occurs
return
the data stored in the given record. Note that if the record has no data, this method will return null.
see
com.sun.midp.rms.RecordStoreImpl#getRecord

	checkOpen();
        return store.getRecord(recordId);
    
int[]getRecordIDs()
Returns all of the recordId's currently in the Transaction Store.

exception
RecordStoreNotOpenException if the record store is not open
return
an array of the recordId's currently in the record store or null if the record store is closed.
see
com.sun.midp.rms.RecordStoreImpl#getRecordIDs

	checkOpen();
        return store.getRecordIDs();
    
public intgetRecordSize(int recordId)
Returns the size (in bytes) of the record.

param
recordId the ID of the record to use in this operation
return
the size (in bytes) of the MIDlet data available in the given record
exception
RecordStoreNotOpenException if the record store is not open
exception
InvalidRecordIDException if the recordId is invalid
exception
RecordStoreException if a general record store exception occurs
see
com.sun.midp.rms.RecordStoreImpl#getRecordSize

	checkOpen();
        return store.getRecordSize(recordId);
    
private native voidlockStore()
Waits for access to Transaction Store

voidsetRecord(int recordId, byte[] newData)
Updates content of the record in the Transaction Store

param
recordId the ID of the record to use in this operation
param
newData the new data to store in the record
exception
RecordStoreNotOpenException if the record store is not open
exception
InvalidRecordIDException if the recordId is invalid
exception
RecordStoreException if a general record store exception occurs
exception
RecordStoreFullException if the operation cannot be completed because the record store has no more room
see
com.sun.midp.rms.RecordStoreImpl#setRecord


	checkOpen();
        store.setRecord(recordId, newData, 0, newData.length);
    
private native voidunlockStore()
Unlocks Transaction Store