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
New Developer
Posts: 8
Registered: ‎04-01-2009
My Device: Not Specified
Accepted Solution

How to initially load persistent data for an application that will implement a persistent database.

I'm developing a smart phone application which will create a persistent database for data storage.  But, I want to initially load this database with data.  Does anyone have any suggestions as to the best way to accomplish this? 
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

use static block and load your data.

Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 8
Registered: ‎04-01-2009
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

Yes, I could use a static block and load the data but having it in the code will just unnecesarily bloat the cod file with a lot of code which runs only one time.   Think of a project where you want to pre-load the persistent database with a 100 instances of the persistable object.  This could be A LOT of data and you only need to load it in the persistent database one time.  And, you don't want to load it from expandable (microSD) memory because doing so adds a level of complexity to the application installation.   I also thought of using a separate data file (.txt or .xml) and load the data from there but again the contents of this file exists in the cod file with no way (that I know of) to delete it later and reduce the footprint of the cod file. 
Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

Since you need it there once, and don't need it after that, I would suggest that you look at putting the data in a separate cod, that you then use the CodeModuleManager to delete.  If you have no data, then you can look for this cod and load it.  We do something similar, where a cod file is optional for a package we have - if present we use it, if not we don't - but we only use this to provide data, we don't then delete the cod.  I might be able to dig out the 'using' code for you, but I don't have any code to delete a cod (and have not tried it).

 

Would this approach work for you?

 

I would caution against removing the initial data.  You may have occasion to use the initialization data on the device to 'reset' a failing application.

New Developer
Posts: 8
Registered: ‎04-01-2009
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

Yes, I think your suggestion to use a separate cod file may work if I can delete it from my app.  I'll investigate using the CodeModuleManager class although I think this would require my application to be signed.  If you have a code snippet on using it to delete a cod file I'd be interested in seeing it. 

 

BUT, you raise a very good question with regards to the possible need to reload it.  How safe is the persistent database against a 'reset' where the data is lost?  Is it possible to do this from the BlackBerry interface or can the user do this with another tool? 

 

Your assistance has be truly appreciated.

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

"How safe is the persistent database" - In my experience, very.  I won't worry about loosing it.  The reload option is more useful as a way of getting an errant user back on track.

 

I suspect to delete the cod, you will have to supply it in a separate application, i.e. a separate alx, or separate jad file for OTA download. 

 

Don't have a code snippet to delete a cod, have a look round I seem to remember someone on this forum posting some. 

 

Here is a code snippet that sees if a cod is present and if so, uses it.  This cod just contains data, a bit like you want.  The data in this case is XML, which the application takes in as a String and then parses.

 

String moduleName = "<your module name>"; int handle = CodeModuleManager.getModuleHandle(moduleName); if ( handle != 0 ) { try { String className = "<a class in your module>"; Object dataObject = (Object) Class.forName(className).newInstance(); String dataString = dataObject.toString();

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

Don't let signing scare you off. Just get the keys and be done with it. $20, takes about 2-3 days, and then you can sign all of your applications.

 

http://na.blackberry.com/eng/developers/javaappdev/codekeys.jsp

 

 

Highlighted
New Developer
Posts: 8
Registered: ‎04-01-2009
My Device: Not Specified

Re: How to initially load persistent data for an application that will implement a persistent databa

Okay, this I think I can do.  

 

Many thanks for your help!