javavaadinvaadin14vaadin-grid

Vaadin's DataProvider.fromFilteringCallbacks hangs forever in loop, how to make it being complete?


I have the below dataProvider

 DataProvider<WebLogFileRow, WebLogFileFilter> dataProvider = DataProvider.fromFilteringCallbacks(
                query -> {
                    int offset = query.getOffset();
                    int limit = query.getLimit();
                    return webLogFileService.getLogFileRows(query.getFilter().get(), offset, limit).stream();
                },
                query -> {
                    int offset = query.getOffset();
                    int limit = query.getLimit();
                    return  webLogFileService.getLogFileRowsCount(query.getFilter().get(), offset, limit);
                }
        );

and the methods in fact call inside of them

  1. data repository with offset and limit values passed

  2. filter the results based on some conditions, so in fact not the whole set comes to grid output.

So, hanging happens when the counter query defines that the only 1 row should be present, then it puts limit 1 to data query and retrieves only one row, at step 1 only one piece of data is taken from the DB and at step 2 it is filtered out, so the total number of rows becomes 0. Instead of throwing some exception for me, the DataProvider starts the eternal loop. Is there a way to throw the exception when the data query's limit doesn't fit the expected value, instead of trying more and more?

enter image description here


Solution

    1. First my mistake was passing limit and offset params to the counter query. However, all that was passed haven't broke the counting results.

    2. The main mistake was to associate the grid's limit and offset with DB limit and offset, if then the list of items it was filtered out and no longer the same length as it was given to the counter query. So, I can't no longer use offset and limit there, as it isn't known how much data would be filtered out. So I had to give them all and that potentially wrong on large data grids

       DataProvider<WebLogFileRow, WebLogFileFilter> dataProvider = DataProvider.fromFilteringCallbacks(
                   query -> {
                       int offset = query.getOffset();
                       int limit = query.getLimit();
                       return webLogFileService.getLogFileRows(query.getFilter().get(), null, null).stream();
                   },
                   query -> {
                       int offset = query.getOffset();
                       int limit = query.getLimit();
                       return  webLogFileService.getLogFileRowsCount(query.getFilter().get(), null, null);
                   }
           );