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.
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 {@value R}. 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 {@value R}. 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 {@value R}, 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 {@value T} 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¶
findTrashInstanceById¶
-
T
findTrashInstanceById
(Object instanceId, Object entityId)¶ Retrieves an instance, that has been moved to trash, by its id. These instances are not retrieved with other retrieve methods.
Parameters: - instanceId – id of the instance, that has been moved to trash
- entityId – id of the entity
Returns: instance of the given id, from trash
getClassType¶
getDetachedField¶
getVersionFieldName¶
retrieve¶
retrieveAll¶
retrieveAll¶
-
List<T>
retrieveAll
(QueryParams queryParams)¶ Retrieves all instances of the {@value T} type, that match the provided parameters.
Parameters: - queryParams – query parameters to be used retrieving instances
Returns: all isntances matching query parameters
revertFromTrash¶
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