User Guide
  • Introduction
  • Overview
    • About 4WS.Platform
      • Architecture
      • Enterprise Edition
      • Tech specs and requirements
      • Warp SDK
    • Creating a web application
  • Core features
    • Tables
    • SqlTool
    • Definition of Data models and Relations
      • Relations
      • Reverse Engineering
      • Custom Fields
    • Defining business components
      • What are business components
      • Business components to fill-in panels
      • Creating business components
        • By a datastore entity
        • By a MongoDB collection
      • Defining Custom Java Business component
    • Defining the UI
      • App Designer
        • App Designer Menu
        • Definition of additional data sources
        • Panel containers and layouts
          • Tab panel
          • Alternative panel
          • Accordion panel
          • Vertical orientation panel
          • Horizontal orientation panel
          • Columns panel
          • Table panel
          • Generic panel
          • Responsive panel
        • Window content
          • Grid Panel
          • Form Panel
          • Filter Panel
          • Tree Panel
          • Google Map Panel
          • Preview Panel (old Image panel)
          • Tree + Grid Panel
          • Image Gallery
        • Windows list
        • Panel definition
          • Columns properties
          • Controls properties
          • Filter properties
          • Supported components
        • Variables
        • Code selectors
          • When not to use a dynamic combo-box
        • Smart Filter and Advanced Filter
        • Multi Value Combobox Filter
        • Multi Value Tree Filter
        • Buttons
        • Translations
          • Translations about GUI components and internationalization settings
          • Data coming from database
          • Custom code and translations
        • Application Menu
        • Bulk import binded to a grid
        • Range Date Filter
      • Web Interpreter
        • Grid components
        • Detail forms
        • Other components
        • Other features
          • Chat
        • Global variables
          • Client-side global variables
          • Server global variables
        • Forgot Password
    • Working with users and roles
      • Rule for roles
      • Permissions Administrator
    • Wizard
      • How to add a checkbox grid to select one or more rows
      • How to load a second grid when clicking on a row from the first grid
      • How to load a form when clicking on a row of the grid
      • How to open a window when double clicking on a row of the grid
      • How to open a window with right click on the popup menu
      • How to open a window when pressing a button on the grid toolbar
      • How to load a grid after loading a form
      • How to open a window when pressing a button on the form toolbar
      • How to load a grid when clicking on a tree node
      • How to load a form when clicking on a tree node
    • Defining events
      • Panel events
      • Column events
      • Control events
      • Filter events
      • Timer events
      • Start-End event
    • Server-side Javascript & Web Service
      • Server-side Javascript
      • Grid component filled by a server-side JS
      • Detail component filled by a server-side JS
      • How to define a server-side JavaScript action
      • Web service
  • Setting up the environment
    • How to install
    • Application parameters
    • Global parameters
  • Modules
    • Reports & Charts
      • Jasper Report + iReport
      • Online report
      • Docx templating
      • Charts
      • Pivot Grid
      • Multidimensional pivot grid
      • Data Export from SQL query
    • SSO
      • Identity management in Platform
        • Identity management on the internal Platform database
        • Identity management based on Google SSO
      • LDAP
        • LDAP support
        • Identity management based on LDAP and database
        • Identity management based on an embedded LDAP server used by Alfresco and or Activiti
        • Identity management based on a remote LDAP server to connect to Platform on the cloud
        • Connecting an LDAP server to Activiti BPM
        • Connecting an LDAP server to Alfresco ECM
      • Google SSO
        • Google SSO
        • Google OAuth2
        • Identity management based on Google SSO
      • Custom SSO
      • Firebase
    • Mobile
      • Mobile introduction
      • Offline vs Online
        • Server side features
        • Server side functionalities
        • Server side Platform features
        • Mobile app features
      • Mobile side specifics
        • Customizations
          • Custom theme editor
        • App Menu
        • Window content
          • Detail scrollable form
          • Scrollable paginated grid
          • Constraint layout
          • Constraint panel
          • Collection grid view
          • Preview panel (mobile)
        • Form Controls
      • Reference guide
      • Cleaning up data
      • How to
      • App deployment
        • App deployment for the iOS platform
        • App deployment for the Android platform
      • Style properties
      • Appendix : Synchronization flow
      • Translations
    • GSuite
      • Introduction
      • Client-side integration
      • GMail
      • Calendar
      • Drive
      • Contacts
    • Google Cloud Platform
      • Datastore
        • Google Datastore Introduction
        • How to create Datastore entities
      • Google Cloud Storage
    • Scheduler
      • Scheduler Introduction
      • Process settings
        • How to define a sequence of consecutive processes
        • How to define a Custom Java Business component
        • How to define a Grid Data Import
        • How to define a server-side Javascript action
      • Email notifications
      • Process executions
      • Manually start a scheduled process
      • Process input parameters
    • Queue Manager
    • Log & Analysis
      • Application Log
      • Log statistics
      • App analyzer
      • Table log
      • Threads
      • Sessions and heap memory
      • Heap memory analysis
      • Access Log
      • Datastore statistics
      • Total monthly costs with Google Datastore
      • Service Monitoring
        • Introduction
        • Defining a service to monitor
        • Notifications setup
        • Events automatically managed by Platform
        • Remote Platform servers
        • Knowledge base
        • Adding log programatically
        • Searching for logged data
        • Use cases
    • File Management
    • Export and Import of Metadata
      • Application Metadata Management
    • Trigger writing operations
    • Audit
    • BPM
      • BPMN Introduction
      • BPMN main parts
      • Activiti Setup
      • Platform integration
        • Processes
        • Models
        • Process instances
        • To-do list
        • Process history
      • Process Web Modeler
        • Model Creation
          • Start-End Event
          • Gateways
        • Supported objects
        • Start tasks and user tasks
        • Form properties
          • Important notes
          • Property types
        • Service tasks
          • Web service
          • SQL Query
          • SQL statement
        • Mail task
        • Script task
          • Example : how to get a value previously read from a SQL query
          • Example : how to get the current process instance id
        • Timer events
        • Subprocess and Call Activiti
      • Utility methods available in Platform
        • How to start a process from a JavaScript action
        • How to complete a user task from a JavaScript action
      • An example
        • Processes
        • Instances
        • Activities
        • History
    • Embedded CMS
    • ECM
      • Alfresco
        • Alfresco Introduction
        • Integration between 4WS.Platform and Alfresco
          • Integration at GUI level
          • Integration at model level
          • Integration at authentication and authorizations level
          • Additional features
        • How to use 4WS.Platform and Alfresco together
          • Set the same Identity Management system
          • Define document types and aspects in Alfresco
          • Import the document types and aspects definitions in 4WS.Platform
          • Define document types and aspects in 4WS.Platform
          • Reverse engineering of document types or aspects
          • Definition of business components to fill-in panels
          • Definition of the GUI
          • Additional server-side services
        • Requirements
        • Current limits in 4WS.Platform - Alfresco integration
      • Archiflow
        • Setup
        • Archiflow artifacts
        • How to
    • Lotus Notes Migration Tool
    • NoSQL databases
      • MongoDB
        • MongoDB Introduction
        • Setting up the environment
        • How to create collections
        • How to create business components
        • How to create windows filled with data coming from MongoDB collections
        • Design rules
      • Google Datastore
        • Google Datastore Introduction
        • Setting up the environment
        • How to create entities
        • How to create business components
        • How to create windows filled with data coming from Datastore entities
        • Design rules
    • TensorFlow
    • Web Page Development
      • Pure Web Page Development
      • Google Material Design development
      • Appendix A - a complete example without any lib
      • Appendix B - a complete example with Google MD
    • Jira Integration
    • Platform for GAE
    • SQL errors management
    • Multidimensional pivot grid
    • Quality
      • Automated Web Service Testing
      • Automated unit testing
      • Source code static analysis using ESlint
      • Source code static analysis using SonarQube
  • Troubleshootings
  • Best practises
    • Database design
    • Database maintenance
    • Creating a Web app : common use cases
    • Creating a mobile app : common use cases
