org.axonframework.eventstore.jdbc
Class GenericEventSqlSchema<T>

java.lang.Object
  extended by org.axonframework.eventstore.jdbc.GenericEventSqlSchema<T>
Type Parameters:
T - The type used when storing serialized data
All Implemented Interfaces:
EventSqlSchema<T>
Direct Known Subclasses:
PostgresEventSqlSchema

public class GenericEventSqlSchema<T>
extends Object
implements EventSqlSchema<T>

Since:
2.2
Author:
Allard Buijze, Kristian Rosenvold

Field Summary
protected  SchemaConfiguration schemaConfiguration
           
 
Constructor Summary
GenericEventSqlSchema()
          Initialize a GenericEventSqlSchema using default settings.
GenericEventSqlSchema(Class<T> dataType)
          Initialize a GenericEventSqlSchema.
GenericEventSqlSchema(Class<T> dataType, SchemaConfiguration schemaConfiguration)
          Initialize a GenericEventSqlSchema.
 
Method Summary
 SerializedDomainEventData<T> createSerializedDomainEventData(ResultSet resultSet)
          Reads the current entry of the ResultSet into a SerializedDomainEventData.
protected  PreparedStatement doInsertEventEntry(String tableName, Connection connection, String eventIdentifier, String aggregateIdentifier, long sequenceNumber, org.joda.time.DateTime timestamp, String eventType, String eventRevision, T eventPayload, T eventMetaData, String aggregateType)
          Creates a statement to insert an entry with given attributes in the given tableName.
 Class<T> getDataType()
          Returns the type used to store serialized payloads.
protected  T readPayload(ResultSet resultSet, int columnIndex)
          Reads a serialized object from the given resultSet at given columnIndex.
protected  Object readTimeStamp(ResultSet resultSet, int columnIndex)
          Reads a timestamp from the given resultSet at given columnIndex.
 void setForceUtc(boolean forceUtc)
          Control if date time in the SQL scheme should use UTC time zone or system local time zone.
 PreparedStatement sql_createDomainEventEntryTable(Connection connection)
          Creates a PreparedStatement that allows for the creation of the table to store Event entries.
 PreparedStatement sql_createSnapshotEventEntryTable(Connection connection)
          Creates a PreparedStatement that allows for the creation of the table to store Snapshots.
 String sql_dateTime(org.joda.time.DateTime input)
          Converts a DateTime to a data value suitable for the database scheme.
 PreparedStatement sql_fetchFromSequenceNumber(Connection connection, String type, Object aggregateIdentifier, long firstSequenceNumber)
          Creates a PreparedStatement that fetches event data for an aggregate with given type and identifier, starting at the given firstSequenceNumber.
 PreparedStatement sql_findSnapshotSequenceNumbers(Connection connection, String type, Object aggregateIdentifier)
          Creates a PreparedStatement that returns the sequence numbers of snapshots for an aggregate of given type and aggregateIdentifier.
 PreparedStatement sql_getFetchAll(Connection connection, String whereClause, Object[] params)
          Creates a PreparedStatement that fetches all event messages matching the given whereClause.
 PreparedStatement sql_insertDomainEventEntry(Connection conn, String eventIdentifier, String aggregateIdentifier, long sequenceNumber, org.joda.time.DateTime timestamp, String eventType, String eventRevision, T eventPayload, T eventMetaData, String aggregateType)
          Creates the PreparedStatement for inserting a DomainEvent in the Event Store, using given attributes.
 PreparedStatement sql_insertSnapshotEventEntry(Connection conn, String eventIdentifier, String aggregateIdentifier, long sequenceNumber, org.joda.time.DateTime timestamp, String eventType, String eventRevision, T eventPayload, T eventMetaData, String aggregateType)
          Creates the PreparedStatement for inserting a Snapshot Event in the Event Store, using given attributes.
 PreparedStatement sql_loadLastSnapshot(Connection connection, Object identifier, String aggregateType)
          Creates the PreparedStatement for loading the last snapshot event for an aggregate with given identifier and of given aggregateType.
 PreparedStatement sql_pruneSnapshots(Connection connection, String type, Object aggregateIdentifier, long sequenceOfFirstSnapshotToPrune)
          Creates a PreparedStatement that deletes all snapshots with a sequence identifier equal or lower to the given sequenceOfFirstSnapshotToPrune, for an aggregate of given type and aggregateIdentifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

