0

Below issues have been discussed in isolation but I could not find a solution which works. Hence posting the complete story and list of issues.
We are building an SDK(midlet jar) to be consumed by multiple apps. This SDK uses persistent store to store certain data. Now couple of issues plaguing us:
1. The key to access the store has been hard-coded in the SDK. Now multiple apps try to access the store with same key value resulting in conflicting issues.
2. The Persistable object package/class name is the same in multiple apps. Because of this we get the "Class Multiply defined" error while launching the apps.

Now for 2, we have been mulling over below options but none of them seem to solve the issue:
1. Do not extend the standard objects like Vector and use standard objects.
Issue: recycling of data is lost causing conflicts.
2. Build the library with a unique name for each application that uses it.
Issues: This would mean we will have to release a different SDK for every client who wants to use it.
3. Check if the Persistable object class already exists before loading the package for the next app.
Issues: What happens when the first package is unistalled? the class type would be deleted?
4. Ask the app to implement the Persistable interface and also pass the key in a callback.
This does not sound right to ask the app to pass some values just because we are not able to use the persistent store.

So as of now SDKs using Persistable objects seems to be totally broken. Or are we missing something?
Any other alternative suggestion to achieve the task is also very welcome.

Lokesh
  • 31
  • 4

2 Answers2

0

if there is a library which functionality can be shared among different applications then make it as a library cod file, and specify this cod file as a library upon compiling the dependent projects.

For instance, if the library name is mylib_version1_00.cod then your other projects could contain the following files after compilation:

for Project1:

  • project1.cod
  • mylib_version1_00.cod

for Project2:

  • project2.cod
  • mylib_version1_00.cod

......

for for ProjectN:

  • projectN.cod
  • mylib_version1_00.cod

upon installation of every project you will install mylib.cod file, and if there's already installed mylib.cod file it will be overwritten, and it will avoid "class xxx multiply defined".

This error occurs because all applications are running under one JVM instance. So if you are uploading to device a cod file with the name, that already exists, it will be rewritten.

In case you will release the next version of your library, name the cod file as

mylib_version2_00.cod

and use version number in package name, for instance:

com.yourcompany.yourpoduct.yourlibary.version1

com.yourcompany.yourpoduct.yourlibary.version2

In this case you can have on the same device cod files: mylib_version1_00.cod and mylib_version2_00.cod and it won't produce "class xxx multiply defined" error.

Now about the persistence. Do not hardcode persistence key in your library. Make an abstract class and declare an abstract method like:

public long getPersistenceKey();

which returns a unique persistence key for an object. And use this method call in the code that persists the information in your abstract class.

and in children classes, used in your custom applications just override this method with different values for every product. And there won't be confilcts anymore.

Hope this helps.

  • Hi Rafael, thanks for your reply. However the only documented solution to adding library dependency I could find was 'adding a midlet jar as dependent library'. Any pointers to documentation on using cod files as dependent library? – Lokesh Aug 20 '14 at 10:24
  • In a project (let say it is `project B`) settings you can specify that the project is a library project. Then in another project, let say in `project A`, you specify that it is "application" (not library) and you can set that it depends on `project B`. After compilation you will need cod files for `project A` and `project B` to install on the device. –  Aug 20 '14 at 10:38
  • @Lokesh and check this link, please: http://docs.blackberry.com/en/developers/deliverables/12002/Add_project_dependency_923676_11.jsp –  Aug 20 '14 at 10:48
  • Hi Rafael, sorry for not being clear but the SDK has to be given to external parties and I cannot share the project(actual code) with them. Is it possible to develop the app against just the .cod file without the actual project? – Lokesh Aug 21 '14 at 11:29
  • @Lokesh you can convert (compile with rapc.exe) a jar file to cod file. Check this link: http://stackoverflow.com/questions/3094043/convert-a-jar-file-into-a-cod-file-using-bb-ant and note that bb ant tools can be found here: http://bb-ant-tools.sourceforge.net –  Aug 21 '14 at 11:39
0

There can be only one persistable class with a given classname on the entire device. If two apps have the same class which are persistable, you'll get a Class Multiply Defined verification error and the second app will not install at all.

The only way is to use the builtin persistable classes for storing persistable data in the SDK. However, this persitable data will not be deleted even when all the apps containing the SDK have been removed by the user. You will also have to take care of the versions of the data to be backward compatible.

You store the data using a builtin class like Hashtable, IntHashtable or Vector. Then you write a wrapper class which gets and sets this information. Basically you'll be mapping your persistable class to a Hashtable or Vector.

Again remember, you should never put any class that is not builtin into this datastore. Otherwise, the datastore will get deleted on the app uninstall.

Hope that helps.

Adwiv
  • 1,283
  • 9
  • 15