public class GenericDataStoreDAOImpl extends Object implements ApplicationEventPublisherAware, GenericDataStoreDAO, SmartInitializingSingleton
generic_data_store
table in the Apache Cassandra database.GenericDataStoreDAO.DataItem
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
log
Logger for this object.
|
Constructor and Description |
---|
GenericDataStoreDAOImpl() |
Modifier and Type | Method and Description |
---|---|
void |
afterSingletonsInstantiated() |
ListenableFuture<Pair<Boolean,String>> |
createItem(UUID componentId,
String key,
String value)
Create a data item for the specified component and key if no such item
exists yet.
|
ListenableFuture<Void> |
createOrUpdateItem(UUID componentId,
String key,
String value)
Creates a data item or updates it if an item with the specified key
already exists for the specified component.
|
ListenableFuture<Void> |
deleteAllItems(UUID componentId)
Removes all data items for the specified component.
|
ListenableFuture<Void> |
deleteItem(UUID componentId,
String key)
Removes the item with the specified key from collection of data items for
the specified component.
|
ListenableFuture<? extends Iterable<? extends GenericDataStoreDAO.DataItem>> |
getAllItems(UUID componentId)
Returns all data items for the specified component.
|
ListenableFuture<? extends GenericDataStoreDAO.DataItem> |
getItem(UUID componentId,
String key)
Returns the data item with the specified key for the specified component.
|
boolean |
isInitialized()
Tells whether this DAO has finished initialization and is ready to be
used.
|
void |
onCassandraProviderInitializedEvent(CassandraProviderInitializedEvent event)
Handles
CassandraProviderInitializedEvent s. |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setCassandraProvider(CassandraProvider cassandraProvider)
Sets the Cassandra provider that provides access to the Apache Cassandra
database.
|
ListenableFuture<Pair<Boolean,String>> |
updateItem(UUID componentId,
String key,
String oldValue,
String newValue)
Updates the data item with the specified key and component.
|
protected final org.slf4j.Logger log
@EventListener @Order(value=1000) public void onCassandraProviderInitializedEvent(CassandraProviderInitializedEvent event)
CassandraProviderInitializedEvent
s. This event is used
when the CassandraProvider
set using
setCassandraProvider(CassandraProvider)
is not ready yet when
this object is initialized. In this case, some actions that usually are
performed during initialization (like creating tables, initializing
access objects) have to be deferred until the Apache Cassandra database
becomes available.event
- initialization event sent by the CassandraProvider
.@Autowired public void setCassandraProvider(CassandraProvider cassandraProvider)
cassandraProvider
- provider that provides a connection to the Apache Cassandra
database.public void afterSingletonsInstantiated()
afterSingletonsInstantiated
in interface SmartInitializingSingleton
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
public ListenableFuture<Pair<Boolean,String>> createItem(UUID componentId, String key, String value)
GenericDataStoreDAO
GenericDataStoreDAO.createOrUpdateItem(UUID, String, String)
, so code should prefer
the latter method unless it has to ensure that it does not overwrite an
existing value. The operation is performed in an asynchronous way so that
it will not block for network communication. The result of the operation
can be checked through the returned future.createItem
in interface GenericDataStoreDAO
componentId
- ID of the component for which the data item should be created.key
- key identifying the data item within the component.value
- value of the data item.true
, the item was created, if false
,
an item with the specified key already existed for the specified
component. In this case, the string is the value of the existing
item. In case of failure, the future's get()
method
will throw an exception.public ListenableFuture<Void> createOrUpdateItem(UUID componentId, String key, String value)
GenericDataStoreDAO
GenericDataStoreDAO.createItem(UUID, String, String)
and
GenericDataStoreDAO.updateItem(UUID, String, String, String)
. The operation is
performed in an asynchronous way so that it will not block for network
communication. The result of the operation can be checked through the
returned future.createOrUpdateItem
in interface GenericDataStoreDAO
componentId
- ID of the component for which the data item should be created
or updated.key
- key identifying the data item within the component.value
- value of the data item.get()
method will throw an exception.public ListenableFuture<Void> deleteAllItems(UUID componentId)
GenericDataStoreDAO
deleteAllItems
in interface GenericDataStoreDAO
componentId
- ID of the component for which all data items should be
removed.get()
method will throw an exception.public ListenableFuture<Void> deleteItem(UUID componentId, String key)
GenericDataStoreDAO
deleteItem
in interface GenericDataStoreDAO
componentId
- ID of the component that owns the data item.key
- key identifying the data item within the component.get()
method will throw an exception.public ListenableFuture<? extends Iterable<? extends GenericDataStoreDAO.DataItem>> getAllItems(UUID componentId)
GenericDataStoreDAO
Returns all data items for the specified component. The operation is performed in an asynchronous way so that it will not block for network communication. The result of the operation can be checked through the returned future.
The iterable returned by the future is only safe for iterating once. Subsequent requests to create an iterator might result in the new iterator only returning the elements that have not been returned by a previously created iterator yet. Besides, the iterator might block while iterating, waiting for additional elements to arrive from the network.
getAllItems
in interface GenericDataStoreDAO
componentId
- ID of the component for which all data items should be
retrieved.get()
method will throw an exception.public ListenableFuture<? extends GenericDataStoreDAO.DataItem> getItem(UUID componentId, String key)
GenericDataStoreDAO
getItem
in interface GenericDataStoreDAO
componentId
- ID of the component that owns the data item.key
- key identifying the data item within the component.get
method returns null
. In
case of failure, the future's get()
method will
throw an exception.public boolean isInitialized()
GenericDataStoreDAO
true
, operations might
still fail because of transient problems.isInitialized
in interface GenericDataStoreDAO
true
if this DAO has been initialized and is ready
to be used, false
if initialization has not
completed yet.public ListenableFuture<Pair<Boolean,String>> updateItem(UUID componentId, String key, String oldValue, String newValue)
GenericDataStoreDAO
oldValue
. This type of atomic operation incurs an additional
overhead. Code that does not mind overwriting a different value should
prefer the GenericDataStoreDAO.createOrUpdateItem(UUID, String, String)
method. The
operation is performed in an asynchronous way so that it will not block
for network communication. The result of the operation can be checked
through the returned future.updateItem
in interface GenericDataStoreDAO
componentId
- ID of the component that owns the data item.key
- key identifying the data item within the component.oldValue
- old value of the data item that must be matched for the update
operation to proceed.newValue
- new value that the data item shall be updated with if the old
value matches.true
, the item was updated, if false
,
the item's value did not match the specified
oldValue
or the item did not exist. If the flag is
false
, the string is the current value of the
existing item or null
if no item with the specified
component ID and key exists. In case of failure, the future's
get()
method will throw an exception.Copyright © 2011–2017 aquenos GmbH. All rights reserved.