Package org.openhab.core.persistence
Interface QueryablePersistenceService
- All Superinterfaces:
PersistenceService
- All Known Subinterfaces:
ModifiablePersistenceService
A queryable persistence service which can be used to store and retrieve
data from openHAB. This is most likely some kind of database system.
- Author:
- Kai Kreuzer - Initial contribution, Chris Jackson - Added getItems method, Mark Herwege - Added methods to retrieve lastUpdate, lastChange and lastState from persistence, Mark Herwege - Implement aliases
-
Method Summary
Modifier and TypeMethodDescriptiondefault Set<PersistenceItemInfo> Returns a set ofPersistenceItemInfoabout items that are stored in the persistence service.default @Nullable PersistenceItemInfogetItemInfo(String itemName, @Nullable String alias) ReturnsPersistenceItemInfofor an item stored in the persistence service.default @Nullable PersistedItempersistedItem(String itemName, @Nullable String alias) Returns aPersistedItemrepresenting the persisted state, last update and change timestamps and previous persisted state.query(FilterCriteria filter) Queries thePersistenceServicefor historic data with a givenFilterCriteria.default Iterable<HistoricItem> query(FilterCriteria filter, @Nullable String alias) Queries thePersistenceServicefor historic data with a givenFilterCriteria.Methods inherited from interface org.openhab.core.persistence.PersistenceService
getDefaultStrategies, getId, getLabel, getSuggestedStrategies, store, store
-
Method Details
-
query
Queries thePersistenceServicefor historic data with a givenFilterCriteria. If the persistence service implementing this class supports using aliases for item names, the default implementation ofquery(FilterCriteria, String)should be overridden as well.- Parameters:
filter- the filter to apply to the query- Returns:
- a time series of items
-
query
Queries thePersistenceServicefor historic data with a givenFilterCriteria. If the persistence service implementing this interface supports aliases and relies on item registry lookups, the default implementation should be overridden to query the database with the aliased name.- Parameters:
filter- the filter to apply to the queryalias- for item name in database- Returns:
- a time series of items
-
getItemInfo
Returns a set ofPersistenceItemInfoabout items that are stored in the persistence service. This allows the persistence service to return information about items that are no longer available as anItemin openHAB. If it is not possible to retrieve the information or it would be too expensive to do so anUnsupportedOperationExceptionshould be thrown. Note that this method will return the names for items as stored in persistence. If aliases are used, the calling method is responsible for mapping back to the real item name.- Returns:
- a set of information about the persisted items
- Throws:
UnsupportedOperationException- if the operation is not supported or would be too expensive to perform
-
getItemInfo
default @Nullable PersistenceItemInfo getItemInfo(String itemName, @Nullable String alias) throws UnsupportedOperationException ReturnsPersistenceItemInfofor an item stored in the persistence service. Null can be returned when the item is not found in the persistence service. If it is not possible to retrieve the information or it would be too expensive to do so anUnsupportedOperationExceptionshould be thrown. The default implementation will query the persistence service for the last value in the persistence store and set the latest timestamp, leaving thePersistenceItemInfoearliest timestamp and count equal to null. Note that the method should return the alias for the item in its response if an alias is being used.- Parameters:
itemName- the real openHAB name as it appears in the item registryalias- for item name in database or null if no alias defined- Returns:
- information about the persisted item
- Throws:
UnsupportedOperationException- if the operation is not supported or would be too expensive to perform
-
persistedItem
Returns aPersistedItemrepresenting the persisted state, last update and change timestamps and previous persisted state. This can be used to restore the full state of an item. The default implementation only queries the service for the last persisted state and does not attempt to look further back to find the last change timestamp and previous persisted state. This avoids potential performance issues if this method is not overriden in the specific persistence service. Persistence services should override this default implementation with a more complete and efficient algorithm.- Parameters:
itemName- name of itemalias- alias of item- Returns:
- a
PersistedItemor null if the item has not been persisted
-