Troubleshooting guide

66
BlackBerry Java Development Environment Development Guide
Manage persistent data
Data integrity To maintain the integrity of data in persistent storage, partial updates are not made if an error occurs during
a commit. Data in the
PersistentObject retains the values from the last commit in order to preserve data
integrity.
If the JVM performs an emergency garbage collection operation due to low memory, outstanding transactions
are committed immediately to avoid compromising data integrity. If the BlackBerry device fails during this
operation, partially completed transactions are committed when the BlackBerry device starts. Outstanding
transactions are not committed during a normal garbage collection operation.
Task Steps
Create a unique long key. Each PersistentObject has a unique long key.
1. In the BlackBerry® Integrated Development Environment, type a string value, such as
com.rim.samples.docs.userinfo.
2. Select this string.
3. Right-click this string and click Convert ‘com.rim.samples.docs.userinfo’ to long.
4. Include a comment in your code to indicate the string that you used to generate the unique long key.
Create a persistent data
store.
1. Create a single static PersistentObject.
static PersistentObject store;
2. Invoke PersistentStore.getPersistentObject, using the unique long key as a parameter.
static {
store = PersistentStore.getPersistentObject( 0xa1a569278238dad2L );}
Store an object persistently. 1. Invoke setContents() on a PersistentObject. This method replaces existing content with the new
content.
2. To save the new content to the persistent store, invoke commit().
String[] userinfo = {username, password};
synchronized(store) {
store.setContents(userinfo);
store.commit();}
Store objects in a batch
transaction.
1. To use a batch transaction to commit objects to the persistent store, invoke
PersistentStore.getSynchObject(). This method retrieves the persistent store monitor that locks
the object.
2. Synchronize on the object.
3. Invoke commit() as necessary. If any commit in the batch fails, the entire batch transaction fails.
Commit a monitor object
separately from a batch
transaction.
>Invoke forceCommit() while synchronizing the monitor object.
Feature Description