How do I use the persistent object store in Blackberry? -


I want to create a simple CRUD application to test the data handling capabilities of Blackberry.

How do I create a simple save function?

In this example I store a vector continuously.

You have to come up with a store ID, which should be for a long time. I usually make it completely by assembling the class name of the qualified app in some strings that make it unique in my application. Use

  // class field ... // application fully qualified name so you do not have a store collision. Fixed string ApplicaitonID = Application.getApplication (). GetClass () GetName (); Stable string STORE_NAME = "myTestStore_V1"; Long storeId = StringUtilities.stringHashToLong (ApplicationID + STORE_NAME); Personal stable persistent object myStoredObject; Private static content protected vector myObjects; // Final range fields  

Example of loading vector from the store:

  myStoredObject = PersistentStore.getPersistentObject (storeId); MyObjects = (content protected vector) myStoredObject.getContents (); // Print the number of objects in the storage: System.out.println (myObjects.size ()); // Insert an element and update the store on "disk" ... myObjects.addElement ("new string"); MyStoredObject.setContents (myObjects); MyStoredObject.commit ();  

Example of starting this store and saving it to disk for the first time:

  myStoredObject = PersistentStore.getPersistentObject (storeId); MyObjects = (content protected vector) myStoredObject.getContents (); If (myObjects == faucet) myObjects = New Content ProtectedVector (); MyStoredObject.setContents (myObjects); MyStoredObject.commit ();  

If you want to make changes (save changes to empty discs), you will need to repeat the two rows below. SetContents (OBJ); And comet ().

You can store the following without doing anything special:

 java.lang.Boolean java.lang.Byte java.lang.Character java.lang integer java.lang. Long java.lang.Object java.lang.Short java.lang.String java.util.Vector java.util.Hashtable 

@se:

To store your classes, They (and all sub-sections) have to implement the "Persistible" interface. I recommend that you do this, because this store is automatically cleaned when your application gets uninstalled. The reason for this is that the OS clears stored objects, when "any" referenced class name in the store is no longer an application associated with it. So if your store is using only strings, then it can never be cleaned up


Comments