Skip to content

Commit

Permalink
Add getAllStatesSince() and getAllStatesBetween() to PersistenceExten…
Browse files Browse the repository at this point in the history
…sions (#3466)

Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored May 27, 2023
1 parent 7843b68 commit 6bb15b8
Showing 1 changed file with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,62 @@ public static long countStateChangesBetween(Item item, ZonedDateTime begin, @Nul
return null;
}

private static Iterable<HistoricItem> getAllStatesBetween(Item item, ZonedDateTime begin,
/**
* Retrieves the historic items for a given <code>item</code> since a certain point in time.
* The default persistence service is used.
*
* @param item the item for which to retrieve the historic item
* @param timestamp the point in time from which to retrieve the states
* @return the historic items since the given point in time, or <code>null</code> if no historic items could be
* found.
*/
public static Iterable<HistoricItem> getAllStatesSince(Item item, ZonedDateTime timestamp) {
return getAllStatesBetween(item, timestamp, null);
}

/**
* Retrieves the historic items for a given <code>item</code> since a certain point in time
* through a {@link PersistenceService} identified by the <code>serviceId</code>.
*
* @param item the item for which to retrieve the historic item
* @param timestamp the point in time from which to retrieve the states
* @param serviceId the name of the {@link PersistenceService} to use
* @return the historic items since the given point in time, or <code>null</code> if no historic items could be
* found or if the provided <code>serviceId</code> does not refer to an available
* {@link QueryablePersistenceService}
*/
public static Iterable<HistoricItem> getAllStatesSince(Item item, ZonedDateTime timestamp, String serviceId) {
return getAllStatesBetween(item, timestamp, null, serviceId);
}

/**
* Retrieves the historic items for a given <code>item</code> beetween two certain points in time.
* The default persistence service is used.
*
* @param item the item for which to retrieve the historic item
* @param begin the point in time from which to retrieve the states
* @param end the point in time to which to retrieve the states
* @return the historic items between the given points in time, or <code>null</code> if no historic items could be
* found.
*/
public static Iterable<HistoricItem> getAllStatesBetween(Item item, ZonedDateTime begin,
@Nullable ZonedDateTime end) {
return getAllStatesBetween(item, begin, end, getDefaultServiceId());
}

/**
* Retrieves the historic items for a given <code>item</code> beetween two certain points in time
* through a {@link PersistenceService} identified by the <code>serviceId</code>.
*
* @param item the item for which to retrieve the historic item
* @param begin the point in time from which to retrieve the states
* @param end the point in time to which to retrieve the states
* @param serviceId the name of the {@link PersistenceService} to use
* @return the historic items between the given points in time, or <code>null</code> if no historic items could be
* found or if the provided <code>serviceId</code> does not refer to an available
* {@link QueryablePersistenceService}
*/
public static Iterable<HistoricItem> getAllStatesBetween(Item item, ZonedDateTime begin,
@Nullable ZonedDateTime end, String serviceId) {
PersistenceService service = getService(serviceId);
if (service instanceof QueryablePersistenceService qService) {
Expand Down

0 comments on commit 6bb15b8

Please sign in to comment.