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.ContentType
APPLICATION_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 void
create(T entity)
Create a new entity.void
delete(T entity)
Delete an entity.T
find(long id)
Find the entity with the given Long id.T
find(Entity<?> parent)
Find the entity related to the given parent, like the Thing for a Datastream.T
find(Id id)
Find an entity.T
find(Id id, Expansion expansion)
Find an entity including referenced entities from expansion.T
find(String id)
Find the entity with the given String id.T
find(URI uri)
Find an entity.protected String
getMqttTopic()
protected String
getMqttTopic(Entity entity)
protected String
getMqttTopic(List<EntityProperty> properties)
protected SensorThingsService
getService()
void
patch(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)
MqttSubscription
subscribe(Entity entity, Consumer<T> handler)
MqttSubscription
subscribe(Consumer<T> handler)
Starts an MQTT subscription.MqttSubscription
subscribe(Consumer<T> handler, EntityProperty... properties)
Starts an MQTT subscription.MqttSubscription
subscribe(Predicate<T> filter, Consumer<T> handler)
Starts an MQTT subscription.MqttSubscription
subscribe(Predicate<T> filter, Consumer<T> handler, EntityProperty... properties)
Starts an MQTT subscription.void
unsubscribe()
Stops all MQTT subscriptions.void
unsubscribe(MqttSubscription subscription)
Stops an MQTT subscription.void
update(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:Dao
Create a new entity.
-
find
public T find(Entity<?> parent) throws ServiceFailureException
Description copied from interface:Dao
Find 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:Dao
Find 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:Dao
Find an entity.
-
find
public T find(Id id, Expansion expansion) throws ServiceFailureException
Description copied from interface:Dao
Find an entity including referenced entities from expansion.
-
update
public void update(T entity) throws ServiceFailureException
Description copied from interface:Dao
Update an entity.
-
patch
public void patch(T entity, List<com.github.fge.jsonpatch.JsonPatchOperation> patch) throws ServiceFailureException
Description copied from interface:Dao
Update 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:Dao
Delete an entity.
-
query
public Query<T> query()
Description copied from interface:Dao
Start a query to find an entity collection.
-
getService
protected SensorThingsService getService()
-
subscribe
public MqttSubscription subscribe(Consumer<T> handler) throws MqttException
Description copied from interface:Dao
Starts an MQTT subscription.
-
subscribe
public MqttSubscription subscribe(Predicate<T> filter, Consumer<T> handler) throws MqttException
Description copied from interface:Dao
Starts an MQTT subscription.- Specified by:
subscribe
in 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:Dao
Starts an MQTT subscription.- Specified by:
subscribe
in 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:Dao
Starts an MQTT subscription.- Specified by:
subscribe
in 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:Dao
Stops an MQTT subscription.- Specified by:
unsubscribe
in interfaceDao<T extends Entity<T>>
- Parameters:
subscription
- contains information on subscription- Throws:
MqttException
- when unsubscribing failed
-
unsubscribe
public void unsubscribe() throws MqttException
Description copied from interface:Dao
Stops all MQTT subscriptions.- Specified by:
unsubscribe
in interfaceDao<T extends Entity<T>>
- Throws:
MqttException
- when unsubscribing failed
-
-