T
- Type of entityID
- Type of primary key of entitypublic class StandardJpaDao<T extends JpaEntity<ID>,ID> extends java.lang.Object implements GenericDao<T,ID>
Constructor and Description |
---|
StandardJpaDao(java.lang.Class<T> type) |
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 limit,
java.lang.Integer start)
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
|
public StandardJpaDao(java.lang.Class<T> type)
public void add(T transientObject)
public ID mergeAndReturnID(T transientObject)
mergeAndReturnID
in interface GenericDao<T extends JpaEntity<ID>,ID>
transientObject
- The object to be added/updatedpublic T find(ID id) throws javax.persistence.EntityNotFoundException
public java.util.List<T> findAll()
public void remove(T persistentObject) throws javax.persistence.EntityNotFoundException
public java.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.
query
in interface GenericDao<T extends JpaEntity<ID>,ID>
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.public 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.
query
in interface GenericDao<T extends JpaEntity<ID>,ID>
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 returnpublic java.util.List<T> query(java.lang.String queryString, java.util.Map<java.lang.String,java.lang.Object> queryParameters, java.lang.Integer limit, java.lang.Integer start)
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.
query
in interface GenericDao<T extends JpaEntity<ID>,ID>
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 index of the record which we want to be the first returned based on the sort in the queryStringstart
- the maximum number of elements to returnpublic void batchMerge(java.util.List<T> listToMerge)
batchMerge
in interface GenericDao<T extends JpaEntity<ID>,ID>
listToMerge
- the list of elements to mergepublic void setEntityManager(javax.persistence.EntityManager entityManager)
setEntityManager
in interface GenericDao<T extends JpaEntity<ID>,ID>
entityManager
- the entityManager to set