public interface StorageFactory
extends java.lang.AutoCloseable
EventStore
and Delivery
.
The applications built with Spine use serialized Protobuf messages as a format of storing the data objects. There is a number of storage types, each of them packs their run-time information into a Proto message of a certain kind.
In order to unify the structure of the stored information and the way of its further
retrieval, a RecordStorage
type is made a common ground for all other storage
types. It is capable of storing and querying any Protobuf messages, and provides
a configuration API for detailing on how each message is transformed into a stored record.
To achieve that, each of the storage classes starts its own initialization by creating
an underlying RecordStorage
and customizing it with a specification of the Proto message to store. Once that is done, all operations are
run through this delegate instance.
Such an approach brings another advantage for SPI users, too. It is sufficient to provide
just a new RecordStorage
implementation in order to extend the storage factory
to support a certain DBMS. The rest of storage types just remain as delegating types,
and their code may be kept agnostic of low-level DBMS details. However, if one wants to extend
the functionality even further, any storage type may be extended and customized.
Another design intention is that all storage types which are presumed to work in a scope of
some Bounded Context — down to a RecordStorage
— would take a context specification as the first parameter. An idea is that they may need to use
the properties of the Bounded Context (such as its name) in their low-level I/O with
the database. Only two of the storage types do not follow this concept: InboxStorage
and CatchUpStorage
. The reason for that is that they are a part of
a Delivery
which is shared across all domain Bounded Contexts.
One more storage which stands apart of this idea is
a TenantStorage
. While it uses a StorageFactory
for an initialization, it is a part of a special Tenants
context, which is also shared
between domain Bounded Contexts of an application.
See the package-level documentation of io.spine.query
for more details on
record specification and querying.
Modifier and Type | Method and Description |
---|---|
default AggregateEventStorage |
createAggregateEventStorage(ContextSpec context)
Creates a new
AggregateEventStorage . |
default <I,S extends io.spine.base.EntityState<I>> |
createAggregateStorage(ContextSpec context,
java.lang.Class<? extends Aggregate<I,S,?>> aggregateCls)
Creates a new
AggregateStorage . |
default CatchUpStorage |
createCatchUpStorage(boolean multitenant)
Creates a new
CatchUpStorage . |
default <I,S extends io.spine.base.EntityState<I>> |
createEntityRecordStorage(ContextSpec context,
java.lang.Class<? extends Entity<I,S>> entityClass)
Creates a new
EntityRecordStorage . |
default EventStore |
createEventStore(ContextSpec context)
Creates a new
EventStore . |
default InboxStorage |
createInboxStorage(boolean multitenant)
Creates a new
InboxStorage . |
<I,R extends com.google.protobuf.Message> |
createRecordStorage(ContextSpec context,
RecordSpec<I,R,?> recordSpec)
Creates a new
RecordStorage . |
<I,R extends com.google.protobuf.Message> RecordStorage<I,R> createRecordStorage(ContextSpec context, RecordSpec<I,R,?> recordSpec)
RecordStorage
.I
- the type of the record identifiersR
- the type of the stored recordscontext
- specification of the Bounded Context in scope of which the storage will be usedrecordSpec
- the specification of the record format in which the items are storedRecordStorage
and therefore use this method during their initialization
to create an private instance of a record storage.default <I,S extends io.spine.base.EntityState<I>> AggregateStorage<I,S> createAggregateStorage(ContextSpec context, java.lang.Class<? extends Aggregate<I,S,?>> aggregateCls)
AggregateStorage
.I
- the type of aggregate IDsS
- the type of aggregate statecontext
- specification of the Bounded Context, in scope of which the storage will be usedaggregateCls
- the class of Aggregate
s to be storeddefault AggregateEventStorage createAggregateEventStorage(ContextSpec context)
AggregateEventStorage
.context
- specification of the Bounded Context in scope of which the storage will be useddefault EventStore createEventStore(ContextSpec context)
EventStore
.context
- specification of the Bounded Context events of which the store would servedefault <I,S extends io.spine.base.EntityState<I>> EntityRecordStorage<I,S> createEntityRecordStorage(ContextSpec context, java.lang.Class<? extends Entity<I,S>> entityClass)
EntityRecordStorage
.I
- the type of entity IDsS
- the type of the entity statecontext
- specification of the Bounded Context, in scope of which this storage will be usedentityClass
- the class of entities to be storeddefault InboxStorage createInboxStorage(boolean multitenant)
InboxStorage
.
The instance of InboxStorage
is used in the Delivery
operations. Therefore there is typically just
a single instance of InboxStorage
per ServerEnvironment
instance, unlike other Storage
types which instances are created
per-BoundedContext
.
multitenant
- whether the created storage should be multi-tenantdefault CatchUpStorage createCatchUpStorage(boolean multitenant)
CatchUpStorage
.
Similar to InboxStorage
, this type of storage is also used in the Delivery
routines. So by default there is a single
instance of CatchUpStorage
per ServerEnvironment
.
multitenant
- whether the created storage should be multi-tenant