Flow: Use of long from DataProvider.size

Created on 23 Nov 2018  路  2Comments  路  Source: vaadin/flow

DataProvider.size method returns an int and I find myself to always cast longs from repositories, e.g. JPA CriteriaBuilder.count or Spring's CrudRepository.count which both returns longs.

Why not making DataProvider.size to return a long?

breaking change enhancement

Most helpful comment

Thank you @Legioth for your considerations.

I'm pointing this out for two reasons mainly:

  1. since the Data Provider API requires a Stream from fetch, and Stream returns/accepts long for count, skip and limit, I'd expect consistency with the Java Stream API, i.e.
DataProvider.fromCallbacks(
    query -> getStream().skip(query.getOffset()).limit(query.getLimit()),
    query -> getStream().count()
);

but instead I need to cast the count to int, or use Math.toIntExact.

  1. you are concerned about giving the impression that isn't a good idea to have a grid with that many rows, but I don't really get why: if the user has a way to filter data, why limiting the backend domain for DataProviders to integer values? It's quite limiting in my opinion, I sure have more than one use cases where I'll hit the integer limit and this would cause trouble.

All 2 comments

Some considerations of varying weight:

  • If we change type of the size method, then we should for consistency also change the type of the offset and limit in the query. This in turn would require application code to downcast those to int with other APIs that don't accept long when querying.
  • Changing it at this point would be backwards incompatible in a way that affects very many applications.
  • Returning long would give the impression that it's a good idea to have a grid with more than 2000000 rows, whereas that is most likely quite problematic from a usability point of view.

Thank you @Legioth for your considerations.

I'm pointing this out for two reasons mainly:

  1. since the Data Provider API requires a Stream from fetch, and Stream returns/accepts long for count, skip and limit, I'd expect consistency with the Java Stream API, i.e.
DataProvider.fromCallbacks(
    query -> getStream().skip(query.getOffset()).limit(query.getLimit()),
    query -> getStream().count()
);

but instead I need to cast the count to int, or use Math.toIntExact.

  1. you are concerned about giving the impression that isn't a good idea to have a grid with that many rows, but I don't really get why: if the user has a way to filter data, why limiting the backend domain for DataProviders to integer values? It's quite limiting in my opinion, I sure have more than one use cases where I'll hit the integer limit and this would cause trouble.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

appreciated picture appreciated  路  3Comments

marcushellberg picture marcushellberg  路  4Comments

knoobie picture knoobie  路  4Comments

anezthes picture anezthes  路  4Comments

vlukashov picture vlukashov  路  3Comments