Spring Data Jpa

org.springframework.data.jpa.repository.support
Class SimpleJpaRepository<T,ID extends Serializable>

java.lang.Object
  extended by org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,ID>
Type Parameters:
T - the type of the entity to handle
ID - the type of the entity's identifier
All Implemented Interfaces:
JpaRepository<T,ID>, JpaSpecificationExecutor<T>, org.springframework.data.repository.PagingAndSortingRepository<T,ID>, org.springframework.data.repository.Repository<T,ID>
Direct Known Subclasses:
QueryDslJpaRepository

@Repository
public class SimpleJpaRepository<T,ID extends Serializable>
extends Object
implements JpaRepository<T,ID>, JpaSpecificationExecutor<T>

Default implementation of the Repository interface. This will offer you a more sophisticated interface than the plain EntityManager .

Author:
Oliver Gierke, Eberhard Wolff

Constructor Summary
SimpleJpaRepository(JpaEntityInformation<T,ID> entityMetadata, javax.persistence.EntityManager entityManager)
          Creates a new SimpleJpaRepository to manage objects of the given domain type.
 
Method Summary
 Long count()
           
 Long count(Specification<T> spec)
          Returns the number of instances that the given Specification will return.
 void delete(Iterable<? extends T> entities)
           
 void delete(T entity)
           
 void deleteAll()
           
 void deleteInBatch(Iterable<T> entities)
          Deletes the given entities in a batch which means it will create a single Query.
 boolean exists(ID id)
           
 List<T> findAll()
           
 org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageable)
           
 List<T> findAll(org.springframework.data.domain.Sort sort)
           
 List<T> findAll(Specification<T> spec)
          Returns all entities matching the given Specification.
 org.springframework.data.domain.Page<T> findAll(Specification<T> spec, org.springframework.data.domain.Pageable pageable)
          Returns a Page of entities matching the given Specification.
 T findOne(ID id)
           
 T findOne(Specification<T> spec)
          Returns a single entity matching the given Specification.
 void flush()
          Flushes all pending changes to the database.
 List<T> save(Iterable<? extends T> entities)
           
 T save(T entity)
           
 T saveAndFlush(T entity)
          Saves an entity and flushes changes instantly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleJpaRepository

public SimpleJpaRepository(JpaEntityInformation<T,ID> entityMetadata,
                           javax.persistence.EntityManager entityManager)
Creates a new SimpleJpaRepository to manage objects of the given domain type.

Parameters:
entityMetadata -
entityManager -
Method Detail

delete

public void delete(T entity)
Specified by:
delete in interface JpaRepository<T,ID extends Serializable>
Specified by:
delete in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

delete

public void delete(Iterable<? extends T> entities)
Specified by:
delete in interface JpaRepository<T,ID extends Serializable>
Specified by:
delete in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

deleteInBatch

public void deleteInBatch(Iterable<T> entities)
Description copied from interface: JpaRepository
Deletes the given entities in a batch which means it will create a single Query. Assume that we will clear the EntityManager after the call.

Specified by:
deleteInBatch in interface JpaRepository<T,ID extends Serializable>

deleteAll

public void deleteAll()
Specified by:
deleteAll in interface JpaRepository<T,ID extends Serializable>
Specified by:
deleteAll in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

findOne

public T findOne(ID id)
Specified by:
findOne in interface JpaRepository<T,ID extends Serializable>
Specified by:
findOne in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

exists

public boolean exists(ID id)
Specified by:
exists in interface JpaRepository<T,ID extends Serializable>
Specified by:
exists in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

findAll

public List<T> findAll()
Specified by:
findAll in interface JpaRepository<T,ID extends Serializable>
Specified by:
findAll in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

findAll

public List<T> findAll(org.springframework.data.domain.Sort sort)
Specified by:
findAll in interface JpaRepository<T,ID extends Serializable>
Specified by:
findAll in interface org.springframework.data.repository.PagingAndSortingRepository<T,ID extends Serializable>

findAll

public org.springframework.data.domain.Page<T> findAll(org.springframework.data.domain.Pageable pageable)
Specified by:
findAll in interface JpaRepository<T,ID extends Serializable>
Specified by:
findAll in interface org.springframework.data.repository.PagingAndSortingRepository<T,ID extends Serializable>

findOne

public T findOne(Specification<T> spec)
Description copied from interface: JpaSpecificationExecutor
Returns a single entity matching the given Specification.

Specified by:
findOne in interface JpaSpecificationExecutor<T>
Returns:

findAll

public List<T> findAll(Specification<T> spec)
Description copied from interface: JpaSpecificationExecutor
Returns all entities matching the given Specification.

Specified by:
findAll in interface JpaSpecificationExecutor<T>
Returns:

findAll

public org.springframework.data.domain.Page<T> findAll(Specification<T> spec,
                                                       org.springframework.data.domain.Pageable pageable)
Description copied from interface: JpaSpecificationExecutor
Returns a Page of entities matching the given Specification.

Specified by:
findAll in interface JpaSpecificationExecutor<T>
Returns:

count

public Long count()
Specified by:
count in interface JpaRepository<T,ID extends Serializable>
Specified by:
count in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

count

public Long count(Specification<T> spec)
Description copied from interface: JpaSpecificationExecutor
Returns the number of instances that the given Specification will return.

Specified by:
count in interface JpaSpecificationExecutor<T>
Parameters:
spec - the Specification to count instances for
Returns:
the number of instances

save

public T save(T entity)
Specified by:
save in interface JpaRepository<T,ID extends Serializable>
Specified by:
save in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

saveAndFlush

public T saveAndFlush(T entity)
Description copied from interface: JpaRepository
Saves an entity and flushes changes instantly.

Specified by:
saveAndFlush in interface JpaRepository<T,ID extends Serializable>
Returns:
the saved entity

save

public List<T> save(Iterable<? extends T> entities)
Specified by:
save in interface JpaRepository<T,ID extends Serializable>
Specified by:
save in interface org.springframework.data.repository.Repository<T,ID extends Serializable>

flush

public void flush()
Description copied from interface: JpaRepository
Flushes all pending changes to the database.

Specified by:
flush in interface JpaRepository<T,ID extends Serializable>

Spring Data Jpa

Copyright © 2011 SpringSource. All Rights Reserved.