T - class typepublic abstract class AbstractHibernateDAO<T> extends Object implements GenericDAO<T>
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHibernateDAO() |
| Modifier and Type | Method and Description |
|---|---|
int |
count(Context context,
javax.persistence.criteria.CriteriaQuery criteriaQuery,
javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
javax.persistence.criteria.Root<T> root)
This method will return the amount of results that would be generated for this CriteriaQuery as an integer
|
int |
count(javax.persistence.Query query)
This method will return the count of items for this query as an integer
This query needs to already be in a formate that'll return one record that contains the amount
|
long |
countLong(Context context,
javax.persistence.criteria.CriteriaQuery criteriaQuery,
javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
javax.persistence.criteria.Root<T> root)
This method will return the count of items for this query as a long
|
T |
create(Context context,
T t)
Create a new instance of this type in the database.
|
javax.persistence.Query |
createQuery(Context context,
String query)
Create a parsed query from a query expression.
|
void |
delete(Context context,
T t)
Remove an instance from the database.
|
List<T> |
executeCriteriaQuery(Context context,
javax.persistence.criteria.CriteriaQuery<T> criteriaQuery,
boolean cacheable,
int maxResults,
int offset)
This method will return a list of objects to be returned that match the given criteriaQuery and parameters.
|
List<T> |
findAll(Context context,
Class<T> clazz)
Fetch all persisted instances of a given object type.
|
T |
findByID(Context context,
Class clazz,
int id)
Fetch the entity identified by its legacy database identifier.
|
T |
findByID(Context context,
Class clazz,
UUID id)
Fetch the entity identified by its UUID primary key.
|
List<T> |
findByX(Context context,
Class clazz,
Map<String,Object> equals,
boolean cacheable,
int maxResults,
int offset)
This method can be used to construct a query for which there needs to be a bunch of equal properties
These properties can be passed along in the equals hashmap
|
List<T> |
findMany(Context context,
javax.persistence.Query query)
Execute a JPA Criteria query and return a collection of results.
|
List<T> |
findMany(Context context,
String query)
Execute a JPQL query and return a collection of results.
|
T |
findUnique(Context context,
String query)
Execute a JPQL query returning a unique result.
|
javax.persistence.criteria.CriteriaBuilder |
getCriteriaBuilder(Context context)
This method should always be used in order to retrieve a CriteriaBuilder for the given context
|
javax.persistence.criteria.CriteriaQuery<T> |
getCriteriaQuery(javax.persistence.criteria.CriteriaBuilder criteriaBuilder,
Class<T> clazz)
This method should always be used in order to retrieve the CriteriaQuery in order to
start creating a query that has to be executed
|
protected org.hibernate.Session |
getHibernateSession(Context context)
The Session used to manipulate entities of this type.
|
Iterator<T> |
iterate(javax.persistence.Query query)
This method will return an Iterator for the given Query
|
List<T> |
list(Context context,
javax.persistence.criteria.CriteriaQuery criteriaQuery,
boolean cacheable,
Class<T> clazz,
int maxResults,
int offset)
This method will return a list with unique results, no duplicates, made by the given CriteriaQuery and parameters
|
List<T> |
list(Context context,
javax.persistence.criteria.CriteriaQuery criteriaQuery,
boolean cacheable,
Class<T> clazz,
int maxResults,
int offset,
boolean distinct)
This method will return a list of results for the given CriteriaQuery and parameters
|
List<T> |
list(javax.persistence.Query query)
This method will be used to return a list of results for the given query
|
void |
save(Context context,
T t)
Persist this instance in the database.
|
T |
singleResult(Context context,
javax.persistence.criteria.CriteriaQuery criteriaQuery)
Retrieve a single result from the query.
|
T |
singleResult(javax.persistence.Query query)
This method will return the first result from the given query or null if no results were found
|
T |
uniqueResult(Context context,
javax.persistence.criteria.CriteriaQuery criteriaQuery,
boolean cacheable,
Class<T> clazz,
int maxResults,
int offset)
Retrieve a unique result from the query.
|
T |
uniqueResult(javax.persistence.Query query)
This method will return a singular result for the given query
|
public T create(Context context, T t) throws SQLException
GenericDAOcreate in interface GenericDAO<T>context - current DSpace context.t - type to be created.SQLExceptionpublic void save(Context context, T t) throws SQLException
GenericDAOsave in interface GenericDAO<T>context - current DSpace context.t - type created here.SQLException - passed through.protected org.hibernate.Session getHibernateSession(Context context) throws SQLException
context - current DSpace context.SQLExceptionpublic void delete(Context context, T t) throws SQLException
GenericDAOdelete in interface GenericDAO<T>context - current DSpace context.t - type of the instance to be removed.SQLException - passed through.public List<T> findAll(Context context, Class<T> clazz) throws SQLException
GenericDAOfindAll in interface GenericDAO<T>context - The relevant DSpace Context.clazz - the desired type.SQLException - if database errorpublic T findUnique(Context context, String query) throws SQLException
GenericDAOfindUnique in interface GenericDAO<T>context - The relevant DSpace Context.query - JPQL query stringSQLException - if database errorpublic T findByID(Context context, Class clazz, UUID id) throws SQLException
GenericDAOfindByID in interface GenericDAO<T>context - current DSpace context.clazz - class of entity to be found.id - primary key of the database record.SQLExceptionpublic T findByID(Context context, Class clazz, int id) throws SQLException
GenericDAOfindByID in interface GenericDAO<T>context - current DSpace context.clazz - class of entity to be found.id - legacy database record ID.SQLException - passed through.public List<T> findMany(Context context, String query) throws SQLException
GenericDAOfindMany in interface GenericDAO<T>context - The relevant DSpace Context.query - JPQL query stringSQLException - if database errorpublic List<T> findMany(Context context, javax.persistence.Query query) throws SQLException
context - The relevant DSpace Context.query - JPQL query stringSQLException - if database errorpublic javax.persistence.Query createQuery(Context context, String query) throws SQLException
context - current DSpace context.query - textual form of the query.SQLExceptionpublic List<T> list(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset) throws SQLException
context - The standard DSpace context objectcriteriaQuery - The CriteriaQuery for which this list will be retrievedcacheable - Whether or not this query should be cacheableclazz - The clazz for which this CriteriaQuery will be executed onmaxResults - The maxmimum amount of results that will be returned for this CriteriaQueryoffset - The offset to be used for the CriteriaQuerySQLExceptionpublic List<T> list(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset, boolean distinct) throws SQLException
context - The standard DSpace context objectcriteriaQuery - The CriteriaQuery to be used to find the list of resultscacheable - A boolean value indicating whether this query should be cached or notclazz - The class on which the CriteriaQuery will searchmaxResults - The maximum amount of results to be returnedoffset - The offset to be used for the CriteriaQuerydistinct - A boolean value indicating whether this list should be distinct or notSQLExceptionpublic List<T> list(javax.persistence.Query query)
query - The query for which the resulting list will be returnedpublic T uniqueResult(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset) throws SQLException
criteriaQuery - JPA criteriaSQLExceptionpublic T singleResult(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery) throws SQLException
criteriaQuery - JPA criteriaSQLExceptionpublic T singleResult(javax.persistence.Query query)
query - The query that is to be executedpublic T uniqueResult(javax.persistence.Query query)
query - The query for which a single result will be givenpublic Iterator<T> iterate(javax.persistence.Query query)
query - The query for which an Iterator will be madepublic int count(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.Root<T> root) throws SQLException
context - The standard DSpace Context objectcriteriaQuery - The CriteriaQuery for which this result will be retrievedcriteriaBuilder - The CriteriaBuilder that accompagnies the CriteriaQueryroot - The root that'll determine on which class object we need to calculate the resultSQLExceptionpublic int count(javax.persistence.Query query)
query - The query for which the amount of results will be returned.public long countLong(Context context, javax.persistence.criteria.CriteriaQuery criteriaQuery, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, javax.persistence.criteria.Root<T> root) throws SQLException
context - The standard DSpace Context objectcriteriaQuery - The CriteriaQuery for which the amount of results will be retrievedcriteriaBuilder - The CriteriaBuilder that goes along with this CriteriaQueryroot - The root created for a DSpace class on which this query will searchSQLExceptionpublic javax.persistence.criteria.CriteriaQuery<T> getCriteriaQuery(javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Class<T> clazz)
criteriaBuilder - The CriteriaBuilder for which this CriteriaQuery will be constructedclazz - The class that this CriteriaQuery will be constructed forpublic javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder(Context context) throws SQLException
context - The standard DSpace Context class for which a CriteriaBuilder will be madeSQLExceptionpublic List<T> executeCriteriaQuery(Context context, javax.persistence.criteria.CriteriaQuery<T> criteriaQuery, boolean cacheable, int maxResults, int offset) throws SQLException
context - The standard context DSpace objectcriteriaQuery - The CriteriaQuery that will be used for executing the querycacheable - Whether or not this query is able to be cachedmaxResults - The maximum amount of results that this query will return
This can be circumvented by passing along -1 as the valueoffset - The offset to be used in this query
This can be circumvented by passing along -1 as the valueSQLExceptionpublic List<T> findByX(Context context, Class clazz, Map<String,Object> equals, boolean cacheable, int maxResults, int offset) throws SQLException
context - The standard DSpace context objectclazz - The class on which the criteriaQuery will be builtequals - A hashmap that can be used to store the String representation of the column
and the value that should match that in the DBcacheable - A boolean indicating whether this query should be cacheable or notmaxResults - The max amount of results to be returned by this queryoffset - The offset to be used in this querySQLExceptionCopyright © 2019 DuraSpace. All rights reserved.