Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getAllStatesSince() and getAllStatesBetween() to PersistenceExtensions #3466

Merged
merged 1 commit into from
May 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,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) {
Expand Down