简体   繁体   中英

IBM Worklight - JSONStore fails to initialize after Direct Update

I am using Worklight 6.0.0.2 for JSONStore-related fixes in Android 4.4 "KitKit".

It works fine except for one issue: after a Direct Update the application restarts but then the JSONStore initialization fails; if we then quit the application and relaunch then it works well.

Steps for reproduction the issue in android 4.4. "KitKat":

  1. Trigger a Direct Update
  2. Allow application to launch it self after updating

    Then you see in LogCat:

    05-13 16:28:57.010: E/jsonstore-core(16691): Error validating schema 05-13 16:28:57.010: E/jsonstore-core(16691): java.lang.Throwable: node with name "_id" already exists in schema 05-13 16:28:57.010: E/jsonstore-core(16691): at com.worklight.androidgap.jsonstore.database.DatabaseSchema.addNode(DatabaseSchema.java:124)

  3. Close the application.
  4. Relaunch it.

Inside initoptions.js

var wlInitOptions = {
connectOnStartup : false,
heartBeatIntervalInSecs : 5,

logger : {
    enabled : true,
    level : 'debug',
    stringify : true,
    pretty : false,
    tag : {
        level : false,
        pkg : true
    },
    whitelist : [],
    blacklist : []
},
analytics : {
    enabled : false
},

};

Inside JS file:

 function wlCommonInit(){
     collections["Videos"] = {
     searchFields:{"BrandID":"string","VideoType":"string","CategoryID":"string","CourseID":"string","ISDeleted":"string","IsDownload":"string","VideoID":"string"}
        };
        var options = {"username":"*","password":"*","localKeyGen":false,"clear":false};

WL.JSONStore.init(collections, options)
        .then(function (resp) {
        Brands=WL.JSONStore.get('Brands');
        Categories=WL.JSONStore.get('Categories');
        Courses=WL.JSONStore.get('Courses');
        Videos=WL.JSONStore.get('Videos');
        Notification=WL.JSONStore.get('Notification');
        UserInformationColl = WL.JSONStore.get('UserInformation');
        BrandListCollection = WL.JSONStore.get('BrandList');
        VideosList = WL.JSONStore.get('VideoList');
        BusinessType= WL.JSONStore.get('BusinessType');

        connectToServer();
    //  initializeAnalytics(2000,131);

            var query={"IsDownload":"2"};
            WL.JSONStore.get('Videos').find(query, {exact:true})
            .then(function (result2) {
                if(result2.length > 0){
                    for(var i=0; i<result2.length; i++){
                        result2[i].json.IsDownload = 0;
                        Videos.replace(result2[i], {})
                        .then(function (numberOfDocumentsReplaced) {
                            WL.Logger.info("The number of document replaced are:--->"+numberOfDocumentsReplaced);
                        })

                        .fail(function (errorObject) {
                            WL.Logger.error("Error in document:---->"+errorObject);
                        });
                    }
                }
                errorvideodownloading();
            })
            .fail(function (errorObject) {
                WL.Logger.debug('error' +errorObject.toString());

            });
        })
        .fail(function (errorObject) {
             WL.Logger.error("init notification error:----->"+errorObject);
             if(errorObject.err === -2){
                 WL.Logger.error("In the errorObject so destroying JSON store and recreating it.");
                 WL.JSONStore.destroy();
                 JsonStoreinit();
                 localStorage.clear();
                 connectToServer();
            }
             else if(errorObject.err === 16)
             {
             hideSplashScreenPlatForm();
             } 
        });
}
else{
    WL.Logger.debug('[JSONStore] Check your dependencies.');

}
}catch(e){
     WL.Logger.error("Exception is:--->"+e);
}   

}

Am not sure about your init Code. But you will get error like

java.lang.Throwable: node with name "_id" already exists in schema 

when you are using the collection until a successful callback.

See this answer for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM