public class GenericServiceImpl<T,ID extends Serializable,DAO extends cz.datalite.dao.GenericDAO<T,ID>> extends Object implements GenericService<T,ID>
| Modifier and Type | Field and Description |
|---|---|
protected DAO |
defaultDAO |
protected static org.slf4j.Logger |
LOGGER |
| Constructor and Description |
|---|
GenericServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
T |
attachPersistenceContext(T entity)
Reattach the entity to the persistence context (without hitting the database).
|
Integer |
count(cz.datalite.dao.DLSearch<T> search)
Count all entities which accept criterias which is written in DLSearch.
|
void |
delete(T entity)
Delete the entity from database.
|
List<T> |
findAll()
Find all entities in this table
|
List<T> |
findByExample(T exampleInstance)
Find all entities like this example
|
List<T> |
findByExample(T exampleInstance,
String[] excludeProperty)
Find all entities like this example
|
T |
findById(ID id)
Find entity with optimistic lock type.
|
T |
findById(ID id,
boolean lock)
Find entity by Id using optimistic or pesimistic lock.
|
T |
get(ID id)
Find entity by Id.
|
T |
get(ID id,
String... path)
Find entity by Id.
|
T |
get(T entity)
Get entity by instance.
|
T |
get(T entity,
String... associationPath)
Get entity by instance.
|
void |
save(T entity)
Save or update the entity in database
|
List<T> |
search(cz.datalite.dao.DLSearch<T> search)
Find all entities which accept criterias which is written in DLSearch.
|
cz.datalite.dao.DLResponse<T> |
searchAndCount(cz.datalite.dao.DLSearch<T> search)
Returns a
DLResponse object that includes both the list of
results like search() and the total length like
count(). |
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
@Transactional(readOnly=true) public T get(ID id)
GenericServiceget in interface GenericService<T,ID extends Serializable>id - object identifier@Transactional(readOnly=true) public T get(ID id, String... path)
GenericServiceget in interface GenericService<T,ID extends Serializable>id - object identifierpath - eager load associated entities on associationPath@Transactional(readOnly=true) public T get(T entity)
GenericServiceThis is convenience method - same result would be get(entity.getId())
Typical usage is to referesh current state in new request -> entity = get(entity); The method is null safe - if null, than nothing is done and null returned.
get in interface GenericService<T,ID extends Serializable>entity - object identifier or null@Transactional(readOnly=true) public T get(T entity, String... associationPath)
GenericServiceThis is convenience method - same result would be get(entity.getId())
Typical usage is to referesh current state in new request -> entity = get(entity); The method is null safe - if null, than nothing is done and null returned.
get in interface GenericService<T,ID extends Serializable>entity - object identifier or nullassociationPath - eager load associated entities on associationPath@Transactional(readOnly=true) public T findById(ID id, boolean lock)
GenericServicefindById in interface GenericService<T,ID extends Serializable>id - entity identifirlock - use pesimistic lock@Transactional(readOnly=true) public T findById(ID id)
GenericServicefindById in interface GenericService<T,ID extends Serializable>id - entity identifier@Transactional(readOnly=true) public List<T> findAll()
GenericServicefindAll in interface GenericService<T,ID extends Serializable>@Transactional(readOnly=true) public List<T> findByExample(T exampleInstance)
GenericServicefindByExample in interface GenericService<T,ID extends Serializable>exampleInstance - example entity@Transactional(readOnly=true) public List<T> findByExample(T exampleInstance, String[] excludeProperty)
GenericServicefindByExample in interface GenericService<T,ID extends Serializable>exampleInstance - example entityexcludeProperty - properties to exclude@Transactional(readOnly=true) public List<T> search(cz.datalite.dao.DLSearch<T> search)
GenericServicesearch in interface GenericService<T,ID extends Serializable>search - object with search parameters@Transactional(readOnly=true) public Integer count(cz.datalite.dao.DLSearch<T> search)
GenericServicecount in interface GenericService<T,ID extends Serializable>search - search object witch search parameters@Transactional(readOnly=true) public cz.datalite.dao.DLResponse<T> searchAndCount(cz.datalite.dao.DLSearch<T> search)
GenericServiceDLResponse object that includes both the list of
results like search() and the total length like
count().searchAndCount in interface GenericService<T,ID extends Serializable>search - search parameters@Transactional public void save(T entity)
GenericServicesave in interface GenericService<T,ID extends Serializable>entity - entity to store@Transactional public void delete(T entity)
GenericServicedelete in interface GenericService<T,ID extends Serializable>entity - entity to delete.@Transactional(readOnly=true) public T attachPersistenceContext(T entity)
GenericServiceReattach the entity to the persistence context (without hitting the database).
Typical use is when you have entity instance from an old request (hence dettached) and you want it to allow lazy load subseqent entities. Without reattach you will get LazyInitializationException: could not initialize proxy - no Session.
If the another entity with the same ID is already in the persistence context, this method uses merge (and the new entity is returned). Otherwise this entity is only attached, no query executed.
attachPersistenceContext in interface GenericService<T,ID extends Serializable>entity - entity to reattach.Copyright © 2017 DataLite. All rights reserved.