Struct krill::commons::eventsourcing::AggregateStore
source · pub struct AggregateStore<A: Aggregate> { /* private fields */ }
Expand description
This type is responsible for managing aggregates.
Implementations§
source§impl<A: Aggregate> AggregateStore<A>
impl<A: Aggregate> AggregateStore<A>
sourcepub fn create(
storage_uri: &Url,
namespace: &Namespace,
use_history_cache: bool
) -> StoreResult<Self>
pub fn create( storage_uri: &Url, namespace: &Namespace, use_history_cache: bool ) -> StoreResult<Self>
Creates an AggregateStore using the given storage url
sourcepub fn create_upgrade_store(
storage_uri: &Url,
name_space: &Namespace,
use_history_cache: bool
) -> StoreResult<Self>
pub fn create_upgrade_store( storage_uri: &Url, name_space: &Namespace, use_history_cache: bool ) -> StoreResult<Self>
Creates an AggregateStore for upgrades using the given storage url
sourcepub fn warm(&self) -> StoreResult<()>
pub fn warm(&self) -> StoreResult<()>
Warms up the cache, to be used after startup. Will fail if any aggregates fail to load.
sourcepub fn warm_aggregate(&self, handle: &MyHandle) -> StoreResult<()>
pub fn warm_aggregate(&self, handle: &MyHandle) -> StoreResult<()>
Warm the cache for a specific aggregate.
sourcepub fn add_pre_save_listener<L: PreSaveEventListener<A>>(
&mut self,
sync_listener: Arc<L>
)
pub fn add_pre_save_listener<L: PreSaveEventListener<A>>( &mut self, sync_listener: Arc<L> )
Adds a listener that will receive all events before they are stored.
sourcepub fn add_post_save_listener<L: PostSaveEventListener<A>>(
&mut self,
listener: Arc<L>
)
pub fn add_post_save_listener<L: PostSaveEventListener<A>>( &mut self, listener: Arc<L> )
Adds a listener that will receive a reference to all events after they are stored.
source§impl<A: Aggregate> AggregateStore<A>
impl<A: Aggregate> AggregateStore<A>
sourcepub fn get_latest(&self, handle: &MyHandle) -> Result<Arc<A>, A::Error>
pub fn get_latest(&self, handle: &MyHandle) -> Result<Arc<A>, A::Error>
Gets the latest version for the given aggregate. Returns an AggregateStoreError::UnknownAggregate in case the aggregate does not exist.
sourcepub fn update_snapshots(&self) -> Result<(), A::Error>
pub fn update_snapshots(&self) -> Result<(), A::Error>
Updates the snapshots for all entities in this store.
sourcepub fn save_snapshot(&self, handle: &MyHandle) -> Result<Arc<A>, A::Error>
pub fn save_snapshot(&self, handle: &MyHandle) -> Result<Arc<A>, A::Error>
Gets the latest version for the given aggregate and updates the snapshot.
sourcepub fn add(&self, cmd: A::InitCommand) -> Result<Arc<A>, A::Error>
pub fn add(&self, cmd: A::InitCommand) -> Result<Arc<A>, A::Error>
Adds a new aggregate instance based on the init event.
sourcepub fn command(&self, cmd: A::Command) -> Result<Arc<A>, A::Error>
pub fn command(&self, cmd: A::Command) -> Result<Arc<A>, A::Error>
Send a command to the latest aggregate referenced by the handle in the command.
This will:
- Retrieve the latest aggregate for this command.
- Call the A::process_command function
on success:
- call pre-save listeners with events
- save command and events
- call post-save listeners with events
- return aggregate on no-op (empty event list):
- do not save anything, return aggregate on error:
- save command and error, return error
source§impl<A: Aggregate> AggregateStore<A>
impl<A: Aggregate> AggregateStore<A>
sourcepub fn command_history(
&self,
id: &MyHandle,
crit: CommandHistoryCriteria
) -> Result<CommandHistory, AggregateStoreError>
pub fn command_history( &self, id: &MyHandle, crit: CommandHistoryCriteria ) -> Result<CommandHistory, AggregateStoreError>
Find all commands that fit the criteria and return history
sourcepub fn get_command(
&self,
id: &MyHandle,
version: u64
) -> Result<StoredCommand<A>, AggregateStoreError>
pub fn get_command( &self, id: &MyHandle, version: u64 ) -> Result<StoredCommand<A>, AggregateStoreError>
Get the command for this key, if it exists
source§impl<A: Aggregate> AggregateStore<A>
impl<A: Aggregate> AggregateStore<A>
sourcepub fn drop_aggregate(&self, id: &MyHandle) -> Result<(), AggregateStoreError>
pub fn drop_aggregate(&self, id: &MyHandle) -> Result<(), AggregateStoreError>
Drop an aggregate, completely. Handle with care!