schemaConfiguration

protected SchemaConfiguration schemaConfiguration
Constructor Detail

GenericEventSqlSchema

public GenericEventSqlSchema()
Initialize a GenericEventSqlSchema using default settings.

Serialized data is stored as byte arrays. Data is stored in a default SchemaConfiguration.


GenericEventSqlSchema

public GenericEventSqlSchema(Class<T> dataType)
Initialize a GenericEventSqlSchema.

Serialized data is stored using the given dataType. Data is stored in a default SchemaConfiguration.

Parameters:
dataType - The type to use when storing serialized data

GenericEventSqlSchema

public GenericEventSqlSchema(Class<T> dataType,
                             SchemaConfiguration schemaConfiguration)
Initialize a GenericEventSqlSchema.

Serialized data is stored using the given dataType. Data is stored according to the given SchemaConfiguration.

Parameters:
dataType -
schemaConfiguration -
Method Detail

setForceUtc

public void setForceUtc(boolean forceUtc)
Control if date time in the SQL scheme should use UTC time zone or system local time zone.

Default is to use system local time zone.

You should not change this after going into production, since it would affect the batching iterator when fetching events.

Parameters:
forceUtc - set true to force all date times to use UTC time zone

sql_loadLastSnapshot

public PreparedStatement sql_loadLastSnapshot(Connection connection,
                                              Object identifier,
                                              String aggregateType)
                                       throws SQLException
Description copied from interface: EventSqlSchema
Creates the PreparedStatement for loading the last snapshot event for an aggregate with given identifier and of given aggregateType.

Specified by:
sql_loadLastSnapshot in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
identifier - The identifier of the aggregate to find the snapshot for
aggregateType - The type identifier of the aggregate
Returns:
a PreparedStatement with all parameters set
Throws:
SQLException - when an exception occurs while creating the prepared statement

sql_insertDomainEventEntry

public PreparedStatement sql_insertDomainEventEntry(Connection conn,
                                                    String eventIdentifier,
                                                    String aggregateIdentifier,
                                                    long sequenceNumber,
                                                    org.joda.time.DateTime timestamp,
                                                    String eventType,
                                                    String eventRevision,
                                                    T eventPayload,
                                                    T eventMetaData,
                                                    String aggregateType)
                                             throws SQLException
Description copied from interface: EventSqlSchema
Creates the PreparedStatement for inserting a DomainEvent in the Event Store, using given attributes.

Specified by:
sql_insertDomainEventEntry in interface EventSqlSchema<T>
Parameters:
conn - The connection to create the PreparedStatement for
eventIdentifier - The unique identifier of the event
aggregateIdentifier - The identifier of the aggregate that generated the event
sequenceNumber - The sequence number of the event
timestamp - The time at which the Event Message was generated
eventType - The type identifier of the serialized event
eventRevision - The revision of the serialized event
eventPayload - The serialized payload of the Event
eventMetaData - The serialized meta data of the event
aggregateType - The type identifier of the aggregate the event belongs to
Returns:
a PreparedStatement with all parameters set
Throws:
SQLException - when an exception occurs while creating the prepared statement

sql_insertSnapshotEventEntry

public PreparedStatement sql_insertSnapshotEventEntry(Connection conn,
                                                      String eventIdentifier,
                                                      String aggregateIdentifier,
                                                      long sequenceNumber,
                                                      org.joda.time.DateTime timestamp,
                                                      String eventType,
                                                      String eventRevision,
                                                      T eventPayload,
                                                      T eventMetaData,
                                                      String aggregateType)
                                               throws SQLException
Description copied from interface: EventSqlSchema
Creates the PreparedStatement for inserting a Snapshot Event in the Event Store, using given attributes.

