public abstract class JdbcEventStorageEngineStatements extends Object
PreparedStatement
builder methods for use in the JdbcEventStorageEngine
.Modifier and Type | Method and Description |
---|---|
static PreparedStatement |
appendEvents(Connection connection,
EventSchema schema,
Class<?> dataType,
List<? extends EventMessage<?>> events,
Serializer serializer,
TimestampWriter timestampWriter)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.appendEvents(List, Serializer) . |
static PreparedStatement |
appendSnapshot(Connection connection,
EventSchema schema,
Class<?> dataType,
DomainEventMessage<?> snapshot,
Serializer serializer,
TimestampWriter timestampWriter)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.storeSnapshot(DomainEventMessage,
Serializer) . |
protected static <T> DomainEventMessage<T> |
asDomainEventMessage(EventMessage<T> event)
Converts an
EventMessage to a DomainEventMessage . |
static PreparedStatement |
cleanGaps(Connection connection,
EventSchema schema,
SortedSet<Long> gaps)
Set the PreparedStatement to be used on internal cleanGaps operation.
|
static PreparedStatement |
createHeadToken(Connection connection,
EventSchema schema)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.createHeadToken() . |
static PreparedStatement |
createTailToken(Connection connection,
EventSchema schema)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.createTailToken() . |
static PreparedStatement |
createTokenAt(Connection connection,
EventSchema schema,
Instant dateTime)
Build the PreparedStatement to be used on
JdbcEventStorageEngine.createTokenAt(Instant) . |
static PreparedStatement |
deleteSnapshots(Connection connection,
EventSchema schema,
String aggregateIdentifier,
long sequenceNumber)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.storeSnapshot(DomainEventMessage,
Serializer) . |
static PreparedStatement |
fetchTrackedEvents(Connection connection,
EventSchema schema,
long index)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int) . |
static PreparedStatement |
lastSequenceNumberFor(Connection connection,
EventSchema schema,
String aggregateIdentifier)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.lastSequenceNumberFor(String) . |
static PreparedStatement |
readEventDataForAggregate(Connection connection,
EventSchema schema,
String identifier,
long firstSequenceNumber,
int batchSize)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.fetchDomainEvents(String, long, int)
"SELECT [trackedEventFields] FROM [domainEventTable] WHERE [aggregateIdentifierColumn] = ?1 AND
[sequenceNumberColumn] >= ?2 AND [sequenceNumberColumn] < ?3 ORDER BY [sequenceNumberColumn] ASC"
NOTE: "?1" is the identifier, "?2" is the firstSequenceNumber and "?3" is based on batchSize
parameters from JdbcEventStorageEngine.fetchDomainEvents(String, long, int) and they should
always be present for the PreparedStatement to work. |
static PreparedStatement |
readEventDataWithGaps(Connection connection,
EventSchema schema,
long globalIndex,
int batchSize,
List<Long> gaps)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
when there are gaps on the GapAwareTrackingToken . |
static PreparedStatement |
readEventDataWithoutGaps(Connection connection,
EventSchema schema,
long globalIndex,
int batchSize)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
when there is no gaps on the GapAwareTrackingToken . |
static PreparedStatement |
readSnapshotData(Connection connection,
EventSchema schema,
String identifier)
Set the PreparedStatement to be used on
JdbcEventStorageEngine.readSnapshotData(String) . |
public static PreparedStatement createTokenAt(Connection connection, EventSchema schema, Instant dateTime) throws SQLException
JdbcEventStorageEngine.createTokenAt(Instant)
. Defaults to:
"SELECT min([globalIndexColumn]) - 1 FROM [domainEventTable] WHERE [timestampColumn] >= ?"
NOTE: "?" is the Instant parameter from JdbcEventStorageEngine.createTokenAt(Instant)
and should
always be present for the PreparedStatement to work.
connection
- The connection to the database.schema
- The EventSchema to be useddateTime
- The dateTime where the token will be created.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement appendEvents(Connection connection, EventSchema schema, Class<?> dataType, List<? extends EventMessage<?>> events, Serializer serializer, TimestampWriter timestampWriter) throws SQLException
JdbcEventStorageEngine.appendEvents(List, Serializer)
. Defaults
to:
"INSERT INTO [domainEventTable] ([domainEventFields]) VALUES (?,?,?,?,?,?,?,?,?)"
NOTE: each "?" is a domain event field from EventSchema.domainEventFields()
and should
always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be used.dataType
- The serialized type of the payload and metadata.events
- The events to be added.serializer
- The serializer for the payload and metadata.timestampWriter
- Writer responsible for writing timestamp in the correct format for the given database.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.protected static <T> DomainEventMessage<T> asDomainEventMessage(EventMessage<T> event)
EventMessage
to a DomainEventMessage
. If the message already is a DomainEventMessage
it will be returned as is. Otherwise a new GenericDomainEventMessage
is made with
null
type, aggregateIdentifier
equal to messageIdentifier
and sequence number of 0L.
Doing so allows using the DomainEventEntry
to store both a GenericEventMessage
and a GenericDomainEventMessage
.
T
- the type of payload in the messageevent
- the input event messagepublic static PreparedStatement lastSequenceNumberFor(Connection connection, EventSchema schema, String aggregateIdentifier) throws SQLException
JdbcEventStorageEngine.lastSequenceNumberFor(String)
. Defaults
to:
"SELECT max([sequenceNumberColumn]) FROM [domainEventTable] WHERE [aggregateIdentifierColumn] = ?"
NOTE: "?" is the aggregateIdentifier parameter from JdbcEventStorageEngine.lastSequenceNumberFor(String)
and should always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedaggregateIdentifier
- The identifier of the aggregate.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement createTailToken(Connection connection, EventSchema schema) throws SQLException
JdbcEventStorageEngine.createTailToken()
. Defaults to:
"SELECT min([globalIndexColumn]) - 1 FROM [domainEventTable]"
connection
- The connection to the database.schema
- The EventSchema to be usedPreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement createHeadToken(Connection connection, EventSchema schema) throws SQLException
JdbcEventStorageEngine.createHeadToken()
. Defaults to:
"SELECT max([globalIndexColumn]) FROM [domainEventTable]"
connection
- The connection to the database.schema
- The EventSchema to be usedPreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement appendSnapshot(Connection connection, EventSchema schema, Class<?> dataType, DomainEventMessage<?> snapshot, Serializer serializer, TimestampWriter timestampWriter) throws SQLException
JdbcEventStorageEngine.storeSnapshot(DomainEventMessage,
Serializer)
. Defaults to:
"INSERT INTO [snapshotTable] ([domainEventFields]) VALUES (?,?,?,?,?,?,?,?,?)"
NOTE: each "?" is a domain event field from EventSchema.domainEventFields()
and should
always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be used.dataType
- The serialized type of the payload and metadata.snapshot
- The snapshot to be appended.serializer
- The serializer for the payload and metadata.timestampWriter
- Writer responsible for writing timestamp in the correct format for the given database.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement deleteSnapshots(Connection connection, EventSchema schema, String aggregateIdentifier, long sequenceNumber) throws SQLException
JdbcEventStorageEngine.storeSnapshot(DomainEventMessage,
Serializer)
. Defaults to:
"DELETE FROM [snapshotTable] WHERE [aggregateIdentifierColumn] = ?1 AND [sequenceNumberColumn] < ?2"
NOTE: "?1" is the aggregateIdentifier and "?2" is the sequenceNumber parameters taken from the snapshot
from JdbcEventStorageEngine.storeSnapshot(DomainEventMessage, Serializer)
and they should always
be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedaggregateIdentifier
- The identifier of the aggregate taken from the snapshot.sequenceNumber
- The sequence number taken from the snapshot.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement fetchTrackedEvents(Connection connection, EventSchema schema, long index) throws SQLException
JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
.
Defaults to:
"SELECT min([globalIndexColumn]) FROM [domainEventTable] WHERE [globalIndexColumn] > ?"
NOTE: "?" is based on the lastToken parameter from JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken,
int)
and should always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedindex
- The index taken from the tracking token.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement cleanGaps(Connection connection, EventSchema schema, SortedSet<Long> gaps) throws SQLException
"SELECT [globalIndexColumn], [timestampColumn] FROM [domainEventTable] WHERE [globalIndexColumn] >= ?1 AND
[globalIndexColumn] <= ?2"
NOTE: "?1" and "?2" are taken from the GapAwareTrackingToken.getGaps()
first and last.connection
- The connection to the database.schema
- The EventSchema to be usedgaps
- The Set of gaps taken from the tracking token.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement readEventDataForAggregate(Connection connection, EventSchema schema, String identifier, long firstSequenceNumber, int batchSize) throws SQLException
JdbcEventStorageEngine.fetchDomainEvents(String, long, int)
"SELECT [trackedEventFields] FROM [domainEventTable] WHERE [aggregateIdentifierColumn] = ?1 AND
[sequenceNumberColumn] >= ?2 AND [sequenceNumberColumn] < ?3 ORDER BY [sequenceNumberColumn] ASC"
NOTE: "?1" is the identifier, "?2" is the firstSequenceNumber and "?3" is based on batchSize
parameters from JdbcEventStorageEngine.fetchDomainEvents(String, long, int)
and they should
always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedidentifier
- The identifier of the aggregate.firstSequenceNumber
- The expected sequence number of the first returned entry.batchSize
- The number of items to include in the batch.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement readSnapshotData(Connection connection, EventSchema schema, String identifier) throws SQLException
JdbcEventStorageEngine.readSnapshotData(String)
. Defaults to:
"SELECT [domainEventFields] FROM [snapshotTable] WHERE [aggregateIdentifierColumn] = ? ORDER BY
[sequenceNumberColumn] DESC"
NOTE: "?" is the identifier parameter from JdbcEventStorageEngine.readSnapshotData(String)
and should always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedidentifier
- The identifier of the aggregate.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement readEventDataWithoutGaps(Connection connection, EventSchema schema, long globalIndex, int batchSize) throws SQLException
JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
when there is no gaps on the GapAwareTrackingToken
. Defaults to:
"SELECT [trackedEventFields] FROM [domainEventTable] WHERE ([globalIndexColumn] > ?1 AND
[globalIndexColumn] <= ?2) ORDER BY [globalIndexColumn] ASC"
NOTE: "?1" is the globalIndex and "?2" is the batchSize parameters from JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
and they should always be present for the
PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedglobalIndex
- The index taken from the tracking token.batchSize
- The number of items to include in the batchPreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.public static PreparedStatement readEventDataWithGaps(Connection connection, EventSchema schema, long globalIndex, int batchSize, List<Long> gaps) throws SQLException
JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
when there are gaps on the GapAwareTrackingToken
. Defaults to:
"SELECT [trackedEventFields] FROM [domainEventTable] WHERE ([globalIndexColumn] > ?1 AND
[globalIndexColumn] <= ?2) OR [globalIndexColumn] IN (?3 .. ?n) ORDER BY [globalIndexColumn] ASC"
NOTE: "?1" is the globalIndex and "?2" is the batchSize parameters from JdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)
. "?3 .. ?n" is taken from the GapAwareTrackingToken.getGaps()
and they should always be present for the PreparedStatement to work.connection
- The connection to the database.schema
- The EventSchema to be usedglobalIndex
- The index taken from the tracking token.batchSize
- The number of items to include in the batchgaps
- The Set of gaps taken from the tracking token.PreparedStatement
.SQLException
- when an exception occurs while creating the prepared statement.Copyright © 2010–2024. All rights reserved.