public class KeyValueTemplate extends Object implements KeyValueOperations, ApplicationEventPublisherAware
KeyValueOperations
.Constructor and Description |
---|
KeyValueTemplate(KeyValueAdapter adapter)
|
KeyValueTemplate(KeyValueAdapter adapter,
MappingContext<? extends KeyValuePersistentEntity<?,?>,? extends KeyValuePersistentProperty<?>> mappingContext)
|
KeyValueTemplate(KeyValueAdapter adapter,
MappingContext<? extends KeyValuePersistentEntity<?,?>,? extends KeyValuePersistentProperty<?>> mappingContext,
IdentifierGenerator identifierGenerator)
|
Modifier and Type | Method and Description |
---|---|
long |
count(Class<?> type)
Total number of elements with given type available.
|
long |
count(KeyValueQuery<?> query,
Class<?> type)
Total number of elements matching given query.
|
void |
delete(Class<?> type)
Remove all elements of type.
|
<T> T |
delete(Object id,
Class<T> type)
Delete item of type with given id.
|
<T> T |
delete(T objectToDelete) |
void |
destroy() |
<T> T |
execute(KeyValueCallback<T> action)
Execute operation against underlying store.
|
protected <T> T |
executeRequired(KeyValueCallback<T> action)
Execute
KeyValueCallback and require a non-null return value. |
<T> Iterable<T> |
find(KeyValueQuery<?> query,
Class<T> type)
Get all elements matching the given query.
|
<T> Iterable<T> |
findAll(Class<T> type)
Get all elements of given type.
|
<T> Iterable<T> |
findAll(Sort sort,
Class<T> type)
Get all elements ordered by sort.
|
<T> Optional<T> |
findById(Object id,
Class<T> type)
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<?,?> |
getMappingContext() |
<T> T |
insert(Object id,
T objectToInsert)
Add object with given id.
|
<T> T |
insert(T objectToInsert)
Add given object.
|
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setEventTypesToPublish(Set<Class<? extends KeyValueEvent>> eventTypesToPublish)
Define the event types to publish via
ApplicationEventPublisher . |
void |
setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator)
Set the
PersistenceExceptionTranslator used for converting RuntimeException . |
<T> T |
update(Object id,
T objectToUpdate) |
<T> T |
update(T objectToUpdate) |
public KeyValueTemplate(KeyValueAdapter adapter)
adapter
- must not be null.public KeyValueTemplate(KeyValueAdapter adapter, MappingContext<? extends KeyValuePersistentEntity<?,?>,? extends KeyValuePersistentProperty<?>> mappingContext)
adapter
- must not be null.mappingContext
- must not be null.public KeyValueTemplate(KeyValueAdapter adapter, MappingContext<? extends KeyValuePersistentEntity<?,?>,? extends KeyValuePersistentProperty<?>> mappingContext, IdentifierGenerator identifierGenerator)
adapter
- must not be null.mappingContext
- must not be null.identifierGenerator
- must not be null.public void setExceptionTranslator(PersistenceExceptionTranslator exceptionTranslator)
PersistenceExceptionTranslator
used for converting RuntimeException
.exceptionTranslator
- must not be null.public void setEventTypesToPublish(Set<Class<? extends KeyValueEvent>> eventTypesToPublish)
ApplicationEventPublisher
.eventTypesToPublish
- use null or Collections.emptySet()
to stop publishing.public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
public <T> T insert(T objectToInsert)
KeyValueOperations
insert
in interface KeyValueOperations
public <T> T insert(Object id, T objectToInsert)
KeyValueOperations
insert
in interface KeyValueOperations
id
- must not be null.objectToInsert
- must not be null.public <T> T update(T objectToUpdate)
update
in interface KeyValueOperations
objectToUpdate
- must not be null.public <T> T update(Object id, T objectToUpdate)
update
in interface KeyValueOperations
id
- must not be null.objectToUpdate
- must not be null.public <T> Iterable<T> findAll(Class<T> type)
KeyValueOperations
KeySpace
if present and therefore returns all elements that can be
assigned to requested type.findAll
in interface KeyValueOperations
type
- must not be null.public <T> Optional<T> findById(Object id, Class<T> type)
KeyValueOperations
KeySpace
if present and therefore returns all elements
that can be assigned to requested type.findById
in interface KeyValueOperations
id
- must not be null.type
- must not be null.Optional.empty()
if not found.public void delete(Class<?> type)
KeyValueOperations
KeySpace
if present and therefore removes all elements that can be
assigned to requested type.delete
in interface KeyValueOperations
type
- must not be null.public <T> T delete(T objectToDelete)
delete
in interface KeyValueOperations
objectToDelete
- must not be null.public <T> T delete(Object id, Class<T> type)
KeyValueOperations
delete
in interface KeyValueOperations
id
- must not be null.type
- must not be null.public long count(Class<?> type)
KeyValueOperations
KeySpace
if present and therefore counts all
elements that can be assigned to requested type.count
in interface KeyValueOperations
type
- must not be null.@Nullable public <T> T execute(KeyValueCallback<T> action)
KeyValueOperations
execute
in interface KeyValueOperations
action
- must not be null.protected <T> T executeRequired(KeyValueCallback<T> action)
KeyValueCallback
and require a non-null return value.T
- action
- public <T> Iterable<T> find(KeyValueQuery<?> query, Class<T> type)
KeyValueOperations
KeySpace
if present and therefore returns all elements that can be assigned to requested type..find
in interface KeyValueOperations
query
- must not be null.type
- must not be null.public <T> Iterable<T> findAll(Sort sort, Class<T> type)
KeyValueOperations
KeySpace
if present and therefore returns all elements that can
be assigned to requested type.findAll
in interface KeyValueOperations
sort
- must not be null.type
- must not be null.public <T> Iterable<T> findInRange(long offset, int rows, Class<T> type)
KeyValueOperations
KeySpace
if present and therefore returns all elements that can
be assigned to requested type.findInRange
in interface KeyValueOperations
type
- must not be null.public <T> Iterable<T> findInRange(long offset, int rows, Sort sort, Class<T> type)
KeyValueOperations
KeySpace
if present and therefore returns all
elements that can be assigned to requested type.findInRange
in interface KeyValueOperations
public long count(KeyValueQuery<?> query, Class<?> type)
KeyValueOperations
KeySpace
if present and therefore counts all
elements that can be assigned to requested type.count
in interface KeyValueOperations
public MappingContext<?,?> getMappingContext()
getMappingContext
in interface KeyValueOperations
public void destroy() throws Exception
destroy
in interface DisposableBean
Exception
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.