MotechDataService¶
-
public interface
MotechDataService
<T>¶ This is a basic service interface with CRUD operations. Mainly it is used as super interface to create service interface related with the given entity schema in
org.motechproject.mds.builder.EntityInfrastructureBuilder
but it can be also used by other service interfaces inside this package.Parameters: - <T> – the type of entity schema.
Methods¶
countForFilters¶
create¶
-
T
create
(T object)¶ Creates the given instance in MDS.
Parameters: - object – instance to create
Returns: created instance
createOrUpdate¶
-
T
createOrUpdate
(T object)¶ Updates the given instance in MDS if it exists (checks the presence of the instances id to verify that) or creates a new one if it doesn’t.
Parameters: - object – instance to update or create
Returns: updated or created instance
delete¶
-
void
delete
(T object)¶ Deletes given instance from MDS.
Parameters: - object – instance to delete
delete¶
deleteById¶
-
void
deleteById
(long id)¶ Deletes instance from MDS, by its id.
Parameters: - id – id of the instance to delete.
detachedCopy¶
-
T
detachedCopy
(T object)¶ Returns detached copy of the given object
Parameters: - object – the object to be detached
Returns: the detached copy of the given object
detachedCopyAll¶
doInTransaction¶
-
<R> R
doInTransaction
(TransactionCallback<R> transactionCallback)¶ Allows to wrap several instructions into a single transaction. Developers should implement the
TransactionCallback
interface and override theTransactionCallback.doInTransaction(org.springframework.transaction.TransactionStatus)
method with whatever should be done in the transaction.Parameters: - transactionCallback – implementation of the
TransactionCallback
- <R> – type that should be returned from the transaction
Returns: anything of type {@param }. Left to the developer, implementing the transaction
- transactionCallback – implementation of the
evictCacheForInstance¶
-
void
evictCacheForInstance
(T instance)¶ Evicts cache for a single entity instance.
Parameters: - instance – the instance to clear the cache for
evictEntityCache¶
-
void
evictEntityCache
(boolean withSubclasses)¶ Evicts cache for the entity class of this data service.
Parameters: - withSubclasses – if true, the cache for subclasses of the entity will be also cleared
executeQuery¶
-
<R> R
executeQuery
(QueryExecution<R> queryExecution)¶ Allows to execute custom query in MDS. Users are supposed to implement the
QueryExecution
interface and override itsQueryExecution.execute(javax.jdo.Query,org.motechproject.mds.util.InstanceSecurityRestriction)
method with their custom behaviour.Parameters: - queryExecution – implementation of the
QueryExecution
, with custom behaviour - <R> – type that should be returned from the custom query
Returns: anything of type {@param }. Left to the developer, implementing the custom query.
- queryExecution – implementation of the
executeSQLQuery¶
-
<R> R
executeSQLQuery
(SqlQueryExecution<R> queryExecution)¶ Allows to execute custom SQL query in MDS. Users should implement the
SqlQueryExecution
interface and override its methods, defining their custom query.Parameters: - queryExecution – implementation of the
SqlQueryExecution
- <R> – type that should be returned by the custom sql query
Returns: anything of type {@param }, left to the developer, implementing the custom sql query.
- queryExecution – implementation of the
filter¶
-
List<T>
filter
(Filters filters, QueryParams queryParams)¶ Retrieves all instances of type {@param } from MDS, filtered using specified filters and query params.
Parameters: - filters – filters to use filtering instances
- queryParams – query parameters to use filtering instances
Returns: a list of instances, filtered using specified parameters
findById¶
findByIds¶
-
List<T>
findByIds
(Collection<Long> ids)¶ Retrieves multiple instances of type {@param } and given ids from MDS. It will not fail if it is unable to find an instance for one or more IDs and will return a collection of these instances that could be found. If null is passed as keys, it will return an empty list.
Parameters: - ids – a collection of ids to find
Returns: a collection of instances with the given ids
findTrashInstanceById¶
getClassType¶
getDetachedField¶
getSchemaVersion¶
getVersionFieldName¶
recordHistory¶
-
boolean
recordHistory
()¶ Checks whether the entity for this service has history recording enabled.
Returns: true if the entity has history recording enabled, false otherwise
retrieve¶
retrieveAll¶
retrieveAll¶
-
List<T>
retrieveAll
(QueryParams queryParams)¶ Retrieves all instances of the {@param } type, that match the provided parameters.
Parameters: - queryParams – query parameters to be used retrieving instances
Returns: all isntances matching query parameters
revertFromTrash¶
-
T
revertFromTrash
(Long trashId)¶ Brings an instance back from trash.
Parameters: - trashId – the id of the trash instance
Throws: - TrashInstanceNotFoundException – if the trash instance with the given id was not found
Returns: the brought back instance
revertToHistoricalRevision¶
-
T
revertToHistoricalRevision
(Long instanceId, Long historicalId)¶ Reverts data from a historical revision of the given instance.
Parameters: - instanceId – the id of the instance which will be reverted
- historicalId – the id of the historical revision that we are reverting to
Throws: - org.motechproject.mds.exception.object.ObjectNotFoundException – if entity with instanceId was not found
- HistoryInstanceNotFoundException – if the historical instance with historicalId was not found
Returns: the reverted instance
update¶
-
T
update
(T object)¶ Updates the given instance in MDS.
Parameters: - object – instance to update
Returns: updated instance
updateFromTransient¶
-
T
updateFromTransient
(T transientObject)¶ Returns the persistent instance, updated with the values from the transient instance. If there’s no instance of the id from the transient instance, it will create one.
Parameters: - transientObject – transient object, from which an update will take place
Returns: persistent instance, updated with the values from the transient instance
updateFromTransient¶
-
T
updateFromTransient
(T transientObject, Set<String> fieldsToUpdate)¶ Returns the persistent instance, updated with the values from the transient instance. If there’s no instance of the id from the transient instance, it will create one. Only fields with the names passed to the method will be updated.
Parameters: - transientObject – transient object, from which an update will take place
- fieldsToUpdate – set of field names that should be updated
Returns: persistent instance, updated with the values from the transient instance