Specified by:
sql_insertSnapshotEventEntry in interface EventSqlSchema<T>
Parameters:
conn - The connection to create the PreparedStatement for
eventIdentifier - The unique identifier of the event
aggregateIdentifier - The identifier of the aggregate that generated the event
sequenceNumber - The sequence number of the event
timestamp - The time at which the Event Message was generated
eventType - The type identifier of the serialized event
eventRevision - The revision of the serialized event
eventPayload - The serialized payload of the Event
eventMetaData - The serialized meta data of the event
aggregateType - The type identifier of the aggregate the event belongs to
Returns:
a PreparedStatement with all parameters set
Throws:
SQLException - when an exception occurs while creating the prepared statement

doInsertEventEntry

protected PreparedStatement doInsertEventEntry(String tableName,
                                               Connection connection,
                                               String eventIdentifier,
                                               String aggregateIdentifier,
                                               long sequenceNumber,
                                               org.joda.time.DateTime timestamp,
                                               String eventType,
                                               String eventRevision,
                                               T eventPayload,
                                               T eventMetaData,
                                               String aggregateType)
                                        throws SQLException
Creates a statement to insert an entry with given attributes in the given tableName. This method is used by sql_insertDomainEventEntry(java.sql.Connection, String, String, long, org.joda.time.DateTime, String, String, Object, Object, String) and sql_insertSnapshotEventEntry(java.sql.Connection, String, String, long, org.joda.time.DateTime, String, String, Object, Object, String), and provides an easier way to change to types of columns used.

Parameters:
tableName - The name of the table to insert the entry into
connection - The connection to create the statement for
eventIdentifier - The unique identifier of the event
aggregateIdentifier - The identifier of the aggregate that generated the event
sequenceNumber - The sequence number of the event
timestamp - The time at which the Event Message was generated
eventType - The type identifier of the serialized event
eventRevision - The revision of the serialized event
eventPayload - The serialized payload of the Event
eventMetaData - The serialized meta data of the event
aggregateType - The type identifier of the aggregate the event belongs to
Returns:
a prepared statement that allows inserting a domain event entry when executed
Throws:
SQLException - when an exception occurs creating the PreparedStatement

sql_pruneSnapshots

public PreparedStatement sql_pruneSnapshots(Connection connection,
                                            String type,
                                            Object aggregateIdentifier,
                                            long sequenceOfFirstSnapshotToPrune)
                                     throws SQLException
Description copied from interface: EventSqlSchema
Creates a PreparedStatement that deletes all snapshots with a sequence identifier equal or lower to the given sequenceOfFirstSnapshotToPrune, for an aggregate of given type and aggregateIdentifier.

Specified by:
sql_pruneSnapshots in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
type - The type identifier of the aggregate
aggregateIdentifier - The identifier of the aggregate
sequenceOfFirstSnapshotToPrune - The sequence number of the most recent snapshot to prune
Returns:
The PreparedStatement, ready to execute
Throws:
SQLException - when an exception occurs while creating the prepared statement

sql_findSnapshotSequenceNumbers

public PreparedStatement sql_findSnapshotSequenceNumbers(Connection connection,
                                                         String type,
                                                         Object aggregateIdentifier)
                                                  throws SQLException
Description copied from interface: EventSqlSchema
Creates a PreparedStatement that returns the sequence numbers of snapshots for an aggregate of given type and aggregateIdentifier.

Specified by:
sql_findSnapshotSequenceNumbers in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
type - The type identifier of the aggregate
aggregateIdentifier - The identifier of the aggregate
Returns:
The PreparedStatement, ready to execute, returning a single column with longs.
Throws:
SQLException - when an exception occurs while creating the prepared statement

sql_fetchFromSequenceNumber

public PreparedStatement sql_fetchFromSequenceNumber(Connection connection,
                                                     String type,
                                                     Object aggregateIdentifier,
                                                     long firstSequenceNumber)
                                              throws SQLException
Description copied from interface: EventSqlSchema
Creates a PreparedStatement that fetches event data for an aggregate with given type and identifier, starting at the given firstSequenceNumber.

Specified by:
sql_fetchFromSequenceNumber in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
type - The type identifier of the aggregate
aggregateIdentifier - The identifier of the aggregate
firstSequenceNumber - The sequence number of the first event to return
Returns:
a PreparedStatement that returns columns that can be converted using EventSqlSchema.createSerializedDomainEventData(java.sql.ResultSet)
Throws:
SQLException - when an exception occurs while creating the prepared statement

