Hello, please help
//GET DATA FROM DATABASE
DATA SIZE : ~21000 rows
public static <T> List<T>findAllWithRigts(int offset, int limit, Class<T> tClass) {
String rightsQuery = RightsExplorer.run(MainView.getCurrentUser(),tClass);
Session session = HibernateHikariUtil.getSession();
String sql = "From "+tClass.getSimpleName() +" WHERE "+rightsQuery+" ORDER BY dateCreate DESC";
Query query = session.createQuery(sql)
.setFirstResult(offset)
.setMaxResults(limit);
return query.getResultList();
}
public static<T> int getCount(Class<T> tClass) {
String rightsQuery = RightsExplorer.run(MainView.getCurrentUser(),tClass);
Long count = (Long) HibernateHikariUtil.getSession().createQuery("SELECT count(*) FROM "+tClass.getSimpleName()+" WHERE "+rightsQuery).uniqueResult();
Integer c = toIntExact( count);
return c;
}
DAO.getCount(getCurrentClass()) and DAO.findAllWithRigts(offset, limit, getCurrentClass()) : its work fast ~200ms;
But Grid element init: **~ 8sec **
My code:
int totalCount = DAO.getCount(getCurrentClass());
DataProvider<Object, Void> dataProvider = DataProvider.fromCallbacks(
// First callback fetches items based on a query
query -> {
// The index of the first item to load
int offset = query.getOffset();
// The number of items to load
int limit = query.getLimit();
List list = DAO.findAllWithRigts(offset, limit, getCurrentClass());
return list.stream();
},
// Second callback fetches the number of items for a query
query -> totalCount
);
Grid grid = new Grid<>();
grid.setPageSize(100);
grid.setDataProvider(dataProvider);
grid.addColumn(new ComponentRenderer<>(object ->{
VerticalLayout box = new VerticalLayout();
Label lName = new Label(object.getName());
}
box.add(lName);
return box;
})).setHeader("Name");
add(grid);