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
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile
Accepted Solution

Persitible Structure Change

Hello all,

 

I am planning on upgrading an application but it seems I forgot about the possibility of the structure of my class changing in the future by adding other objects to it.

 

Is the best practice to just have place holders in a class?

 

e.g.

 

public class Settings implements Persistable{

int placeholder1;

int placeholder2;

int placeholder3;

...

}

 

How should I handle the change to the format in an upgrade, create a mirror of my old class, read it in the updated app, then save it in the new structure and save that?

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Persitible Structure Change

you could use a mutable object, like hashtable, for your settings.
this allows you to add and remove settings without the resulting config object being incompatible.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Persitible Structure Change

Is this common practice when making apps that need to save settings?
Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: Persistable Structure Change

[ Edited ]

It is certainly the way I recommend.  I particularly like Hashtable. 

Please use plain text.
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Persitible Structure Change

Thanks, I will have a look at it.
Please use plain text.
Contributor
satyagrwl
Posts: 12
Registered: ‎06-16-2011
My Device: 9000
My Carrier: Vodafone

Re: Persitible Structure Change

Yes... One good thing that you can do...

 

Use IntHashtable Instead of Hashtable and define all int keys whatever you want to put on that and put the value on IntHashTable.

Please use plain text.
Developer
mapleleafs90
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: Persitible Structure Change

Well actually I have a custom class that I am saving which contains other classes. So Im not so sure that IntHashTable would work if its dedicated to only integer objects.

So hopefully that one is compatible with HashTable, and when I modify the items inside of this custom class I guess I can read it and then update it to the new format.

One thing I do not understand is how it will work if a user decides not to take one upgrade and then go directly from 1.0 -> 1.2 bypassing 1.1?

I have 2 classes that I save one as I mentioned above full of integers, possible some strings. Also another separate from the one above Vector which contains a few classes of different types in no set order and the size changes based on the user deleting things, creating new ones, etc.
Please use plain text.
Contributor
satyagrwl
Posts: 12
Registered: ‎06-16-2011
My Device: 9000
My Carrier: Vodafone

Re: Persitible Structure Change

Using IntHashtable It is very simple process and it will handle all the scenario.

 

Make a Class which will have all getter and setter of your specific.

Define your public static final int keys to mape your data.

Keep a object of intHashtable and initialy read it from Persistance if it is there then then assign else creat new and commit.

Now in your getter and setter read the object from IntHashtable for that specified key if its not there then return the default value and in each setter put the value on the key in IntHashtable and commit it.

 

Done :smileyhappy:

Please use plain text.