Initial Load Mobile Database

Initial Load Mobile Database

  

Hi,

I want to develop a mobile only application (i.e. no server components) that has a set of core components (i.e. no UI) that have a database that has some pre-loaded tables.

There are two questions:

1. What event can I use to cause the database to load from some source when it is downloaded and installs itself?

- There does not seem to be any system event that I can use to cause the pre-load of the database?

- So far I have created an initial load action that another "main" mobile app can call from it's  "OnApplicationReady" event, which I believe only fires when the first UI is executed.

2. What is the best way to actually load the database?

- I can load tables with direct code record by record which works for tables with a small number of rows

- I tried to do it with a json text file in the resources folder but am not very familiar with json and so far have not made it work continually getting failures processing my attempt at a json file. If anyone has a small example of that I would be grateful.


Once again these are headless components with no server interaction so no sysncronization or calls to a server component are possible.

I may be missing something obvious but any help would be appreciated.

Thanks

Keith




Hi Keith,

I wonder what you are trying to achieve. Could you be more specific about your use case?

If you can have the data in the server also, I would suggest you use one of the common offline data synchronisation patterns advocated by Outsystems to get your local entities filled in from entities in the server. Check them here. You can either opt for the Read Only pattern or the Read-Only Data Optimized pattern.

If you can go along by filling the local entities from server side entities, then you can configure the moment the synchronisation takes place by changing the config in the OfflineDataSyncConfiguration action. I would suggest you set the SyncOnOnline parameter to true. According to the documentation, the synchronisation will take place the moment the device becomes online. I didn't try this one yet, so my advice is based on the docs :) Check it here

For more details on how to trigger offline synchronisation, you can check the documentation here.

EDIT: Even though you are saying that your module is a "headless" module, I would suspect you still can make use of the mobile patterns module to get the offline data sync to work. I have to try this myself though. Good luck en let us know if and how you made some progress on this.

Greetings, pedro

Pedro Rodrigues wrote:

Hi Keith,

I wonder what you are trying to achieve. Could you be more specific about your use case?

If you can have the data in the server also, I would suggest you use one of the common offline data synchronisation patterns advocated by Outsystems to get your local entities filled in from entities in the server. Check them here. You can either opt for the Read Only pattern or the Read-Only Data Optimized pattern.

If you can go along by filling the local entities from server side entities, then you can configure the moment the synchronisation takes place by changing the config in the OfflineDataSyncConfiguration action. I would suggest you set the SyncOnOnline parameter to true. According to the documentation, the synchronisation will take place the moment the device becomes online. I didn't try this one yet, so my advice is based on the docs :) Check it here

For more details on how to trigger offline synchronisation, you can check the documentation here.

Greetings, pedro

Hi Pedro,


Thanks for replying. I am well aware of synchronization and it's patterns which is why I explained that this was mobile only and has no server access.

I am trying to create a mobile architecture that utilizes mobile core components with no reliance on a server. I can do it OK and everything will work fine except that when installed the database does not load automatically, giving the two issues for which I am seeking a better answer than the ones I have.


This would be like a 4-layer architecture for mobile.

Thanks

Keith

 


Hi Keith, I see what you mean. Can you be more specific on your use case? Is the data read-only? why do you need to have it prefilled? is it reference data (e.g. countries, zipcodes)? Can you share the module you are working on even though it is still not working as expected?


greetings, pedro

Solution

Hi Keith, apparently there is no cordova event triggered the moment an app is installed (the list of all possible cordova events: https://cordova.apache.org/docs/en/latest/cordova/events/events.html). As Outsystems runs from within cordova, there is no way for you to trigger the load of the local entity upon app installation. 

The first event triggered is the deviceready event which I assume is mapped to the OnApplicationReady system event in Outsystems. As a result, I don't think there is any other way to trigger the load of the data than the one you suggested (having an action that loads the data triggered from the OnApplicationReady in the "main" mobile app).


With respect to how to load the data into the local storage, I'm sending you an oap with an example. In sum, there is a client action that returns the JSON representing all countries. This action is used as the source of information to fill in the Country local entity. See if it suits your needs.


greetings, pedro

Solution

Pedro Rodrigues wrote:

Hi Keith, apparently there is no cordova event triggered the moment an app is installed (the list of all possible cordova events: https://cordova.apache.org/docs/en/latest/cordova/events/events.html). As Outsystems runs from within cordova, there is no way for you to trigger the load of the local entity upon app installation. 

The first event triggered is the deviceready event which I assume is mapped to the OnApplicationReady system event in Outsystems. As a result, I don't think there is any other way to trigger the load of the data than the one you suggested (having an action that loads the data triggered from the OnApplicationReady in the "main" mobile app).


With respect to how to load the data into the local storage, I'm sending you an oap with an example. In sum, there is a client action that returns the JSON representing all countries. This action is used as the source of information to fill in the Country local entity. See if it suits your needs.


greetings, pedro

Hi Pedro,

That certainly helped a lot to figure out my JSON issues, so thanks very much for that.

Also for confirming that I am not missing some event that will help to trigger the load of the data. The way I currently have it is workable and works fine as the consumer has to know it is consuming the provider module so needs to make sure its data is loaded.

I can work on putting the JSON in a file and loading it with some javascript.

Regards

Keith


Keith,

I tried to duplicate a process I have working with another development environment.

I created a SQLite database (e.g. test.db) and included that database with the PhoneGap Build build.

Then I used the SQLite Plugin to work with that database.  It's completely server free.

I've tried the same process under OS but can't get it going..  I used the Data tab, Resources, to include my test.db database.  I tried accessing that test.db file with SQLite directly and with the File Plugin... but there's so little doc on all this... and OS makes stuff so convoluted... that I can't get it working.

Hi Keith, you're welcome. Just one suggestion: 

In order to make sure that the developer does not forget to call the data loader action, I would suggest that the first thing you do in every public action available in the services module you are creating is to check whether the data load has taken place. If that is not a case, raise an exception. You don't have a check in development time but at least in runtime the user will get to see what is wrong. 

Greetings, Pedro 

Keith,

Do you need to completely avoid server communication?

You can minimize the info being sent between client/server...

Either way, I just want to mention this great article by Miguel Vicente, where he talks about the challenges faced building the Next Step app.

There are some cool tips in there.

Pedro Rodrigues wrote:

Hi Keith, you're welcome. Just one suggestion: 

In order to make sure that the developer does not forget to call the data loader action, I would suggest that the first thing you do in every public action available in the services module you are creating is to check whether the data load has taken place. If that is not a case, raise an exception. You don't have a check in development time but at least in runtime the user will get to see what is wrong. 

Greetings, Pedro 

Hi Pedro,

Yes I have that catcher, thanks agaiin for being so helpful.

Keith


João Heleno wrote:

Keith,

Do you need to completely avoid server communication?

You can minimize the info being sent between client/server...

Either way, I just want to mention this great article by Miguel Vicente, where he talks about the challenges faced building the Next Step app.

There are some cool tips in there.

Hi João,

The answer in this case is Yes.

Thanks for the pointer to the article. For Web/Mobile I already have most of the stuff it talks about, SyncController, RI-Handler etc., but this is going to be solely mobile.

Regards

Keith