Tabnine Logo
EventSchema
Code IndexAdd Tabnine to your IDE (free)

How to use
EventSchema
in
org.axonframework.eventsourcing.eventstore.jdbc

Best Java code snippets using org.axonframework.eventsourcing.eventstore.jdbc.EventSchema (Showing top 20 results out of 315)

origin: AxonFramework/AxonFramework

  /**
   * Builds a new {@link EventSchema} from builder values.
   *
   * @return new EventSchema
   */
  public EventSchema build() {
    return new EventSchema(this);
  }
}
origin: AxonFramework/AxonFramework

@Override
public PreparedStatement createDomainEventTable(Connection connection,
                        EventSchema schema) throws SQLException {
  String sql = "CREATE TABLE IF NOT EXISTS " + schema.domainEventTable() + " (\n" +
      schema.globalIndexColumn() + " " + idColumnType() + " NOT NULL,\n" +
      schema.aggregateIdentifierColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.sequenceNumberColumn() + " BIGINT NOT NULL,\n" +
      schema.typeColumn() + " VARCHAR(255),\n" +
      schema.eventIdentifierColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.metaDataColumn() + " " + payloadType() + ",\n" +
      schema.payloadColumn() + " " + payloadType() + " NOT NULL,\n" +
      schema.payloadRevisionColumn() + " VARCHAR(255),\n" +
      schema.payloadTypeColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.timestampColumn() + " VARCHAR(255) NOT NULL,\n" +
      "PRIMARY KEY (" + schema.globalIndexColumn() + "),\n" +
      "UNIQUE (" + schema.aggregateIdentifierColumn() + ", " +
      schema.sequenceNumberColumn() + "),\n" +
      "UNIQUE (" + schema.eventIdentifierColumn() + ")\n" +
      ")";
  return connection.prepareStatement(sql);
}
origin: AxonFramework/AxonFramework

/**
 * Creates a statement to delete all snapshots of the aggregate with given {@code aggregateIdentifier}.
 *
 * @param connection          The connection to the database.
 * @param aggregateIdentifier The identifier of the aggregate whose snapshots to delete.
 * @return A {@link PreparedStatement} that deletes all the aggregate's snapshots when executed.
 *
 * @throws SQLException when an exception occurs while creating the prepared statement.
 */
protected PreparedStatement deleteSnapshots(Connection connection, String aggregateIdentifier, long sequenceNumber)
    throws SQLException {
  PreparedStatement preparedStatement = connection.prepareStatement(
      "DELETE FROM " + schema.snapshotTable() + " WHERE " + schema.aggregateIdentifierColumn() + " = ? "
          + "AND " + schema.sequenceNumberColumn() + " < ?"
  );
  preparedStatement.setString(1, aggregateIdentifier);
  preparedStatement.setLong(2, sequenceNumber);
  return preparedStatement;
}
origin: AxonFramework/AxonFramework

/**
 * Returns a comma separated list of domain event column names to select from an event or snapshot entry.
 *
 * @return comma separated domain event column names.
 */
protected String domainEventFields() {
  return String.join(", ", schema.eventIdentifierColumn(), schema.timestampColumn(), schema.payloadTypeColumn(),
            schema.payloadRevisionColumn(), schema.payloadColumn(), schema.metaDataColumn(),
            schema.typeColumn(), schema.aggregateIdentifierColumn(), schema.sequenceNumberColumn());
}
origin: AxonFramework/AxonFramework

/**
 * Creates a statement to read domain event entries for an aggregate with given identifier starting with the first
 * entry having a sequence number that is equal or larger than the given {@code firstSequenceNumber}.
 *
 * @param connection          The connection to the database.
 * @param identifier          The identifier of the aggregate.
 * @param firstSequenceNumber The expected sequence number of the first returned entry.
 * @param batchSize           The number of items to include in the batch
 * @return A {@link PreparedStatement} that returns event entries for the given query when executed.
 *
 * @throws SQLException when an exception occurs while creating the prepared statement.
 */
