Skip to content

How to Create a new WEBSQL Table

sangramanand edited this page Jul 11, 2013 · 1 revision

WEBSQL operates exactly like the normal Database, but its data is stored in the Browser. WEBSQL queries allows us to access the database virtually when the Regular Database connection is lost.

Pre-requisites

  • We create a new Table called RESPOS_MODIFIERS
  • on running script ant update.database, a Object Model class of the new table is generated say MenuModifiers.java
  • The MenuModifiers.java contains the setters & getters method of all the class properties which actually are columns of the DB table.

Once we have the pre-requisites ready, we can go ahead and create a WEBSQL table for RESPOS_MODIFIERS

Steps for creating WEBSQL Table - RESPOS_MODIFIERS

  1. Create a new Class in package "org.openbravo.retail.posterminal.master" named OutletItemModifiers.java

  2. The class should extend ProcessHQLQuery. In the override method getQuery(), add the table details and the list of columns that you want to fetch from DB and store in WEBSQL. EX: @ https://gist.github.com/sangramanand/94e4b1d1c4860a25f814#file-itemmodifiers-js

  3. Create a new js file, say ItemModifiers.java. The JS file contains all the properties MAP & CRUD Operations of the table - RESPOS_MODIFIERS. EX:https://gist.github.com/sangramanand/94e4b1d1c4860a25f814#file-outletitemmodifiers-java

  4. The reference of WEBSQL Table i.e., OB.Model.ItemModifiers should be included in the Window's model that is accessing the RESPOS_MODIFIERS. In our case, pointofsale-model.js.

  5. Now, run the ant smartbuild to compile the java class and update the webcontent folder for the newly created JS file.

  6. Reload the page, and Navigate to Resources tab in the Chrome developer tools. The Resources page contains the WEBSQL options, which displays all the Tables available. Check for RESPOS_MODIFIERS.

WEBSQL

Note: If the entire process goes fine, you will find the RESPOS_MODIFIERS table. Now, you can run the line,

OB.Dal.find(OB.Model.ItemModifiers, criteria, successCallbackProducts, errorCallback);

to fetch the records from RESPOS_MODIFIERS table of WEBSQL.