Powered by GitBook
On this page

Was this helpful?

  1. Best practises

Database design

In case you need to design a new database, it can be helpful to create tables having a common structure, in terms of field names and type. These are some rules that we suggest to follow: PRIMARY KEY : You should not define fields called ID or FUNCTION in the DB, as they may conflict with some Javascript commands. A possible variant is to call ID_ or _ID, e.g. CUSTOMER_ID, PRODUCT_ID, etc. Every table must have either a primary key or unique keys. Platform does not replace the business analysis: this important task must be carried out before the development of the application, as well as the database design. Independently of the way an application will be developed, the analysis still plays a foundamental role in the development cycle of the application. DATABASE TYPES : field types must be defined according to the database types; these are common types that can be used with Platform:

  • Oracle database

    • NUMBER(N)

    • DATE

    • CHAR(N)

    • CLOB

  • MS SQLServer database

    • NUMERIC(N)

    • DECIMAL(M,N)

    • DATE

    • DATETIME

    • NVARCHAR(N)

    • NCHAR(N)

    • TEXT

  • MySQL database

    • NUMERIC(N)

    • DECIMAL(M,N)

    • DATE

    • DATETIME

    • VARCHAR(N)

    • CHAR(N)

    • TEXT

  • PostgreSQL database

    • NUMERIC(N)

    • DECIMAL(M,N)

    • DATE

    • DATETIME

    • VARCHAR(N)

    • CHAR(N)

    • TEXT

