T
- the entity typeID
- the primary key of entitypublic interface GenericDao<T,ID>
Modifier and Type | Method and Description |
---|---|
void |
add(T transientObject)
Adds an object of type T.
|
void |
batchMerge(java.util.List<T> listToMerge)
Handles batch insert or batch update.
|
T |
find(ID id)
Get a T record using it's id
|
java.util.List<T> |
findAll()
Gets a List
|
T |
merge(T transientObject)
Adds or updates an object of type T
|
ID |
mergeAndReturnID(T transientObject)
Adds or updates an object of type T and returns the ID
|
java.util.List<T> |
query(java.lang.String queryString,
java.util.Map<java.lang.String,java.lang.Object> queryParameters)
Query using the passed in query, with named parameters contained in the queryParameters.
|
java.util.List<T> |
query(java.lang.String queryString,
java.util.Map<java.lang.String,java.lang.Object> queryParameters,
java.lang.Integer limit)
Query using the passed in query, with named parameters contained in the queryParameters.
|
java.util.List<T> |
query(java.lang.String queryString,
java.util.Map<java.lang.String,java.lang.Object> queryParameters,
java.lang.Integer start,
java.lang.Integer limit)
Query using the passed in query, with named parameters contained in the queryParameters.
|
void |
remove(T persistentObject)
Deletes entity T from table.
|
void |
setEntityManager(javax.persistence.EntityManager entityManager)
Added for testing
|
void add(T transientObject)
transientObject
- The object to be addedT merge(T transientObject)
transientObject
- The object to be added/updatedID mergeAndReturnID(T transientObject)
transientObject
- The object to be added/updatedT find(ID id) throws javax.persistence.EntityNotFoundException
id
- the primary key of the entityjavax.persistence.EntityNotFoundException
- when no entity with unique identifier ID existsjava.util.List<T> findAll()
void remove(T persistentObject) throws javax.persistence.EntityNotFoundException
persistentObject
- Entity to deletejavax.persistence.EntityNotFoundException
- if the instance is not an entity or is a detached entityjava.util.List<T> query(java.lang.String queryString, java.util.Map<java.lang.String,java.lang.Object> queryParameters)
Do not concatenate the queryString with parameters before passing it in to this method! We should be using named parameters via the queryParamters to avoid SQL-injection attacks.
queryString
- The query to execute, with named parameters if neededqueryParameters
- The parameters that will be used for the query. If null then query executes without params.java.util.List<T> query(java.lang.String queryString, java.util.Map<java.lang.String,java.lang.Object> queryParameters, java.lang.Integer limit)
Do not concatenate the queryString with parameters before passing it in to this method! We should be using named parameters via the queryParamters to avoid SQL-injection attacks.
queryString
- The query to execute, with named parameters if neededqueryParameters
- The parameters that will be used for the query. If null then query executes without params.limit
- the maximum number of elements to returnjava.util.List<T> query(java.lang.String queryString, java.util.Map<java.lang.String,java.lang.Object> queryParameters, java.lang.Integer start, java.lang.Integer limit)
Do not concatenate the queryString with parameters before passing it in to this method! We should be using named parameters via the queryParamters to avoid SQL-injection attacks.
queryString
- The query to execute, with named parameters if neededqueryParameters
- The parameters that will be used for the query. If null then query executes without params.start
- the index of the record which we want to be the first returned based on the sort in the queryStringlimit
- the maximum number of elements to returnvoid batchMerge(java.util.List<T> listToMerge)
listToMerge
- the list of elements to mergevoid setEntityManager(javax.persistence.EntityManager entityManager)
entityManager
- the entityManager to set