I would like to display a 2D-chart containing the amount of processed objects (mapped in JPA) in a given time span. This amount can be scale up to around 30k objects in an timespan of 30 minutes.
As a DBMS I am using PostgreSQL 9.4 and JPA 2.0 with Hibernate in version 4.2.21.
At the moment I am using this piece of code in order to add the amount into my temporal "buckets".
// Get all objects after a given start date
List<MyObject> myObjects= myJPADbService.getMyObjects(Date.from(startDate.atZone
(ZoneId.systemDefault()).toInstant()), Integer.MAX_VALUE);
for (MyObject information : myObjects) {
LocalDateTime pageDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(information.getLastSeen().getTime()), ZoneId.systemDefault());
long duration;
if (temporalUnit == ChronoUnit.MINUTES) {
duration = Duration.between(startDate, pageDate).toMinutes();
} else if (temporalUnit == ChronoUnit.DAYS) {
duration = Duration.between(startDate, pageDate).toDays();
} else {
duration = Duration.between(startDate, pageDate).toHours();
}
pagesPerUnit[(int) (Math.abs(duration))]++;
}
However depending on an user selected timespan, this piece of code might be very inefficient. It might be more efficient, if the DBMS computes the buckets according to an user selected timespan.
How can this be formulated in proper JPQL syntax?