Spring Data Core

org.springframework.data.repository
Interface CrudRepository<T,ID extends Serializable>

All Superinterfaces:
Repository<T,ID>
All Known Subinterfaces:
PagingAndSortingRepository<T,ID>

@NoRepositoryBean
public interface CrudRepository<T,ID extends Serializable>
extends Repository<T,ID>

Interface for generic CRUD operations on a repository for a specific type.

Author:
Oliver Gierke, Eberhard Wolff

Method Summary
 long count()
          Returns the number of entities available.
 void delete(ID id)
          Deletes the entity with the given id.
 void delete(Iterable<? extends T> entities)
          Deletes the given entities.
 void delete(T entity)
          Deletes a given entity.
 void deleteAll()
          Deletes all entities managed by the repository.
 boolean exists(ID id)
          Returns whether an entity with the given id exists.
 Iterable<T> findAll()
          Returns all instances of the type.
 Iterable<T> findAll(Iterable<ID> ids)
          Returns all instances of the type with the given IDs.
 T findOne(ID id)
          Retrieves an entity by its id.
<S extends T>
Iterable<S>
save(Iterable<S> entities)
          Saves all given entities.
<S extends T>
S
save(S entity)
          Saves a given entity.
 

Method Detail

save

<S extends T> S save(S entity)
Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.

Parameters:
entity -
Returns:
the saved entity

save

<S extends T> Iterable<S> save(Iterable<S> entities)
Saves all given entities.

Parameters:
entities -
Returns:
the saved entities
Throws:
IllegalArgumentException - in case the given entity is (@literal null}.

findOne

T findOne(ID id)
Retrieves an entity by its id.

Parameters:
id - must not be null.
Returns:
the entity with the given id or null if none found
Throws:
IllegalArgumentException - if id is null

exists

boolean exists(ID id)
Returns whether an entity with the given id exists.

Parameters:
id - must not be null.
Returns:
true if an entity with the given id exists, false otherwise
Throws:
IllegalArgumentException - if id is null

findAll

Iterable<T> findAll()
Returns all instances of the type.

Returns:
all entities

findAll

Iterable<T> findAll(Iterable<ID> ids)
Returns all instances of the type with the given IDs.

Parameters:
ids -
Returns:

count

long count()
Returns the number of entities available.

Returns:
the number of entities

delete

void delete(ID id)
Deletes the entity with the given id.

Parameters:
id - must not be null.
Throws:
IllegalArgumentException - in case the given id is null

delete

void delete(T entity)
Deletes a given entity.

Parameters:
entity -
Throws:
IllegalArgumentException - in case the given entity is (@literal null}.

delete

void delete(Iterable<? extends T> entities)
Deletes the given entities.

Parameters:
entities -
Throws:
IllegalArgumentException - in case the given Iterable is (@literal null}.

deleteAll

void deleteAll()
Deletes all entities managed by the repository.


Spring Data Core

Copyright © 2011-2013-2013 Pivotal. All Rights Reserved.