java.lang.Object
org.springframework.data.keyvalue.core.KeyValueTemplate
- All Implemented Interfaces:
Aware,DisposableBean,ApplicationEventPublisherAware,KeyValueOperations
public class KeyValueTemplate
extends Object
implements KeyValueOperations, ApplicationEventPublisherAware
Basic implementation of
KeyValueOperations.- Author:
- Christoph Strobl, Oliver Gierke, Thomas Darimont, Mark Paluch, Mert Zeybekler, Adeyemi Abass
-
Constructor Summary
ConstructorsConstructorDescriptionKeyValueTemplate(KeyValueAdapter adapter) KeyValueTemplate(KeyValueAdapter adapter, MappingContext<? extends KeyValuePersistentEntity<?, ?>, ? extends KeyValuePersistentProperty<?>> mappingContext) KeyValueTemplate(KeyValueAdapter adapter, MappingContext<? extends KeyValuePersistentEntity<?, ?>, ? extends KeyValuePersistentProperty<?>> mappingContext, IdentifierGenerator identifierGenerator) -
Method Summary
Modifier and TypeMethodDescriptionlongTotal number of elements with given type available.longcount(KeyValueQuery<?> query, Class<?> type) Total number of elements matching given query.voidRemove all elements of type.<T> TDelete item of type with given id.<T> Tdelete(T objectToDelete) voiddestroy()<T> Texecute(KeyValueCallback<T> action) Execute operation against underlying store.protected <T> TexecuteRequired(KeyValueCallback<T> action) ExecuteKeyValueCallbackand require a non-null return value.booleanexists(KeyValueQuery<?> query, Class<?> type) Determine whether result of givenKeyValueQuerycontains at least one element.<T> Iterable<T>find(KeyValueQuery<?> query, Class<T> type) Get all elements matching the given query.<T> Iterable<T>Get all elements of given type.<T> Iterable<T>Get all elements ordered by sort.<T> Optional<T>Get element of given type with given id.<T> Iterable<T>findInRange(long offset, int rows, Class<T> type) Get all elements in given range.<T> Iterable<T>findInRange(long offset, int rows, Sort sort, Class<T> type) Get all elements in given range ordered by sort.MappingContext<?,?> <T> TAdd object with given id.<T> Tinsert(T objectToInsert) Add given object.voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) voidsetEventTypesToPublish(Set<Class<? extends KeyValueEvent>> eventTypesToPublish) Define the event types to publish viaApplicationEventPublisher.voidsetExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator) Set thePersistenceExceptionTranslatorused for convertingRuntimeException.<T> T<T> Tupdate(T objectToUpdate)
-
Constructor Details
-
KeyValueTemplate
- Parameters:
adapter- must not be null.
-
KeyValueTemplate
public KeyValueTemplate(KeyValueAdapter adapter, MappingContext<? extends KeyValuePersistentEntity<?, ?>, ? extends KeyValuePersistentProperty<?>> mappingContext) - Parameters:
adapter- must not be null.mappingContext- must not be null.
-
KeyValueTemplate
public KeyValueTemplate(KeyValueAdapter adapter, MappingContext<? extends KeyValuePersistentEntity<?, ?>, ? extends KeyValuePersistentProperty<?>> mappingContext, IdentifierGenerator identifierGenerator) - Parameters:
adapter- must not be null.mappingContext- must not be null.identifierGenerator- must not be null.- Since:
- 2.4
-
-
Method Details
-
setExceptionTranslator
Set thePersistenceExceptionTranslatorused for convertingRuntimeException.- Parameters:
exceptionTranslator- must not be null.
-
setEventTypesToPublish
Define the event types to publish viaApplicationEventPublisher.- Parameters:
eventTypesToPublish- use null orCollections.emptySet()to stop publishing.
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisherin interfaceApplicationEventPublisherAware
-
insert
public <T> T insert(T objectToInsert) Description copied from interface:KeyValueOperationsAdd given object. Object needs to have id property to which a generated value will be assigned.- Specified by:
insertin interfaceKeyValueOperations- Returns:
- the inserted object.
-
insert
Description copied from interface:KeyValueOperationsAdd object with given id.- Specified by:
insertin interfaceKeyValueOperations- Parameters:
id- must not be null.objectToInsert- must not be null.- Returns:
- the inserted object.
-
update
public <T> T update(T objectToUpdate) - Specified by:
updatein interfaceKeyValueOperations- Parameters:
objectToUpdate- must not be null.- Returns:
- the updated object.
-
update
- Specified by:
updatein interfaceKeyValueOperations- Parameters:
id- must not be null.objectToUpdate- must not be null.- Returns:
- the updated object.
-
findAll
Description copied from interface:KeyValueOperationsGet all elements of given type. RespectsKeySpaceif present and therefore returns all elements that can be assigned to requested type.- Specified by:
findAllin interfaceKeyValueOperations- Parameters:
type- must not be null.- Returns:
- empty iterable if no elements found.
-
findById
Description copied from interface:KeyValueOperationsGet element of given type with given id. RespectsKeySpaceif present and therefore returns all elements that can be assigned to requested type.- Specified by:
findByIdin interfaceKeyValueOperations- Parameters:
id- must not be null.type- must not be null.- Returns:
Optional.empty()if not found.
-
delete
Description copied from interface:KeyValueOperationsRemove all elements of type. RespectsKeySpaceif present and therefore removes all elements that can be assigned to requested type.- Specified by:
deletein interfaceKeyValueOperations- Parameters:
type- must not be null.
-
delete
public <T> T delete(T objectToDelete) - Specified by:
deletein interfaceKeyValueOperations- Parameters:
objectToDelete- must not be null.- Returns:
-
delete
Description copied from interface:KeyValueOperationsDelete item of type with given id.- Specified by:
deletein interfaceKeyValueOperations- Parameters:
id- must not be null.type- must not be null.- Returns:
- the deleted item or null if no match found.
-
count
Description copied from interface:KeyValueOperationsTotal number of elements with given type available. RespectsKeySpaceif present and therefore counts all elements that can be assigned to requested type.- Specified by:
countin interfaceKeyValueOperations- Parameters:
type- must not be null.- Returns:
-
execute
Description copied from interface:KeyValueOperationsExecute operation against underlying store.- Specified by:
executein interfaceKeyValueOperations- Parameters:
action- must not be null.- Returns:
-
executeRequired
ExecuteKeyValueCallbackand require a non-null return value.- Type Parameters:
T-- Parameters:
action-- Returns:
-
find
Description copied from interface:KeyValueOperationsGet all elements matching the given query.
RespectsKeySpaceif present and therefore returns all elements that can be assigned to requested type..- Specified by:
findin interfaceKeyValueOperations- Parameters:
query- must not be null.type- must not be null.- Returns:
- empty iterable if no match found.
-
findAll
Description copied from interface:KeyValueOperationsGet all elements ordered by sort. RespectsKeySpaceif present and therefore returns all elements that can be assigned to requested type.- Specified by:
findAllin interfaceKeyValueOperations- Parameters:
sort- must not be null.type- must not be null.- Returns:
-
findInRange
Description copied from interface:KeyValueOperationsGet all elements in given range. RespectsKeySpaceif present and therefore returns all elements that can be assigned to requested type.- Specified by:
findInRangein interfaceKeyValueOperationstype- must not be null.- Returns:
-
findInRange
Description copied from interface:KeyValueOperationsGet all elements in given range ordered by sort. RespectsKeySpaceif present and therefore returns all elements that can be assigned to requested type.- Specified by:
findInRangein interfaceKeyValueOperations- Returns:
-
count
Description copied from interface:KeyValueOperationsTotal number of elements matching given query. RespectsKeySpaceif present and therefore counts all elements that can be assigned to requested type.- Specified by:
countin interfaceKeyValueOperations- Returns:
-
exists
Description copied from interface:KeyValueOperationsDetermine whether result of givenKeyValueQuerycontains at least one element.- Specified by:
existsin interfaceKeyValueOperations- Returns:
-
getMappingContext
- Specified by:
getMappingContextin interfaceKeyValueOperations- Returns:
- mapping context in use.
-
getKeyValueAdapter
- Specified by:
getKeyValueAdapterin interfaceKeyValueOperations- Returns:
KeyValueAdapterin use.
-
destroy
- Specified by:
destroyin interfaceDisposableBean- Throws:
Exception
-