protected PreparedStatement readEventData(Connection connection, String identifier,
                     long firstSequenceNumber, int batchSize) throws SQLException {
  Transaction tx = transactionManager.startTransaction();
  try {
    final String sql = "SELECT " + trackedEventFields() + " FROM " + schema.domainEventTable() + " WHERE " +
        schema.aggregateIdentifierColumn() + " = ? AND " + schema.sequenceNumberColumn() + " >= ? AND " +
        schema.sequenceNumberColumn() + " < ? ORDER BY " + schema.sequenceNumberColumn() + " ASC";
    PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString(1, identifier);
    preparedStatement.setLong(2, firstSequenceNumber);
    preparedStatement.setLong(3, firstSequenceNumber + batchSize);
    return preparedStatement;
  } finally {
    tx.commit();
  }
}
origin: AxonFramework/AxonFramework

@Override
public TrackingToken createTailToken() {
  String sql = "SELECT min(" + schema.globalIndexColumn() + ") - 1 FROM " + schema.domainEventTable();
  Long index = transactionManager.fetchInTransaction(
      () -> executeQuery(getConnection(),
                connection -> connection.prepareStatement(sql),
                resultSet -> nextAndExtract(resultSet, 1, Long.class),
                e -> new EventStoreException("Failed to get tail token", e)));
  return Optional.ofNullable(index)
          .map(seq -> GapAwareTrackingToken.newInstance(seq, Collections.emptySet()))
          .orElse(null);
}
origin: AxonFramework/AxonFramework

PreparedStatement statement =
    conn.prepareStatement(format("SELECT %s, %s FROM %s WHERE %s >= ? AND %s <= ?",
                   schema.globalIndexColumn(),
                   schema.timestampColumn(),
                   schema.domainEventTable(),
                   schema.globalIndexColumn(),
                   schema.globalIndexColumn()));
