Class JdbcEventStorageEngineStatements
java.lang.Object
org.axonframework.eventsourcing.eventstore.jdbc.statements.JdbcEventStorageEngineStatements
Class which holds the default
PreparedStatement builder methods for use in the JdbcEventStorageEngine.- Since:
- 4.3
- Author:
- Lucas Campos
-
Method Summary
Modifier and TypeMethodDescriptionstatic PreparedStatementappendEvents(Connection connection, EventSchema schema, Class<?> dataType, List<? extends EventMessage<?>> events, Serializer serializer, TimestampWriter timestampWriter) Set the PreparedStatement to be used onJdbcEventStorageEngine.appendEvents(List, Serializer).static PreparedStatementappendSnapshot(Connection connection, EventSchema schema, Class<?> dataType, DomainEventMessage<?> snapshot, Serializer serializer, TimestampWriter timestampWriter) Set the PreparedStatement to be used onJdbcEventStorageEngine.storeSnapshot(DomainEventMessage, Serializer).protected static <T> DomainEventMessage<T> asDomainEventMessage(EventMessage<T> event) Converts anEventMessageto aDomainEventMessage.static PreparedStatementcleanGaps(Connection connection, EventSchema schema, SortedSet<Long> gaps) Set the PreparedStatement to be used on internal cleanGaps operation.static PreparedStatementcreateHeadToken(Connection connection, EventSchema schema) Set the PreparedStatement to be used onJdbcEventStorageEngine.createHeadToken().static PreparedStatementcreateTailToken(Connection connection, EventSchema schema) Set the PreparedStatement to be used onJdbcEventStorageEngine.createTailToken().static PreparedStatementcreateTokenAt(Connection connection, EventSchema schema, Instant dateTime) Build the PreparedStatement to be used onJdbcEventStorageEngine.createTokenAt(Instant).static PreparedStatementdeleteSnapshots(Connection connection, EventSchema schema, String aggregateIdentifier, long sequenceNumber) Set the PreparedStatement to be used onJdbcEventStorageEngine.storeSnapshot(DomainEventMessage, Serializer).static PreparedStatementfetchTrackedEvents(Connection connection, EventSchema schema, long index) Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int).static PreparedStatementlastSequenceNumberFor(Connection connection, EventSchema schema, String aggregateIdentifier) Set the PreparedStatement to be used onJdbcEventStorageEngine.lastSequenceNumberFor(String).static PreparedStatementreadEventDataForAggregate(Connection connection, EventSchema schema, String identifier, long firstSequenceNumber, int batchSize) Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchDomainEvents(String, long, int)static PreparedStatementreadEventDataWithGaps(Connection connection, EventSchema schema, long globalIndex, int batchSize, List<Long> gaps) Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)when there are gaps on theGapAwareTrackingToken.static PreparedStatementreadEventDataWithoutGaps(Connection connection, EventSchema schema, long globalIndex, int batchSize) Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)when there is no gaps on theGapAwareTrackingToken.static PreparedStatementreadSnapshotData(Connection connection, EventSchema schema, String identifier) Set the PreparedStatement to be used onJdbcEventStorageEngine.readSnapshotData(String).
-
Method Details
-
createTokenAt
public static PreparedStatement createTokenAt(Connection connection, EventSchema schema, Instant dateTime) throws SQLException Build the PreparedStatement to be used onJdbcEventStorageEngine.createTokenAt(Instant). Defaults to:"SELECT min([globalIndexColumn]) - 1 FROM [domainEventTable] WHERE [timestampColumn] >= ?"NOTE: "?" is the Instant parameter fromJdbcEventStorageEngine.createTokenAt(Instant)and should always be present for the PreparedStatement to work.- Parameters:
connection- The connection to the database.schema- The EventSchema to be useddateTime- The dateTime where the token will be created.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
appendEvents
public static PreparedStatement appendEvents(Connection connection, EventSchema schema, Class<?> dataType, List<? extends EventMessage<?>> events, Serializer serializer, TimestampWriter timestampWriter) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.appendEvents(List, Serializer). Defaults to:"INSERT INTO [domainEventTable] ([domainEventFields]) VALUES (?,?,?,?,?,?,?,?,?)"NOTE: each "?" is a domain event field fromEventSchema.domainEventFields()and should always be present for the PreparedStatement to work.- Parameters:
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.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
asDomainEventMessage
Converts anEventMessageto aDomainEventMessage. If the message already is aDomainEventMessageit will be returned as is. Otherwise a newGenericDomainEventMessageis made withnulltype,aggregateIdentifierequal tomessageIdentifierand sequence number of 0L.Doing so allows using the
DomainEventEntryto store both aGenericEventMessageand aGenericDomainEventMessage.- Type Parameters:
T- the type of payload in the message- Parameters:
event- the input event message- Returns:
- the message converted to a domain event message
-
lastSequenceNumberFor
public static PreparedStatement lastSequenceNumberFor(Connection connection, EventSchema schema, String aggregateIdentifier) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.lastSequenceNumberFor(String). Defaults to:"SELECT max([sequenceNumberColumn]) FROM [domainEventTable] WHERE [aggregateIdentifierColumn] = ?"NOTE: "?" is the aggregateIdentifier parameter fromJdbcEventStorageEngine.lastSequenceNumberFor(String)and should always be present for the PreparedStatement to work.- Parameters:
connection- The connection to the database.schema- The EventSchema to be usedaggregateIdentifier- The identifier of the aggregate.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
createTailToken
public static PreparedStatement createTailToken(Connection connection, EventSchema schema) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.createTailToken(). Defaults to:"SELECT min([globalIndexColumn]) - 1 FROM [domainEventTable]"- Parameters:
connection- The connection to the database.schema- The EventSchema to be used- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
createHeadToken
public static PreparedStatement createHeadToken(Connection connection, EventSchema schema) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.createHeadToken(). Defaults to:"SELECT max([globalIndexColumn]) FROM [domainEventTable]"- Parameters:
connection- The connection to the database.schema- The EventSchema to be used- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
appendSnapshot
public static PreparedStatement appendSnapshot(Connection connection, EventSchema schema, Class<?> dataType, DomainEventMessage<?> snapshot, Serializer serializer, TimestampWriter timestampWriter) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.storeSnapshot(DomainEventMessage, Serializer). Defaults to:"INSERT INTO [snapshotTable] ([domainEventFields]) VALUES (?,?,?,?,?,?,?,?,?)"NOTE: each "?" is a domain event field fromEventSchema.domainEventFields()and should always be present for the PreparedStatement to work.- Parameters:
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.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
deleteSnapshots
public static PreparedStatement deleteSnapshots(Connection connection, EventSchema schema, String aggregateIdentifier, long sequenceNumber) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.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 fromJdbcEventStorageEngine.storeSnapshot(DomainEventMessage, Serializer)and they should always be present for the PreparedStatement to work.- Parameters:
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.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
fetchTrackedEvents
public static PreparedStatement fetchTrackedEvents(Connection connection, EventSchema schema, long index) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int). Defaults to:"SELECT min([globalIndexColumn]) FROM [domainEventTable] WHERE [globalIndexColumn] > ?"NOTE: "?" is based on the lastToken parameter fromJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)and should always be present for the PreparedStatement to work.- Parameters:
connection- The connection to the database.schema- The EventSchema to be usedindex- The index taken from the tracking token.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
cleanGaps
public static PreparedStatement cleanGaps(Connection connection, EventSchema schema, SortedSet<Long> gaps) throws SQLException Set the PreparedStatement to be used on internal cleanGaps operation. Defaults to:"SELECT [globalIndexColumn], [timestampColumn] FROM [domainEventTable] WHERE [globalIndexColumn] >= ?1 AND [globalIndexColumn] <= ?2"NOTE: "?1" and "?2" are taken from theGapAwareTrackingToken.getGaps()first and last.- Parameters:
connection- The connection to the database.schema- The EventSchema to be usedgaps- The Set of gaps taken from the tracking token.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
readEventDataForAggregate
public static PreparedStatement readEventDataForAggregate(Connection connection, EventSchema schema, String identifier, long firstSequenceNumber, int batchSize) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.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 fromJdbcEventStorageEngine.fetchDomainEvents(String, long, int)and they should always be present for the PreparedStatement to work.- Parameters:
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.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
readSnapshotData
public static PreparedStatement readSnapshotData(Connection connection, EventSchema schema, String identifier) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.readSnapshotData(String). Defaults to:"SELECT [domainEventFields] FROM [snapshotTable] WHERE [aggregateIdentifierColumn] = ? ORDER BY [sequenceNumberColumn] DESC"NOTE: "?" is the identifier parameter fromJdbcEventStorageEngine.readSnapshotData(String)and should always be present for the PreparedStatement to work.- Parameters:
connection- The connection to the database.schema- The EventSchema to be usedidentifier- The identifier of the aggregate.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
readEventDataWithoutGaps
public static PreparedStatement readEventDataWithoutGaps(Connection connection, EventSchema schema, long globalIndex, int batchSize) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)when there is no gaps on theGapAwareTrackingToken. 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 fromJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)and they should always be present for the PreparedStatement to work.- Parameters:
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 batch- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-
readEventDataWithGaps
public static PreparedStatement readEventDataWithGaps(Connection connection, EventSchema schema, long globalIndex, int batchSize, List<Long> gaps) throws SQLException Set the PreparedStatement to be used onJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int)when there are gaps on theGapAwareTrackingToken. 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 fromJdbcEventStorageEngine.fetchTrackedEvents(TrackingToken, int). "?3 .. ?n" is taken from theGapAwareTrackingToken.getGaps()and they should always be present for the PreparedStatement to work.- Parameters:
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.- Returns:
- The newly created
PreparedStatement. - Throws:
SQLException- when an exception occurs while creating the prepared statement.
-