javablackberryjakarta-eepersistent-object-store

PersistentObject Blackberry


How can you easily check whether your app has persistentObjects? Right now I'm using the following:

public boolean needsFirstTimeInit() {
    PersistentObject persistentObject = getPersistentObject(Settings.TABLE_USERS);
    Vector vector = (Vector) getVector(persistentObject);
    if(vector.size()<=0){
        return true;
    }
    return false;
}

The negative here is that I'm asking data from a table I know that has to exists, and if it exists I assume the tables haven't been initialized. Is there a better way of doing this?


Solution

  • The following solution worked best for me:

    PersistentObject is considered as a table and contains a Vector(filled with objects).

    I made a vector with all hashcodes of the tableNames. (v1) I made a hashtable (hashcode tablename, PersistentObject); (h1) On every startup I check if all hashcodes in v1 have a value (persistentObject) in h2. If not, I initialise the persistentObject and put it in the hashtable.