Moreover, we suggest to define the database instance with a Unicode charset: this will ensure that characters typed using the GUI will be stored correctly into the database.

IDENTITY FIELDS/SEQUENCES : Oracle sequences are supported, as well as identity fields in SQLServer, PostgreSQL and MySQL

STANDARD FIELDS TO INCLUDE IN ANY TABLE : if you want to trace data creation/updating carried out by the users, a few fields should be added to each table; in the following list a series of fields are reported with type and meaning:

  • USER_ID_CREATE VARCHAR(255))/NVARCHAR(255) – Platform can use this field to automatically store the user who is creating the record

  • CREATE_DATE DATE/DATETIME – Platform can use this field to automatically store the current date when creating a new record

  • USER_ID_UPDATE VARCHAR(255))/NVARCHAR(255) – Platform can use this field to automatically store the user who is updating the record

  • LAST_UPDATE DATE/DATETIME – Platform can use this field to automatically store the current date when updating the current record

  • ENABLED CHAR(1)/NCHAR(1) – Flag used to manage logical deletion of records: it can have S/N or Y/N values, used to filter a list of "valid" records, i.e. not logically deleted; when deleting a record, it will be marked as logically deleted (flag set to ‘N’), i.e. not actually removed from the database, but just updated to the ‘N’ value

  • ROW_VERSION NUMBER(12)/NUMERIC(12) – Numeric field used to manage concurrent updates to the same record from different users: each time the record is updated by a specific user, Platform will automatically increase the value of this field and will forbit the next update if the record to update will not have the ROW_VERSION value aligned to the most refreshed value: this behavior will avoid to have inconsistent data stored into the database due to different users working on old data.

DATA PARTITION : according to the database and data visibility, there are scenarios where data must be partitioned according to the user. That means that (all) tables should contain an additional field in the primary key used to filter data according to the current user.

