Package de.fraunhofer.iosb.ilt.sta.dao
Class BaseDao<T extends Entity<T>>
- java.lang.Object
-
- de.fraunhofer.iosb.ilt.sta.dao.BaseDao<T>
-
- Type Parameters:
T- the entity's type
- All Implemented Interfaces:
Dao<T>
- Direct Known Subclasses:
ActuatorDao,DatastreamDao,FeatureOfInterestDao,HistoricalLocationDao,LocationDao,MultiDatastreamDao,ObservationDao,ObservedPropertyDao,SensorDao,TaskDao,TaskingCapabilityDao,ThingDao
public abstract class BaseDao<T extends Entity<T>> extends Object implements Dao<T>
The entity independent implementation of a data access object. Specific entity Daos can be implemented by inheriting from this class and supplying three arguments in the constructor.- Author:
- Nils Sommer, Hylke van der Schaaf, Michael Jacoby
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.http.entity.ContentTypeAPPLICATION_JSON_PATCH
-
Constructor Summary
Constructors Constructor Description BaseDao(SensorThingsService service, Class<T> entityClass)Constructor.BaseDao(SensorThingsService service, Class<T> entityClass, Entity<?> parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreate(T entity)Create a new entity.voiddelete(T entity)Delete an entity.Tfind(long id)Find the entity with the given Long id.Tfind(Entity<?> parent)Find the entity related to the given parent, like the Thing for a Datastream.Tfind(Id id)Find an entity.Tfind(Id id, Expansion expansion)Find an entity including referenced entities from expansion.Tfind(String id)Find the entity with the given String id.Tfind(URI uri)Find an entity.protected StringgetMqttTopic()protected StringgetMqttTopic(Entity entity)protected StringgetMqttTopic(List<EntityProperty> properties)protected SensorThingsServicegetService()voidpatch(T entity, List<com.github.fge.jsonpatch.JsonPatchOperation> patch)Update the given entity with the given patch.Query<T>query()Start a query to find an entity collection.BaseDao<T>setParent(Entity<?> parent)MqttSubscriptionsubscribe(Entity entity, Consumer<T> handler)MqttSubscriptionsubscribe(Consumer<T> handler)Starts an MQTT subscription.MqttSubscriptionsubscribe(Consumer<T> handler, EntityProperty... properties)Starts an MQTT subscription.MqttSubscriptionsubscribe(Predicate<T> filter, Consumer<T> handler)Starts an MQTT subscription.MqttSubscriptionsubscribe(Predicate<T> filter, Consumer<T> handler, EntityProperty... properties)Starts an MQTT subscription.voidunsubscribe()Stops all MQTT subscriptions.voidunsubscribe(MqttSubscription subscription)Stops an MQTT subscription.voidupdate(T entity)Update an entity.
-
-
-
Constructor Detail
-
BaseDao
public BaseDao(SensorThingsService service, Class<T> entityClass)
Constructor.- Parameters:
service- the service to operate onentityClass- the class of the entity's type
-
BaseDao
public BaseDao(SensorThingsService service, Class<T> entityClass, Entity<?> parent)
-
-
Method Detail
-
create
public void create(T entity) throws ServiceFailureException
Description copied from interface:DaoCreate a new entity.
-
find
public T find(Entity<?> parent) throws ServiceFailureException
Description copied from interface:DaoFind the entity related to the given parent, like the Thing for a Datastream.
-
find
public T find(Id id) throws ServiceFailureException
Description copied from interface:DaoFind an entity.
-
find
public T find(long id) throws ServiceFailureException
Find the entity with the given Long id. This is a shorthand for find(new IdLong(id));- Parameters:
id- the entity's unique id- Returns:
- the entity
- Throws:
ServiceFailureException- the operation failed
-
find
public T find(String id) throws ServiceFailureException
Find the entity with the given String id. This is a shorthand for find(new IdLong(id));- Parameters:
id- the entity's unique id- Returns:
- the entity
- Throws:
ServiceFailureException- the operation failed
-
find
public T find(URI uri) throws ServiceFailureException
Description copied from interface:DaoFind an entity.
-
find
public T find(Id id, Expansion expansion) throws ServiceFailureException
Description copied from interface:DaoFind an entity including referenced entities from expansion.
-
update
public void update(T entity) throws ServiceFailureException
Description copied from interface:DaoUpdate an entity.
-
patch
public void patch(T entity, List<com.github.fge.jsonpatch.JsonPatchOperation> patch) throws ServiceFailureException
Description copied from interface:DaoUpdate the given entity with the given patch. Does not update the entity object itself. To see the result, fetch it anew from the server.
-
delete
public void delete(T entity) throws ServiceFailureException
Description copied from interface:DaoDelete an entity.
-
query
public Query<T> query()
Description copied from interface:DaoStart a query to find an entity collection.
-
getService
protected SensorThingsService getService()
-
subscribe
public MqttSubscription subscribe(Consumer<T> handler) throws MqttException
Description copied from interface:DaoStarts an MQTT subscription.
-
subscribe
public MqttSubscription subscribe(Predicate<T> filter, Consumer<T> handler) throws MqttException
Description copied from interface:DaoStarts an MQTT subscription.- Specified by:
subscribein interfaceDao<T extends Entity<T>>- Parameters:
filter- predicate to further filter returned entitieshandler- a handler that is called upon received messages- Returns:
- object containing information about new MQTT subscription
- Throws:
MqttException- when subscription failed
-
subscribe
public MqttSubscription subscribe(Predicate<T> filter, Consumer<T> handler, EntityProperty... properties) throws MqttException
Description copied from interface:DaoStarts an MQTT subscription.- Specified by:
subscribein interfaceDao<T extends Entity<T>>- Parameters:
filter- predicate to further filter returned entitieshandler- a handler that is called upon received messagesproperties- properties to select, must be presten for entity type T- Returns:
- object containing information about new MQTT subscription
- Throws:
MqttException- when subscription failed
-
subscribe
public MqttSubscription subscribe(Consumer<T> handler, EntityProperty... properties) throws MqttException
Description copied from interface:DaoStarts an MQTT subscription.- Specified by:
subscribein interfaceDao<T extends Entity<T>>- Parameters:
handler- a handler that is called upon received messagesproperties- properties to select, must be presten for entity type T- Returns:
- object containing information about new MQTT subscription
- Throws:
MqttException- when subscription failed
-
subscribe
public MqttSubscription subscribe(Entity entity, Consumer<T> handler) throws MqttException
- Throws:
MqttException
-
getMqttTopic
protected String getMqttTopic()
-
getMqttTopic
protected String getMqttTopic(Entity entity) throws MqttException
- Throws:
MqttException
-
getMqttTopic
protected String getMqttTopic(List<EntityProperty> properties) throws MqttException
- Throws:
MqttException
-
unsubscribe
public void unsubscribe(MqttSubscription subscription) throws MqttException
Description copied from interface:DaoStops an MQTT subscription.- Specified by:
unsubscribein interfaceDao<T extends Entity<T>>- Parameters:
subscription- contains information on subscription- Throws:
MqttException- when unsubscribing failed
-
unsubscribe
public void unsubscribe() throws MqttExceptionDescription copied from interface:DaoStops all MQTT subscriptions.- Specified by:
unsubscribein interfaceDao<T extends Entity<T>>- Throws:
MqttException- when unsubscribing failed
-
-