BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 06-01-2009, 09:28 PM   #1
souhail
New Member
 
Join Date: Jun 2009
Model: 8830
PIN: N/A
Carrier: Telus
Posts: 2
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
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Default

Don't you have a hard time trying to follow the code formatted that way? I do. Please read this thread: http://www.blackberryforums.com/deve...rum-posts.html

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
pravipravi
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


20 Ton Hydraulic Portable Ram Lifting Cylinder Stroke Porta Power Jack Tool picture

20 Ton Hydraulic Portable Ram Lifting Cylinder Stroke Porta Power Jack Tool

$88.35



37061 - IMPERIAL RAM MODULE -  picture

37061 - IMPERIAL RAM MODULE -

$205.00



RAM MODULE (COMES WITH WIRING HARDNESS) picture

RAM MODULE (COMES WITH WIRING HARDNESS)

$200.00



NCR 1924-0122-8801 KC4 Kitchen Controller 64GB HDD / 8GB RAM Win10 NEW IN BOX picture

NCR 1924-0122-8801 KC4 Kitchen Controller 64GB HDD / 8GB RAM Win10 NEW IN BOX

$402.36



M1187 J-Head RAM Adapter Milling Machine Part Accessory Adjusted Head Angle USA picture

M1187 J-Head RAM Adapter Milling Machine Part Accessory Adjusted Head Angle USA

$105.00



Ram Kl-1 picture

Ram Kl-1

$700.00







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