Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleHook for loading data
loadOrderGroups(viewState) {

    grid = viewState.getComponentByReference("orderGroupsGrid");
    
    // standard or expanded Hibernate or JPA criteria builder
    criteriaBuilder = someService.getCriteriaBuilder();
    criteriaQuery = criteriaBuilder.createQuery();
    from = criteriaQuery.from("orderGroup");
    min = criteriaBuilder.min(from.get("orders"));
    
    // the 'modelName' entity must be always first
    criteriaQuery = criteriaQuery.multiselect(from, min);
    
    // this would apply criteria from the grids filter but not pagination yet
    criteriaQuery = someService.applyGridFilterCriteria(criteriaQuery, grid);
    
    query = someService.createQuery(criteriaQuery);
    
    // list() dosn't fetch data from the db, it just prepares the list
    // object which in fact is a proxy to the database
    datasetSize = query.list().size();
    
    query.setFirstResult(grid.getFirstResult());
    query.setMaxResults(grid.getMaxResults());
    
    // the first get from the list will actualy call select on the db
    // remember that in this case this is actually a List<Object[]>
    grid.setDatasetPage(query.list());
    grid.setDatasetSize(datasetSize);
}