T - Your resource class to manage, usually an entity classID - Resource id type, usually Long or StringR - The repository class@Transactional(readOnly=true) public class CrudServiceImpl<T,ID extends Serializable,R extends org.springframework.data.repository.PagingAndSortingRepository<T,ID>> extends Object implements CrudService<T,ID>
PagingAndSortingRepository Spring Data repository implementation
You should extend it and inject your Repository bean by overriding setRepository(org.springframework.data.repository.PagingAndSortingRepository)| Modifier and Type | Field and Description |
|---|---|
protected R |
repository |
| Constructor and Description |
|---|
CrudServiceImpl() |
| Modifier and Type | Method and Description |
|---|---|
Long |
count()
Count all resources.
|
T |
create(T resource)
Create new resource.
|
void |
delete(ID id)
Delete existing resource.
|
void |
delete(T resource)
Delete existing resource.
|
void |
deleteAll()
Delete all existing resource.
|
void |
deleteAllWithCascade()
Delete all existing resource, including linked entities with cascade delete
|
Iterable<T> |
findAll()
Find all resources.
|
org.springframework.data.domain.Page<T> |
findAll(org.springframework.data.domain.Pageable pageRequest)
Find all resources (pageable).
|
T |
findById(ID id)
Find resource by id.
|
Iterable<T> |
findByIds(Set<ID> ids)
Find resources by their ids.
|
void |
setRepository(R repository) |
T |
update(T resource)
Update existing resource.
|
public void setRepository(R repository)
repository - the repository to set@Transactional public T create(T resource)
create in interface CrudService<T,ID extends Serializable>resource - Resource to create@Transactional public T update(T resource)
update in interface CrudService<T,ID extends Serializable>resource - Resource to update@Transactional public void delete(T resource)
delete in interface CrudService<T,ID extends Serializable>resource - Resource to delete@Transactional public void delete(ID id)
delete in interface CrudService<T,ID extends Serializable>id - Resource id@Transactional public void deleteAll()
deleteAll in interface CrudService<T,ID extends Serializable>@Transactional public void deleteAllWithCascade()
deleteAllWithCascade in interface CrudService<T,ID extends Serializable>public T findById(ID id)
findById in interface CrudService<T,ID extends Serializable>id - Resource idpublic Iterable<T> findByIds(Set<ID> ids)
findByIds in interface CrudService<T,ID extends Serializable>ids - Resource idspublic Iterable<T> findAll()
findAll in interface CrudService<T,ID extends Serializable>public org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageRequest)
findAll in interface CrudService<T,ID extends Serializable>pageRequest - page requestpublic Long count()
count in interface CrudService<T,ID extends Serializable>Copyright © 2009–2014. All rights reserved.