sql_getFetchAll

public PreparedStatement sql_getFetchAll(Connection connection,
                                         String whereClause,
                                         Object[] params)
                                  throws SQLException
Description copied from interface: EventSqlSchema
Creates a PreparedStatement that fetches all event messages matching the given whereClause. The given parameters provide the parameters used in the where clause, in the order of declaration.

Specified by:
sql_getFetchAll in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
whereClause - The SQL snippet to use after the WHERE directive. May be null or an empty String to indicate that no filter is to be applied
params - The parameters to set in the WHERE clause
Returns:
a PreparedStatement that returns columns that can be converted using EventSqlSchema.createSerializedDomainEventData(java.sql.ResultSet)
Throws:
SQLException - when an exception occurs while creating the prepared statement

readTimeStamp

protected Object readTimeStamp(ResultSet resultSet,
                               int columnIndex)
                        throws SQLException
Reads a timestamp from the given resultSet at given columnIndex. The resultSet is positioned in the row that contains the data. This method must not change the row in the result set.

Parameters:
resultSet - The resultSet containing the stored data
columnIndex - The column containing the timestamp
Returns:
an object describing the timestamp
Throws:
SQLException - when an exception occurs reading from the resultSet.

readPayload

protected T readPayload(ResultSet resultSet,
                        int columnIndex)
                 throws SQLException
Reads a serialized object from the given resultSet at given columnIndex. The resultSet is positioned in the row that contains the data. This method must not change the row in the result set.

Parameters:
resultSet - The resultSet containing the stored data
columnIndex - The column containing the timestamp
Returns:
an object describing the serialized data
Throws:
SQLException - when an exception occurs reading from the resultSet.

sql_createSnapshotEventEntryTable

public PreparedStatement sql_createSnapshotEventEntryTable(Connection connection)
                                                    throws SQLException
Description copied from interface: EventSqlSchema
Creates a PreparedStatement that allows for the creation of the table to store Snapshots.

Specified by:
sql_createSnapshotEventEntryTable in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
Returns:
The Prepared Statement, ready to be executed
Throws:
SQLException - when an exception occurs while creating the prepared statement

sql_createDomainEventEntryTable

public PreparedStatement sql_createDomainEventEntryTable(Connection connection)
                                                  throws SQLException
Description copied from interface: EventSqlSchema
Creates a PreparedStatement that allows for the creation of the table to store Event entries.

Specified by:
sql_createDomainEventEntryTable in interface EventSqlSchema<T>
Parameters:
connection - The connection to create the PreparedStatement for
Returns:
The Prepared Statement, ready to be executed
Throws:
SQLException - when an exception occurs while creating the prepared statement

createSerializedDomainEventData

public SerializedDomainEventData<T> createSerializedDomainEventData(ResultSet resultSet)
                                                             throws SQLException
Description copied from interface: EventSqlSchema
Reads the current entry of the ResultSet into a SerializedDomainEventData.

Note: the implementation *must* not change the ResultSet's cursor position.

Specified by:
createSerializedDomainEventData in interface EventSqlSchema<T>
Parameters:
resultSet - The result set returned from executing one of the Prepared Statements declared on this interface
Returns:
a single SerializedDomainEventData instance
Throws:
SQLException - when an exception occurs while creating the prepared statement
See Also:
SimpleSerializedDomainEventData

sql_dateTime

public String sql_dateTime(org.joda.time.DateTime input)
Description copied from interface: EventSqlSchema
Converts a DateTime to a data value suitable for the database scheme.

Specified by:
sql_dateTime in interface EventSqlSchema<T>
Parameters:
input - DateTime to convert
Returns:
data representing the date time suitable for the current SQL scheme

getDataType

public Class<T> getDataType()
Description copied from interface: EventSqlSchema
Returns the type used to store serialized payloads.

Specified by:
getDataType in interface EventSqlSchema<T>
Returns:
the type used to store serialized payloads


Copyright © 2010-2016. All Rights Reserved.