Furthermore, in case of an "application service provider" installation, where the same database should be used to serve different organizations sharing the same database structure but NOT the same data, data must be partitioned according to the organization (i.e. a set of users beloning to the same organization). That means that all tables should contain an additional field in the primary key used to filter data according to the organization the user belongs to. These two needs are both supported by Platform, through two additional fields to add to all tables as part of the primary key:

  • COMPANY_ID CHAR(1)/NCHAR(1) NOT NULL – this field represents the organization; users belonging to the same organization will be defined using the same COMPANY_ID value

  • SITE_ID NUMBER(5)/NUMERIC(5) NOT NULL – this field represents the property of a record; different records could have different values of SITE_ID (e.g. 00000,00001,00002 etc); in this way, a user could be granted to read (and/or write) records having SITE_ID 00000 or 00001 but not 00002.

PERFORMANCE ISSUES : When working with databases, there can be performance issues involved with the execution of SQL queries. It is important to being aware of these issues and the right way to deal with them:

  • total number of records – usually a business component for lists executes two SQL queries: the first is the real query used to fetch the first block of data, the second is a SELECT COUNT(*) FROM … used to recon the total number of records composing the result set. This information is used to show on the grid the total number of records and allow the scrolling among the pages of data until the last block of data. The second query can consume a significant amount of time with a very large table content: in this scenario it would be better to disable the execution of the second query. In order to do it, open the business component for list, click of the “Panels” subfolder and open all grids depending on that business component: in the grid definition window, you can see a check box named “Do not count records”: when selecting it, the second query will be disabled

  • where conditions on not indexed fields – a very common scenario when a SQL query sounds slow is when there are WHERE conditions working on fields which have not been declared as indexed. Consequently the database cannot optimize the query to quickly fetch data. In such a scenario, try to add indexes to those fields.

  • where UPPER conditions on fields – pay attention to the filtering conditions applied to columns in grid. If you declare this filtering conditions as NOT case-sensitive, it means that Platform will apply automatically an UPPER function to the field, like in this example: SELECT * FROM TABLE WHERE UPPER(FIELD) = ‘TEXTINUPPERCASE’ . Unless you have defined a complex index on the UPPER function for that field, the database will not perform a fast query.

  • queries with binding variables vs queries without binding variables – it is not correct comparing the executing time of a query executed with Platform using binding variables (e.g. SELECT FIELD1 FROM TABLE WHERE FIELD2 = ? ) with the same query executed through an external SQL client where the binding variables have been replaced with in-line values: they query is not the same and consequently also the execution time! Pay attention to the where conditions, otherwise you can lead to the wrong result that the query in Platform is slow “for some reason”

  • CHAR type field in Oracle database – in case of Oracle database and a SQL query having a WHERE condition on CHAR type fields, it could happen that the SQL query seems slower: sometimes the performance can be improved in this scenario when replacing the binding variable on the CHAR field with an in-line value. You can force the execution of business component for list without the use of binding variables, by unchecking the checkbox named “Bind variables” in he business component definition window

  • the same query, executed multiple times – if you execute a SQL query in Platform and it seems slow and a few seconds after you execute exactly the same query on an external SQL client and here it is faster: bear in mind that a database is able to cache the result after the first execution of the query, so it could be wrong to compare the execution time described in this scenario! Try to invert the query executions: first on the SQL client, then on Platform: what about the resulting time?

  • fetch size when extracting data from a query – if you are executing a SQL query with a server-side js component and you are processing the whole result and this operation requires several seconds or minutes, but when executing the query on an external SQL client you can see the results instantly,, remember that it is likely the the SQL client is showing you only a porting of the whole data: that is the reason why it is faster; try to scroll all data shown on the SQL client until the end of the resultset: how long does it take?

Maintenance

It is not advisable to rename PK columns in a table. The application uses the PK fields to generate unique keys as well as to set the parameters of input/output for windows and panels. If you decide to change the primary keys fields, you have to align the data model, through the ad hoc button available in the detail model form and then manually align the input/output parameters folder of panes using that object.

PreviousBest practisesNextDatabase maintenance

Last updated 5 years ago

Was this helpful?