Interface CrudRepository<T,K>
- Type Parameters:
T
- the type of the repositoryK
- the type of the primary key of T, or in case of compound primary key, T itself, orVoid
if T does not have a primary key
- All Known Subinterfaces:
CrudRepositoryBaseRepo<T,
,K, Q> ValqueriesAccessDataLayer<T,
,K> ValqueriesCrudRepository<T,
K>
- All Known Implementing Classes:
AutoCrudRepositoryImpl
,CrudRepositoryTestDoubleBase
,com.fracturecode.saga.repository.FairLockRepository
,TestFairLockRepository
,ValqueriesAccessDataLayerImpl
,ValqueriesAccessDataLayerTestDouble
,ValqueriesCrudRepositoryImpl
If the repository entity does not have a key field, the type of the key should be Void
.
This will prevent using the get(K)
, deleteById(K)
and deleteByIds(Collection)
methods at compile time, as it is not possible to get an entity by its key if it does not have one.
It is still possible to query other fields and get entities by other means.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Represents a result of an update.static interface
CrudRepository.InlineQuery<T,
Q extends CrudRepository.InlineQuery<T, Q>> Represents a query within aCrudRepository
. -
Method Summary
Modifier and TypeMethodDescriptiondeleteById
(K id) Delete an instance of the entity by its id (primary key).deleteByIds
(Collection<K> id) Delete all instances of the entity which has an id (primary key) in the given collection.Get an instance of the entity by its id (primary key).getAll()
Get all instances of the entity, as a stream.Insert a new instance of the entity or update an existing one.
-
Method Details
-
get
Get an instance of the entity by its id (primary key).Note: If the entity does not have a primary key, this method will not be available.
In case of compound primary key, pass the model object with the primary key fields populated.
- Parameters:
id
- the id of the entity- Returns:
- an optional containing the entity if it exists
-
getAll
Get all instances of the entity, as a stream.- Returns:
- an unordered stream of all instances of the entity
-
deleteById
Delete an instance of the entity by its id (primary key).Note: If the entity does not have a primary key, this method will not be available.
In case of compound primary key, pass the model object with the primary key fields populated.
- Parameters:
id
- the id of the entity to be deleted- Returns:
- the result of the delete operation
-
deleteByIds
Delete all instances of the entity which has an id (primary key) in the given collection.Note: If the entity does not have a primary key, this method will not be available.
In case of compound primary key, pass the model object with the primary key fields populated.
- Parameters:
id
- a collection of ids to be deleted- Returns:
- the result of the delete operation
-
save
Insert a new instance of the entity or update an existing one. Will match by primary key, but not other unique keys.- Parameters:
t
- the entity to save- Returns:
- the result of the save operation
-