Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 77
Registered: ‎02-17-2010
My Device: Not Specified

Persistant storage

[ Edited ]

Hi ,

 

Sorry for coming back with same old doubt. But still my doubt is not cleared .. Can u ppl please help me to resolve this issue.

 

One of my app contains storing data like i need to store

student id ,student first and last name, address,phone number

 

student id,course , -- ,--

 

and few more details.

 

these are just like separate tables in msacces or say sqllite.

 

I thought of  creating separate persistent storage objects for each table

	static {
		// com.aa.bb.somename
		long KEY = 0x26cd764287a1621fL;
		storeChannels = PersistentStore.getPersistentObject(KEY);
		vec_Channels = (Vector) storedata.getContents();
			.
			;


	}
	static {
		// com.cc.gg.somename
		long KEY = 0x87we9456561621fq
		storeChannels = PersistentStore.getPersistentObject(KEY);
		vec_Channels = (Vector) storedata.getContents();
			.
			;


	}

 but am not sure whether this opproach is good or not .. i referred this link too

http://supportforums.blackberry.com/t5/Java-Development/multiple-persistent-objects/td-p/44209

 

suggestions are that to store all objects and put it in hashmap.. but i like to go with above method (creating diff per objects) .. please clarify this doubt.. 

 

Is it good to create multiple persistant object for single app ?

if not what is the best method to store multiple data ?

 

Thanks ,

 

 

Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Persistant storage

The best way to go is to use some sort of data structure where you keep all your objects and store that data structure in the persistent storage. Most often hashtable is used but you should use whatever suits your needs best.

If I were you I would first analyze what operations I will need and how I am going to use the data then choose the suitable approach. I guess that you could create a class containing info about the student and store objects of that class in a vector for example and put that vector in the persistent store.
----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Regular Contributor
Posts: 77
Registered: ‎02-17-2010
My Device: Not Specified

Re: Persistant storage

Thanks for the reply .

 

I know the process how to store data in persistent storage.. let me clearly explain my problem,

 

I have 4 tables like

1. student table with 4 fields

2.Teachers table with 5 fields

3.course table with 4 field etc

 

my doubt is do i need to create 3 persistant key to store these tables

 

i mean 

	static {
		// com.aa.bb.somename ------------ > for student table
		long KEY = 0x26cd764287a1621fL;
		storeStudents= PersistentStore.getPersistentObject(KEY);
		vec_student = (Vector) storedata.getContents();
		if(vec_Student==null){
vec_student = new Vector();
Syncronized(storeStudents){
storeStudents.setContents(vec_student);
}


	}
	static {
		// com.cc.gg.somename --------------- > for teachers table
		long KEY = 0x87we9456561621fq
		storeTeachers= PersistentStore.getPersistentObject(KEY);
		vec_Teachers = (Vector) storedata.getContents();
		if(vec_Teachers ==null){
			vec_student = new Vector();
			Syncronized(storeTeachers){
		storeStudents.setContents(vec_Teachers);
		}


	}
		
static {
		// com.cc.gg.somename --------------- > for Course table
		long KEY = 0x87we9456561621fq
		storeCourse = PersistentStore.getPersistentObject(KEY);
		vec_Course = (Vector) storedata.getContents();
			.
			;


	}

 

or

other approach,

 

if not required to create 3 persistant table and say i have one vector which contains above three vectors as its item,

ex : Vector mainvec = new Vector();

mainvec.addElement(vec_students);

mainvec.addElement(vec_Teachers);

mainvec.addElement(vec_Course);

 

then commit mainvec to single persistant storage.

 

by using second method if i want to edit or update single item i need to read all data and check which instance and do all operations,.. this will make my code dirty..

 

To go with first method, am feared of memory leackage.. but this method is clear and makes code more readable. but am not sure whether first method is good to implement..

 

any suggestions and inputs are highly appriciated..

 

Looking forward for replies ...

Thanku

 

 

Highlighted
Developer
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Persistent storage

Ok I think I understand your concern.

 

As you said the approach where you use one vector where you store all 3 tables and persist that vector is more neat and makes your code easier and more readable. I would generally go with this approach

 

BUT here are some reasons why you shouldn't use it: 

1) If your application will access the persistent storage often you don't want to read/save info to the storage many times per second for instance.

2) If your tables are about to get really big you might not want to or load the whole students data when editing a record in the teachers table.

 

If your app is going to persist a LOT of data and/or read it very often you will need to optimize the process otherwise go with the approach where everything is in one data structure. Just analyze how your app will work with the data Smiley Happy

----------------------------------------------------------------------
Press the button to give kudos if I helped you Smiley Happy
Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: Persistent storage

Sorry, it's just my opinion...

But, if you are accessing 3 or 4 tables like that..

Why don't you use SQLite database for storing data?