Programmatic data manipulation
Latest commit a1cac03 Jan 5, 2017 @knstvk knstvk committed on GitHub Update
Failed to load latest commit information.

Data Manipulation

This example project outlines various ways of programmatic data manipulation in CUBA applications.

  • Programmatic creation, updating and deletion of entities on the middleware and on the client tier. See the following methods of the CustomerBrowse screen controller:

    • onCreateInService() - sends customer data to a middleware service method.
    • onCreateInController() - replicates the logic of the midlleware service right in the screen controller.
  • Execution of queries on the middleware and on the client tier. See the following methods of the CustomerBrowse screen controller:

    • calculateDiscountInService() - delegeates to a middleware service method.
    • calculateDiscountInScreen() - executes query in the screen controller via DataManager.
  • Providing uniqueness by using database-level unique constraints. The SAMPLE_CUSTOMER table has the IDX_SAMPLE_CUSTOMER_UNQ_EMAIL constraint by EMAIL column, so the database throws an error on attempt to create two customers with the same email. The main message pack of the web module contains a message with the IDX_SAMPLE_CUSTOMER_UNQ_EMAIL key which will be automatically picked up by the platform to display a user-friendly message. See cuba.uniqueConstraintViolationPattern application property for how to adjust this mechanism for your database.

  • Enforcing complex rules using entity listeners. OrderEntityListener throws an exception on attempt to create an order if there are already two or more orders for the same customer on the same day.

  • Handling exceptions coming from the middleware. TooManyOrdersExceptionHandler shows a notification on unhandled TooManyOrdersException. See Client-Level Exception Handlers for details.

  • Using the REST API to control the application from an external tool. See the project in the clients/rest-client directory. To create IntelliJ IDEA project files, open the command line in this directory and run gradle idea.

    • The RestClient.createCustomer() method creates an entity by sending JSON to the standard REST API CRUD method.
    • The RestClient.createCustomerViaService() method creates an entity by sending its attributes to the middleware service.

Based on CUBA Platform 6.3.5