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>, CrudRepository<T,ID>, PagingAndSortingRepository<T,ID>, Repository<T,ID>
Direct Known Subclasses:
QueryDslJpaRepository

@Repository
@Transactional(readOnly=true)
public class SimpleJpaRepository<T,ID extends Serializable>
extends Object
implements JpaRepository<T,ID>, JpaSpecificationExecutor<T>

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

Author:
Oliver Gierke, Eberhard Wolff

Constructor Summary
SimpleJpaRepository(Class<T> domainClass, javax.persistence.EntityManager em)
          Creates a new SimpleJpaRepository to manage objects of the given domain type.
SimpleJpaRepository(JpaEntityInformation<T,?> entityInformation, javax.persistence.EntityManager entityManager)
          Creates a new SimpleJpaRepository to manage objects of the given JpaEntityInformation.
 
Method Summary
 long count()
           
 long count(Specification<T> spec)
          Returns the number of instances that the given Specification will return.
 void delete(ID id)
           
 void delete(Iterable<? extends T> entities)
           
 void delete(T entity)
           
 void deleteAll()
           
 void deleteAllInBatch()
          Deletes all entites in a batch call.
 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()
           
 List<T> findAll(Iterable<ID> ids)
           
 Page<T> findAll(Pageable pageable)
           
 List<T> findAll(Sort sort)
           
 List<T> findAll(Specification<T> spec)
          Returns all entities matching the given Specification.
 Page<T> findAll(Specification<T> spec, Pageable pageable)
          Returns a Page of entities matching the given Specification.
 List<T> findAll(Specification<T> spec, Sort sort)
          Returns all entities matching the given Specification and Sort.
 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.
<S extends T>
List<S>
save(Iterable<S> entities)
           
<S extends T>
S
save(S entity)
           
 T saveAndFlush(T entity)
          Saves an entity and flushes changes instantly.
 void setLockMetadataProvider(LockMetadataProvider lockMetadataProvider)
          Configures a custom LockMetadataProvider to be used to detect LockModeTypes to be applied to queries.
 
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,?> entityInformation,
                           javax.persistence.EntityManager entityManager)
Creates a new SimpleJpaRepository to manage objects of the given JpaEntityInformation.

Parameters:
entityInformation - must not be null.
entityManager - must not be null.

SimpleJpaRepository

public SimpleJpaRepository(Class<T> domainClass,
                           javax.persistence.EntityManager em)
Creates a new SimpleJpaRepository to manage objects of the given domain type.

Parameters:
domainClass - must not be null.
em - must not be null.
Method Detail

setLockMetadataProvider

public void setLockMetadataProvider(LockMetadataProvider lockMetadataProvider)
Configures a custom LockMetadataProvider to be used to detect LockModeTypes to be applied to queries.

Parameters:
lockMetadataProvider -

delete

@Transactional
public void delete(ID id)
Specified by:
delete in interface CrudRepository<T,ID extends Serializable>

delete

@Transactional
public void delete(T entity)
Specified by:
delete in interface CrudRepository<T,ID extends Serializable>

delete

@Transactional
public void delete(Iterable<? extends T> entities)
Specified by:
delete in interface CrudRepository<T,ID extends Serializable>

deleteInBatch

@Transactional
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

@Transactional
public void deleteAll()
Specified by:
deleteAll in interface CrudRepository<T,ID extends Serializable>

deleteAllInBatch

@Transactional
public void deleteAllInBatch()
Description copied from interface: JpaRepository
Deletes all entites in a batch call.

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

findOne

public T findOne(ID id)
Specified by:
findOne in interface CrudRepository<T,ID extends Serializable>

exists

public boolean exists(ID id)
Specified by:
exists in interface CrudRepository<T,ID extends Serializable>

findAll

public List<T> findAll()
Specified by:
findAll in interface JpaRepository<T,ID extends Serializable>
Specified by:
findAll in interface CrudRepository<T,ID extends Serializable>

findAll

public List<T> findAll(Iterable<ID> ids)
Specified by:
findAll in interface CrudRepository<T,ID extends Serializable>

findAll

public List<T> findAll(Sort sort)
Specified by:
findAll in interface JpaRepository<T,ID extends Serializable>
Specified by:
findAll in interface PagingAndSortingRepository<T,ID extends Serializable>

findAll

public Page<T> findAll(Pageable pageable)
Specified by:
findAll in interface 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 Page<T> findAll(Specification<T> spec,
                       Pageable pageable)
Description copied from interface: JpaSpecificationExecutor
Returns a Page of entities matching the given Specification.

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

findAll

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

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

count

public long count()
Specified by:
count in interface CrudRepository<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

@Transactional
public <S extends T> S save(S entity)
Specified by:
save in interface CrudRepository<T,ID extends Serializable>

saveAndFlush

@Transactional
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

@Transactional
public <S extends T> List<S> save(Iterable<S> entities)
Specified by:
save in interface JpaRepository<T,ID extends Serializable>
Specified by:
save in interface CrudRepository<T,ID extends Serializable>

flush

@Transactional
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-2012-2012 SpringSource. All Rights Reserved.