public interface GenericService<T,ID extends Serializable>
| 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(). |
T get(ID id)
id - object identifierT get(ID id, String... path)
id - object identifierpath - eager load associated entities on associationPathT get(T entity)
This 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.
entity - object identifier or nullT get(T entity, String... associationPath)
This 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.
entity - object identifier or nullassociationPath - eager load associated entities on associationPathT findById(ID id, boolean lock)
id - entity identifirlock - use pesimistic lockT findById(ID id)
id - entity identifierList<T> findByExample(T exampleInstance)
exampleInstance - example entityList<T> findByExample(T exampleInstance, String[] excludeProperty)
exampleInstance - example entityexcludeProperty - properties to excludeList<T> search(cz.datalite.dao.DLSearch<T> search)
search - object with search parametersInteger count(cz.datalite.dao.DLSearch<T> search)
search - search object witch search parameterscz.datalite.dao.DLResponse<T> searchAndCount(cz.datalite.dao.DLSearch<T> search)
DLResponse object that includes both the list of
results like search() and the total length like
count().search - search parametersvoid save(T entity)
entity - entity to storevoid delete(T entity)
entity - entity to delete.T attachPersistenceContext(T entity)
Reattach 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.
entity - entity to reattach.Copyright © 2017 DataLite. All rights reserved.