BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-01-2009, 09:28 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Model: 8830
PIN: N/A
Carrier: Telus
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default persistable object at class level

Please Login to Remove!

Hi



I am trying to store data in my blackberry by implementing a class that implements the persistable type, each class has its own data structure, and therefore i would like to encapulate it all inside the class and not have to load all the different hex numbers (references to the object store) from the main application. am i doing anything wrong?



I'm not able to get the results back in my test app size the _data vector size is 0.



also i dont understand why in most other sample apps i see, the store in static braces:



static {

store =

PersistentStore.getPersistentObject(0xdec6a67096f8 33cL);

synchronized (store) {

if (store.getContents() == null) {

store.setContents(new Vector());

store.commit();

}

}

_data = new Vector();

_data = (Vector) store.getContents();

}



is the static keyword necessary around the block of code? and how can i integrate it into my class?



Thanks



---------------------- my code ----------------



public class WeightRecordPersistableCollection implements Persistable {





private static Vector _data; //vector of WeightRecordPersistable objects

private static PersistentObject store;

private long objID = 0x88ab2311;



public WeightRecordPersistableCollection() {

set_data(new Vector(20));

for (int i = 0; i < get_data().capacity(); ++i) {

get_data().addElement(null);

}

StoreData();

}



public Vector getElement(int id) {

return (Vector) get_data().elementAt(id);

}



//need a getElement by hashcode



public void setElement(int id, WeightRecordPersistable value) {

int oldcapacity = get_data().capacity();

//expand the vector if size is too small

if(id > oldcapacity-1){

get_data().setSize(id+1);

for(int j=oldcapacity-1; j<get_data().capacity(); j++){

get_data().addElement(null);

}

}

get_data().setElementAt(value, id);

}



//save the list of goals in memory

public void GetWeightRecordList(){

store = PersistentStore.getPersistentObject (objID);

synchronized (store) {

_data = (Vector) store.getContents();

}

System.out.println("vecgor size in getting: " + _data.size());

}



public void StoreData(){

store = PersistentStore.getPersistentObject (objID);

synchronized (store) {

if (store.getContents() != null) {

store.setContents(_data);

store.commit();

}

}

}



}
Offline  
Old 06-02-2009, 10:43 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Don't you have a hard time trying to follow the code formatted that way? I do. Please read this thread: How to paste 100% FORMATTED Source Code In Your Forum Posts

Then have a look at the Application Developers' Guide sections on Persistent Storage: Livelink - Redirection
__________________
My other Blackberry is a PlayBook.
Offline  
Old 06-15-2009, 03:32 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

is the static keyword necessary around the block of code? and how can i integrate it into my class?

Answer: Its not necessary.
__________________
Praveen K
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.