T - the generic type of the domain entityPK - the generic type of the primary key from the domain entitypublic abstract class AbstractRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable> extends Object implements GenericRepository<T,PK>
AbstractRepository provides methods for database operations like
insert, delete, update and selections. The create, update and delete processes can be overwritten
by providing strategies for them. By default the strategies are null and the default behavior of
the process will be taken.| Constructor and Description |
|---|
AbstractRepository() |
| Modifier and Type | Method and Description |
|---|---|
void |
create(T entity)
Persists the given entity.
|
javax.persistence.TypedQuery<T> |
createNamedQuery(String name,
Class<T> resultClass)
Factory method for create a new
TypedQuery from the given name and the given type. |
javax.persistence.TypedQuery<T> |
createNamedTypedQuery(String name)
Factory method for create a new
TypedQuery from the given name and the type of the
generic entity. |
void |
delete(List<T> entities)
Delete all persistent entities in the given list.
|
void |
delete(PK id)
Deletes an entity of a given Id.
|
void |
delete(T entity)
Deletes the given entity from persistent storage in the database.
|
void |
evict(T entity)
Remove this instance from the session cache.
|
boolean |
exists(PK id)
Checks if an entry exists with the given id.
|
List<T> |
findAll()
Returns a list of all persistent entities.
|
T |
get(PK id)
Retrieve a persisted entity with a given id from the database.
|
javax.persistence.Query |
getQuery(String hqlQuery)
Gets a
Query from the given hql query. |
T |
load(PK id)
Retrieve a persisted entity with a given id from the database.
|
List<T> |
merge(List<T> entities)
Merges all new entities in the given list.
|
T |
merge(T entity)
Merges the given entity.
|
DeleteStrategy<T,PK> |
newDeleteStrategy()
Factory method for creating a new
DeleteStrategy for interact on deletion process. |
MergeStrategy<T,PK> |
newMergeStrategy()
Factory method for creating a new
MergeStrategy for interact on merge process. |
SaveOrUpdateStrategy<T,PK> |
newSaveOrUpdateStrategy()
Factory method for creating a new
SaveOrUpdateStrategy for interact on save or update
process. |
void |
refresh(T entity)
Re-read the state of the given instance from the underlying database.
|
List<PK> |
save(List<T> entities)
Save all new entities in the given list.
|
PK |
save(T entity)
Persist the given entity into database.
|
void |
saveOrUpdate(List<T> entities)
Save or update all transient entities in the given list.
|
void |
saveOrUpdate(T entity)
Save or update the given persistent entity.
|
void |
update(List<T> entities)
Update all transient entities in the given list.
|
void |
update(T entity)
Update changes made to the given entity.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetEntityManager, getType, setEntityManagerpublic void create(T entity)
create in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the entitypublic javax.persistence.TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
TypedQuery from the given name and the given type.createNamedQuery in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>name - the nameresultClass - the result classTypedQuerypublic javax.persistence.TypedQuery<T> createNamedTypedQuery(String name)
TypedQuery from the given name and the type of the
generic entity.createNamedTypedQuery in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>name - the nameTypedQuerypublic void delete(List<T> entities)
delete in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entities - the list with the persistent entities to deletepublic void delete(PK id)
delete in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>id - the idpublic void delete(T entity)
delete in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the persistent entitypublic void evict(T entity)
evict in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the entity to evict.public boolean exists(PK id)
exists in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>id - the id to checkpublic List<T> findAll()
findAll in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>public T get(PK id)
get in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>id - the idpublic javax.persistence.Query getQuery(String hqlQuery)
Query from the given hql query.getQuery in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>hqlQuery - the hql queryQuerypublic T load(PK id)
load in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>id - the idpublic List<T> merge(List<T> entities)
merge in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entities - the list to savepublic T merge(T entity)
merge in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the entitypublic DeleteStrategy<T,PK> newDeleteStrategy()
DeleteStrategy for interact on deletion process.
This method can be overridden so users can provide their own version of a new
DeleteStrategy for the deletion process.DeleteStrategy for the deletion process.public MergeStrategy<T,PK> newMergeStrategy()
MergeStrategy for interact on merge process. This
method can be overridden so users can provide their own version of a new
MergeStrategy for the merge process.MergeStrategy for the merge process.public SaveOrUpdateStrategy<T,PK> newSaveOrUpdateStrategy()
SaveOrUpdateStrategy for interact on save or update
process. This method can be overridden so users can provide their own version of a new
SaveOrUpdateStrategy for the save or update process.SaveOrUpdateStrategy for the save or update process.public void refresh(T entity)
GenericRepositoryrefresh in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the entity to re-read.public List<PK> save(List<T> entities)
save in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entities - the list to savepublic PK save(T entity)
save in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the new instance to save.public void saveOrUpdate(List<T> entities)
saveOrUpdate in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entities - the transient entitiespublic void saveOrUpdate(T entity)
saveOrUpdate in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the transient entity to save or update.public void update(List<T> entities)
update in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entities - the transient entities to update.public void update(T entity)
update in interface GenericRepository<T extends de.alpharogroup.db.entity.BaseEntity<PK>,PK extends Serializable>entity - the transient entity to update.Copyright © 2015–2018 Alpha Ro Group UG (haftungsbeschrÀngt). All rights reserved.