T - The type of the entity.PK - The type of the unique identifier for the entity.public class GenericDao<T,PK> extends Object implements Dao<T,PK>
Dao interface. It is a wrapper around
the EntityManager interface.| Modifier | Constructor and Description |
|---|---|
protected |
GenericDao(Class<T> inEntityClass,
javax.inject.Provider<javax.persistence.EntityManager> inManagerProvider)
Creates a generic DAO that handles the given type of entity.
|
| Modifier and Type | Method and Description |
|---|---|
T |
create(T entity)
Creates an entity in the database.
|
List<T> |
getAll()
Gets all of this DAO's entities.
|
protected DatabaseSupport |
getDatabaseSupport() |
protected Class<T> |
getEntityClass() |
protected javax.persistence.EntityManager |
getEntityManager()
Returns an entity manager that can be used to interact with the data
source.
|
protected List<T> |
getListAsc(javax.persistence.metamodel.SingularAttribute<T,?> attribute)
Gets all of this DAO's entities ordered by the provided attribute in
ascending order.
|
protected <Y> List<T> |
getListByAttribute(QueryPathProvider<T,Y> provider,
Y value)
Executes a query for all entities whose path value is the same as the
given target value.
|
protected <Y> List<T> |
getListByAttribute(javax.persistence.metamodel.SingularAttribute<T,Y> attribute,
Y value)
Gets the entities that have the target value of the specified attribute.
|
protected <Y> List<T> |
getListByAttributeIn(QueryPathProvider<T,Y> provider,
List<Y> values)
Executes a query for all entities whose path value is any of the target
values.
|
protected <Y> List<T> |
getListByAttributeIn(javax.persistence.metamodel.SingularAttribute<T,Y> attribute,
List<Y> values)
Gets the entities that have any of the target values of the specified
attribute.
|
protected <Y> T |
getUniqueByAttribute(javax.persistence.metamodel.SingularAttribute<T,Y> attribute,
Y value)
Gets the entity that has the target value of the specified attribute.
|
protected <Y> T |
getUniqueByAttribute(String attributeName,
Y value)
Gets the entity that has the target value of the specified attribute.
|
T |
refresh(T entity)
Synchronizes the given entity with what is currently in the database.
|
T |
remove(T entity)
Deletes an entity from the database.
|
T |
retrieve(PK uniqueId)
Selects an entity from the database.
|
T |
update(T entity)
Updates an entity in the database.
|
protected GenericDao(Class<T> inEntityClass, javax.inject.Provider<javax.persistence.EntityManager> inManagerProvider)
inEntityClass - The type of entities to handle.inManagerProvider - Provides entity managers on demand.public T create(T entity)
EntityManager.persist(java.lang.Object) and throws the same
exceptions.public final T retrieve(PK uniqueId)
EntityManager.find(java.lang.Class, java.lang.Object) and throws
the same exceptions.public T update(T entity)
EntityManager.merge(java.lang.Object) and throws the same
exceptions.public T remove(T entity)
EntityManager.remove(java.lang.Object) and throws the same
exceptions.public T refresh(T entity)
protected List<T> getListAsc(javax.persistence.metamodel.SingularAttribute<T,?> attribute)
attribute - the attribute to order by.null.protected <Y> T getUniqueByAttribute(javax.persistence.metamodel.SingularAttribute<T,Y> attribute, Y value)
Y - the type of the attribute and target value.attribute - the attribute of the entity to compare.value - the target value of the given attribute.null if there is none.protected <Y> T getUniqueByAttribute(String attributeName, Y value)
Y - the type of the attribute and target value.attributeName - the name of the attribute.value - the target value of the given attribute.null if there is none.protected <Y> List<T> getListByAttribute(javax.persistence.metamodel.SingularAttribute<T,Y> attribute, Y value)
Y - the type of the attribute and target value.attribute - the attribute of the entity to compare.value - the target value of the given attribute.null.protected <Y> List<T> getListByAttribute(QueryPathProvider<T,Y> provider, Y value)
QueryPathProvider
and is followed through to get the resulting value. That resulting value
is compared to the given target value in the query.Y - the type of the target value and resulting attribute/column
value.provider - provides the path from the entity to the target
attribute/column.value - the target value to compare with the resulting attribute
value.protected <Y> List<T> getListByAttributeIn(javax.persistence.metamodel.SingularAttribute<T,Y> attribute, List<Y> values)
Y - the type of the attribute and target value.attribute - the attribute of the entity to compare.values - the target values of the given attribute.null.protected <Y> List<T> getListByAttributeIn(QueryPathProvider<T,Y> provider, List<Y> values)
QueryPathProvider and is
followed through to get the resulting value. That resulting value is
compared to the given target values in the query.Y - the type of the target value and resulting attribute/column
value.provider - provides the path from the entity to the target
attribute/column.values - the target values of the given attribute.protected javax.persistence.EntityManager getEntityManager()
protected DatabaseSupport getDatabaseSupport()
Copyright © 2016–2018 Emory University. All rights reserved.