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
CustomerBrowsescreen 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_CUSTOMERtable has theIDX_SAMPLE_CUSTOMER_UNQ_EMAILconstraint byEMAILcolumn, so the database throws an error on attempt to create two customers with the same email. The main message pack of thewebmodule contains a message with theIDX_SAMPLE_CUSTOMER_UNQ_EMAILkey 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-clientdirectory. To create IntelliJ IDEA project files, open the command line in this directory and rungradle 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.
- The
Based on CUBA Platform 6.6.1