Class and Demo code:
Class: BerrySyncPersistentStore?.java
package BerrySync?.data;
import net.rim.device.api.system.PersistentObject?;
import net.rim.device.api.system.PersistentStore?;
public class BerrySyncPersistentStore? {
*
Static Utility Functions
*
public static void SaveData?(long _key, Object _data) throws Exception {
Create a persistent data store
PersistentObject? _store;
_store = PersistentStore?.getPersistentObject(_key);
Store Persistent data
synchronized(_store){
_store.setContents(_data);}
_store.commit();
}
public static Object LoadData?(long _key) throws Exception {
Create a persistent data store
PersistentObject? _store;
_store = PersistentStore?.getPersistentObject(_key);
Retrieve persistent data
Object _data;
synchronized(_store) {
_data = (Object)_store.getContents();
}}
return _data;
}
Class: Record.java
package BerrySync?.data;
import net.rim.device.api.crypto.AESKey;
import net.rim.device.api.crypto.InitializationVector?;
import net.rim.device.api.util.Persistable;
public class Record implements Persistable{
public String _data;}
public String _payload;
public String _collection;
public String _id;
public String _modified;
public int _ttl;
public int _sortIndex;
public AESKey _key;
public InitializationVector? _iv;
Demo code: in FetchScreen?.java
Private inner classes
*
final private class SaveOB implements FieldChangeListener? {
public void fieldChanged(Field field, int context) {
try {
Record _data = new Record();
_data._data = "data 1";
_data._id = "id 1";
long _key = 0x4ee5665b495a4912L;
BerrySyncPersistentStore?.SaveData?(_key, _data);
}}_storeArea.setText("Save Object" + " | " + _data._data + " | " + _data._id);}
catch(Exception e) {
_networkArea.setText(e.toString());}
final private class LoadOB implements FieldChangeListener? {}
public void fieldChanged(Field field, int context) {
try {}
long _key = 0x4ee5665b495a4912L;}
Record _data = (Record)BerrySyncPersistentStore?.LoadData?(_key);
if (_data == null) {
_storeArea.setText("Load Object" + _data);}else{
_storeArea.setText("Load Object" + " | " + _data._data + " | " + _data._id);}
catch(Exception e) {
_networkArea.setText(e.toString());}
No comments:
Post a Comment