statement.setLong(1, gaps.first());
statement.setLong(2, gaps.last() + 1L);
while (resultSet.next()) {
  try {
    long sequenceNumber = resultSet.getLong(schema.globalIndexColumn());
    Instant timestamp =
        DateTimeUtils.parseInstant(readTimeStamp(resultSet, schema.timestampColumn()).toString());
    if (gaps.contains(sequenceNumber) || timestamp.isAfter(gapTimeoutFrame())) {
origin: AxonFramework/AxonFramework

@Test
public void testCreateDomainEventTable() throws Exception {
  // test passes if no exception is thrown
  testSubject.createDomainEventTable(connection, eventSchema)
      .execute();
  connection.prepareStatement("SELECT * FROM " + eventSchema.domainEventTable())
      .execute();
  connection.prepareStatement("DROP TABLE " + eventSchema.domainEventTable())
      .execute();
  connection.prepareStatement("DROP SEQUENCE " + eventSchema.domainEventTable() + "_seq")
      .execute();
}
origin: AxonFramework/AxonFramework

  @Test
  public void testCreateSnapshotEventTable() throws Exception {
    // test passes if no exception is thrown
    testSubject.createSnapshotEventTable(connection, eventSchema)
        .execute();
    connection.prepareStatement("SELECT * FROM " + eventSchema.snapshotTable())
        .execute();

    connection.prepareStatement("DROP TABLE " + eventSchema.snapshotTable())
        .execute();
  }
}
origin: AxonFramework/AxonFramework

/**
 * Returns a comma separated list of tracked domain event column names to select from an event entry.
 *
 * @return comma separated tracked domain event column names.
 */
protected String trackedEventFields() {
  return schema.globalIndexColumn() + ", " + domainEventFields();
}
origin: AxonFramework/AxonFramework

/**
 * Initializes the default Event Schema
 */
public EventSchema() {
  this(builder());
}
origin: AxonFramework/AxonFramework

@Override
public TrackingToken createHeadToken() {
  String sql = "SELECT max(" + schema.globalIndexColumn() + ") FROM " + schema.domainEventTable();
  Long index = transactionManager.fetchInTransaction(
      () -> executeQuery(getConnection(),
                connection -> connection.prepareStatement(sql),
                resultSet -> nextAndExtract(resultSet, 1, Long.class),
                e -> new EventStoreException("Failed to get head token", e)));
  return Optional.ofNullable(index)
          .map(seq -> GapAwareTrackingToken.newInstance(seq, Collections.emptySet()))
          .orElse(null);
}
origin: AxonFramework/AxonFramework

@Override
public Optional<Long> lastSequenceNumberFor(String aggregateIdentifier) {
  String sql = "SELECT max(" + schema.sequenceNumberColumn() + ") FROM " + schema.domainEventTable() +
      " WHERE " + schema.aggregateIdentifierColumn() + " = ?";
  return Optional.ofNullable(transactionManager.fetchInTransaction(
      () -> executeQuery(getConnection(), connection -> {
                  PreparedStatement stmt = connection.prepareStatement(sql);
                  stmt.setString(1, aggregateIdentifier);
                  return stmt;
                },
                resultSet -> nextAndExtract(resultSet, 1, Long.class),
                e -> new EventStoreException(
                    format("Failed to read events for aggregate [%s]", aggregateIdentifier), e
                )
      )));
}
origin: AxonFramework/AxonFramework

@Override
public TrackingToken createTokenAt(Instant dateTime) {
  String sql = "SELECT min(" + schema.globalIndexColumn() + ") - 1 FROM " + schema.domainEventTable() + " WHERE "
      + schema.timestampColumn() + " >= ?";
  Long index = transactionManager.fetchInTransaction(
      () -> executeQuery(getConnection(),
                connection -> {
                  PreparedStatement stmt = connection.prepareStatement(sql);
                  stmt.setString(1, formatInstant(dateTime));
                  return stmt;
                },
                resultSet -> nextAndExtract(resultSet, 1, Long.class),
                e -> new EventStoreException(format("Failed to get token at [%s]", dateTime), e)));
  if (index == null) {
    return null;
  }
  return GapAwareTrackingToken.newInstance(index, Collections.emptySet());
}
origin: org.axonframework/axon-core

/**
 * Returns a comma separated list of tracked domain event column names to select from an event entry.
 *
 * @return comma separated tracked domain event column names.
 */
protected String trackedEventFields() {
  return schema.globalIndexColumn() + ", " + domainEventFields();
}
origin: org.axonframework/axon-core

/**
 * Initializes the default Event Schema
 */
public EventSchema() {
  this(builder());
}
origin: AxonFramework/AxonFramework

@Override
public PreparedStatement createSnapshotEventTable(Connection connection, EventSchema schema) throws SQLException {
  String sql = "CREATE TABLE " + schema.snapshotTable() + " (\n" +
      schema.aggregateIdentifierColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.sequenceNumberColumn() + " NUMBER(19) NOT NULL,\n" +
      schema.typeColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.eventIdentifierColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.metaDataColumn() + " " + payloadType() + ",\n" +
      schema.payloadColumn() + " " + payloadType() + " NOT NULL,\n" +
      schema.payloadRevisionColumn() + " VARCHAR(255),\n" +
      schema.payloadTypeColumn() + " VARCHAR(255) NOT NULL,\n" +
      schema.timestampColumn() + " VARCHAR(255) NOT NULL,\n" +
      "PRIMARY KEY (" + schema.aggregateIdentifierColumn() + ", " +
      schema.sequenceNumberColumn() + "),\n" +
      "UNIQUE (" + schema.eventIdentifierColumn() + ")\n" +
      ")";
  return connection.prepareStatement(sql);
}
origin: AxonFramework/AxonFramework

    () -> format("Token [%s] is of the wrong type", lastToken));
GapAwareTrackingToken previousToken = (GapAwareTrackingToken) lastToken;
String sql = "SELECT " + trackedEventFields() + " FROM " + schema.domainEventTable() +
    " WHERE (" + schema.globalIndexColumn() + " > ? AND " + schema.globalIndexColumn() + " <= ?) ";
List<Long> gaps;
if (previousToken != null) {
  gaps = new ArrayList<>(previousToken.getGaps());
  if (!gaps.isEmpty()) {
    sql += " OR " + schema.globalIndexColumn() + " IN (" +
        String.join(",", Collections.nCopies(gaps.size(), "?")) + ") ";
  gaps = Collections.emptyList();
sql += "ORDER BY " + schema.globalIndexColumn() + " ASC";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
long globalIndex = previousToken == null ? -1 : previousToken.getIndex();
origin: AxonFramework/AxonFramework

/**
 * Creates a statement to read the snapshot entry of an aggregate with given identifier.
 *
 * @param connection The connection to the database.
 * @param identifier The aggregate identifier.
 * @return A {@link PreparedStatement} that returns the last snapshot entry of the aggregate (if any) when executed.
 *
 * @throws SQLException when an exception occurs while creating the prepared statement.
 */
protected PreparedStatement readSnapshotData(Connection connection, String identifier) throws SQLException {
  final String s = "SELECT " + domainEventFields() + " FROM " + schema.snapshotTable() + " WHERE " +
      schema.aggregateIdentifierColumn() + " = ? ORDER BY " + schema.sequenceNumberColumn() + " DESC";
  PreparedStatement statement = connection.prepareStatement(s);
  statement.setString(1, identifier);
  return statement;
}
origin: org.axonframework/axon-core

/**
 * Creates a statement to read domain event entries for an aggregate with given identifier starting with the first
 * entry having a sequence number that is equal or larger than the given {@code firstSequenceNumber}.
 *
 * @param connection          The connection to the database.
 * @param identifier          The identifier of the aggregate.
 * @param firstSequenceNumber The expected sequence number of the first returned entry.
 * @param batchSize           The number of items to include in the batch
 * @return A {@link PreparedStatement} that returns event entries for the given query when executed.
 * @throws SQLException when an exception occurs while creating the prepared statement.
 */
protected PreparedStatement readEventData(Connection connection, String identifier,
                     long firstSequenceNumber, int batchSize) throws SQLException {
  Transaction tx = transactionManager.startTransaction();
  try {
    final String sql = "SELECT " + trackedEventFields() + " FROM " + schema.domainEventTable() + " WHERE " +
        schema.aggregateIdentifierColumn() + " = ? AND " + schema.sequenceNumberColumn() + " >= ? AND " +
        schema.sequenceNumberColumn() + " < ? ORDER BY " + schema.sequenceNumberColumn() + " ASC";
    PreparedStatement preparedStatement = connection.prepareStatement(sql);
    preparedStatement.setString(1, identifier);
    preparedStatement.setLong(2, firstSequenceNumber);
    preparedStatement.setLong(3, firstSequenceNumber + batchSize);
    return preparedStatement;
  } finally {
    tx.commit();
  }
}
org.axonframework.eventsourcing.eventstore.jdbcEventSchema

Javadoc

Schema of an event entry to be stored using Jdbc.

Most used methods

  • <init>
  • domainEventTable
    Returns the name of the domain event table.
  • snapshotTable
    Returns the name of the snapshot event table.
  • aggregateIdentifierColumn
    Get the name of the column containing the aggregate identifier of the event.
  • builder
    Returns a new Builder initialized with default settings.
  • eventIdentifierColumn
    Get the name of the column containing the identifier of the event.
  • globalIndexColumn
    Get the name of the column containing the global index of the event.
  • metaDataColumn
    Get the name of the column containing the serialized metadata of the event.
  • payloadColumn
    Get the name of the column containing the serialized payload of the event.
  • payloadRevisionColumn
    Get the name of the column containing the revision number of the serialized payload.
  • payloadTypeColumn
    Get the name of the column containing the event payload type.
  • sequenceNumberColumn
    Get the name of the column containing the aggregate sequence number of the event.
  • payloadTypeColumn,
  • sequenceNumberColumn,
  • timestampColumn,
  • typeColumn

Popular in Java

  • Start an intent from android
  • scheduleAtFixedRate (ScheduledExecutorService)
  • compareTo (BigDecimal)
  • startActivity (Activity)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • JList (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now