Troubleshooting guide

83
4: Managing data
import java.io.*;
import java.util.*;
import net.rim.device.api.collection.*;
import net.rim.device.api.i18n.*;
import net.rim.device.api.synchronization.*;
import net.rim.device.api.util.*;
import net.rim.device.api.system.*;
/**
* A collection enabled for OTA backup/restore. Basically a serially syncable collection
* with few added interfaces.
*/
class OTABackupRestoreContactCollection implements SyncConverter, SyncCollection,
OTASyncCapable, CollectionEventSource
{
private static final long PERSISTENT_KEY = 0x266babf899b20b56L; //
com.rim.samples.device.otabackuprestoredemo.OTABackupRestoreContactCollection._persist
private static final long AR_KEY = 0xef780e08b3a7cf07L; //
com.rim.samples.device.otabackuprestoredemo.OTABackupRestoreContactCollection
private PersistentObject _persist; // the persistable object for the contacts
private Vector _contacts; // the actual contacts
private Vector _listeners; // listeners to generate events when contacts
are added
private SyncCollectionSchema _schema; // lets us know about the data we are backing
up
private static final int FIELDTAG_FIRST_NAME = 1;
private static final int FIELDTAG_LAST_NAME = 2;
private static final int FIELDTAG_EMAIL_ADDRESS = 3;
private static final int DEFAULT_RECORD_TYPE = 1; // the id for the default (and
the only) record type
private static final int[] KEY_FIELD_IDS = new int[] { // key fields - lets the server
know which fields uniquely define a record
FIELDTAG_FIRST_NAME,
FIELDTAG_LAST_NAME
};
private OTABackupRestoreContactCollection()
{
_persist = PersistentStore.getPersistentObject( PERSISTENT_KEY );
_contacts = (Vector)_persist.getContents();
if( _contacts == null )
{
_contacts = new Vector();
_persist.setContents( _contacts );
_persist.commit();
}
_listeners = new CloneableVector();
// set up the schema for the collection
_schema = new SyncCollectionSchema();