MemPOI
MemPOI copied to clipboard
Support a wider range of data sources i.e. not just `PreparedStatement`
Is your feature request related to a problem? Please describe.
Currently, the only way to provide the data for a worksheet is via a PreparedStatement
. This is not very convenient for projects that don't use raw SQL or don't use a relational database at all.
Describe the solution you'd like In my specific case, database access is usually one of the following
- A method of a Spring Data JPA repository that defines a JPQL query
- A criteria query
As far as I know, there is no way to get a PreparedStatement
from a Spring Data JPA repository method such as this one
public interface UserRepository extends CrudRepository<User, UUID> {
@Query("""
from UserRole ur
where ur.role.name = 'SYSTEM_ADMIN'""")
Collection<UserRole> findAllSysAdmins();
}
In this case, the query is relatively simple, so it would not be too arduous to define a PreparedStatement
that executes the equivalent SQL query, but for more complex queries the effort required to translate the JPQL/criteria query into SQL could be considerable.
Although support for JPA queries would solve my problem, perhaps it would be better to consider a type that hides the details of where the data comes from, e.g.
interface WorksheetData {
/* Provides the labels to be used for the columns in row 1 of the worksheet */
List<String> columnHeaders()
/* Provides the values to be shown in rows 2 onwards of the worksheet */
List<List<Object> cellValues()
}
Then a user could provide their own implementation of this object (instead of a PreparedStatement
) which might get the data from a web service, a text file, etc. but MemPOI shouldn't know or care where the data comes from.