This sample demonstrates two ways of working with views in ms-sql. The same approach can be used for another database.
The sample has two persistent entities
Each employee belongs to some department.
There are two views declared in the database and 2 corresponding entities:
- The AvgHourlyRate entity mapped to the avg_hourly_rate DB view - shows the average hourly rate between all employees in the department
- Mapping works through the standard CUBA mechanism
- The only restriction of the approach is that the view must have id field
- The DepartmentSize entity mapped to the department_size DB view (shows how many employees work in the department) by the EntityQuery and QueryField annotations
- Mapping is implemented in the custom TsqlQueryDatasource datasource via QueryServiceBean
- The datasource supprots paging and sorting on the DB side
Define a datasource in your screen (as it is shown here) and then you can specify it for any data-aware UI component in CUBA (for example it is shown here).