DefaultMotechDataService

public abstract class DefaultMotechDataService<T> implements MotechDataService<T>

This is a basic implementation of org.motechproject.mds.service.MotechDataService. Mainly it is used as super class to create a service related with the given entity schema in org.motechproject.mds.builder.EntityInfrastructureBuilder but it can be also used by other services inside this package.

Parameters:
  • <T> – the type of entity schema.

Methods

copyValuesFromRecord

protected void copyValuesFromRecord(T target, Object record)

count

public long count()

count

protected long count(List<Property> properties)

countForFilters

public long countForFilters(Filters filters)

create

public T create(T object)

createOrUpdate

public T createOrUpdate(T object)

debug

protected void debug(String msg, Object... args)

delete

public void delete(T object)

delete

public void delete(String primaryKeyName, Object value)

deleteAll

public void deleteAll()

deleteById

public void deleteById(long id)

detachedCopy

public T detachedCopy(T object)

detachedCopyAll

public List<T> detachedCopyAll(List<T> objects)

doInTransaction

public <R> R doInTransaction(TransactionCallback<R> transactionCallback)

evictAllCache

public void evictAllCache()

evictCacheForInstance

public void evictCacheForInstance(T instance)

evictEntityCache

public void evictEntityCache(boolean withSubclasses)

executeQuery

public <R> R executeQuery(QueryExecution<R> queryExecution)

executeSQLQuery

public <R> R executeSQLQuery(SqlQueryExecution<R> queryExecution)

filter

public List<T> filter(Filters filters, QueryParams queryParams)

findById

public T findById(Long id)

findByIds

public List<T> findByIds(Collection<Long> ids)

findTrashInstanceById

public Object findTrashInstanceById(Long trashId)

getClassType

public Class<T> getClassType()

getDetachedField

public Object getDetachedField(T instance, String fieldName)

getId

protected Object getId(T instance)

getLogger

protected Logger getLogger()

getRepository

protected MotechDataRepository<T> getRepository()

getSchemaVersion

public Long getSchemaVersion()

getVersionFieldName

public String getVersionFieldName()

init

public void init()

recordHistory

public boolean recordHistory()

retrieve

public T retrieve(String primaryKeyName, Object value)

retrieveAll

public List<T> retrieveAll()

retrieveAll

public List<T> retrieveAll(QueryParams queryParams)

retrieveAll

protected List<T> retrieveAll(List<Property> properties)

retrieveAll

protected List<T> retrieveAll(List<Property> properties, QueryParams queryParams)

revertFromTrash

public T revertFromTrash(Long trashId)

revertToHistoricalRevision

public T revertToHistoricalRevision(Long instanceId, Long historicalId)

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)

setEntityInfoReader

public void setEntityInfoReader(EntityInfoReader entityInfoReader)

setHistoryService

public void setHistoryService(HistoryService historyService)

setOsgiEventProxy

public void setOsgiEventProxy(OsgiEventProxy osgiEventProxy)

setRepository

public void setRepository(MotechDataRepository<T> repository)

setTransactionManager

public void setTransactionManager(JdoTransactionManager transactionManager)

setTrashService

public void setTrashService(TrashService trashService)

update

public T update(T object)

updateFromTransient

public T updateFromTransient(T transientObject)

updateFromTransient

public T updateFromTransient(T transientObject, Set<String> fieldsToUpdate)

validateCredentials

protected InstanceSecurityRestriction validateCredentials()

validateCredentials

protected InstanceSecurityRestriction validateCredentials(T instance)

verifySchemaVersion

protected void verifySchemaVersion(Object record, Long recordId, boolean forTrash)