Tabnine Logo
Transaction.commit
Code IndexAdd Tabnine to your IDE (free)

How to use
commit
method
in
org.axonframework.common.transaction.Transaction

Best Java code snippets using org.axonframework.common.transaction.Transaction.commit (Showing top 17 results out of 315)

origin: AxonFramework/AxonFramework

/**
 * Executes the given {@code task} in a new {@link Transaction}. The transaction is committed when the task
 * completes normally, and rolled back when it throws an exception.
 *
 * @param task The task to execute
 */
default void executeInTransaction(Runnable task) {
  Transaction transaction = startTransaction();
  try {
    task.run();
    transaction.commit();
  } catch (Throwable e) {
    transaction.rollback();
    throw e;
  }
}
origin: AxonFramework/AxonFramework

  /**
   * Invokes the given {@code supplier} in a transaction managed by the current TransactionManager. Upon completion
   * of the call, the transaction will be committed in the case of a regular return value, or rolled back in case an
   * exception occurred.
   * <p>
   * This method is an alternative to {@link #executeInTransaction(Runnable)} in cases where a result needs to be
   * returned from the code to be executed transactionally.
   *
   * @param supplier The supplier of the value to return
   * @param <T>      The type of value to return
   * @return The value returned by the supplier
   */
  default <T> T fetchInTransaction(Supplier<T> supplier) {
    Transaction transaction = startTransaction();
    try {
      T result = supplier.get();
      transaction.commit();
      return result;
    } catch (Throwable e) {
      transaction.rollback();
      throw e;
    }
  }
}
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 Object handle(UnitOfWork<? extends T> unitOfWork, InterceptorChain interceptorChain) throws Exception {
    Transaction transaction = transactionManager.startTransaction();
    unitOfWork.onCommit(u -> transaction.commit());
    unitOfWork.onRollback(u -> transaction.rollback());
    return interceptorChain.proceed();
  }
}
origin: AxonFramework/AxonFramework

@Test
public void testHandlerIsInvokedInTransactionScope() throws Exception {
  CountDownLatch countDownLatch = new CountDownLatch(1);
  AtomicInteger counter = new AtomicInteger();
  AtomicInteger counterAtHandle = new AtomicInteger();
  when(mockTransactionManager.startTransaction()).thenAnswer(i -> {
    counter.incrementAndGet();
    return mockTransaction;
  });
  doAnswer(i -> counter.decrementAndGet()).when(mockTransaction).rollback();
  doAnswer(i -> counter.decrementAndGet()).when(mockTransaction).commit();
  doAnswer(invocation -> {
    counterAtHandle.set(counter.get());
    countDownLatch.countDown();
    return null;
  }).when(mockHandler).handle(any());
  testSubject.start();
  // give it a bit of time to start
  Thread.sleep(200);
  eventBus.publish(createEvents(2));
  assertTrue("Expected Handler to have received 2 published events", countDownLatch.await(5, TimeUnit.SECONDS));
  assertEquals(1, counterAtHandle.get());
}
origin: AxonFramework/AxonFramework

/**
 * Attach a transaction to this Unit of Work, using the given {@code transactionManager}. The transaction will be
 * managed in the lifecycle of this Unit of Work. Failure to start a transaction will cause this Unit of Work
 * to be rolled back.
 *
 * @param transactionManager The Transaction Manager to create, commit and/or rollback the transaction
 */
default void attachTransaction(TransactionManager transactionManager) {
  try {
    Transaction transaction = transactionManager.startTransaction();
    onCommit(u -> transaction.commit());
    onRollback(u -> transaction.rollback());
  } catch (Throwable t) {
    rollback(t);
    throw t;
  }
}
origin: AxonFramework/AxonFramework

  @Override
  protected void storeEvents(EventMessage<?>... events) {
    UnitOfWork<?> unitOfWork = CurrentUnitOfWork.get();
    Transaction transaction = transactionManager.startTransaction();
    unitOfWork.onCommit(u -> transaction.commit());
    unitOfWork.onRollback(u -> transaction.rollback());
    super.storeEvents(events);
  }
}
origin: org.axonframework/axon-core

/**
 * Executes the given {@code task} in a new {@link Transaction}. The transaction is committed when the task
 * completes normally, and rolled back when it throws an exception.
 *
 * @param task The task to execute
 */
default void executeInTransaction(Runnable task) {
  Transaction transaction = startTransaction();
  try {
    task.run();
    transaction.commit();
  } catch (Throwable e) {
    transaction.rollback();
    throw e;
  }
}
origin: org.axonframework/axon-messaging

/**
 * Executes the given {@code task} in a new {@link Transaction}. The transaction is committed when the task
 * completes normally, and rolled back when it throws an exception.
 *
 * @param task The task to execute
 */
default void executeInTransaction(Runnable task) {
  Transaction transaction = startTransaction();
  try {
    task.run();
    transaction.commit();
  } catch (Throwable e) {
    transaction.rollback();
    throw e;
  }
}
origin: org.axonframework/axon-messaging

  /**
   * Invokes the given {@code supplier} in a transaction managed by the current TransactionManager. Upon completion
   * of the call, the transaction will be committed in the case of a regular return value, or rolled back in case an
   * exception occurred.
   * <p>
   * This method is an alternative to {@link #executeInTransaction(Runnable)} in cases where a result needs to be
   * returned from the code to be executed transactionally.
   *
   * @param supplier The supplier of the value to return
   * @param <T>      The type of value to return
   * @return The value returned by the supplier
   */
  default <T> T fetchInTransaction(Supplier<T> supplier) {
    Transaction transaction = startTransaction();
    try {
      T result = supplier.get();
      transaction.commit();
      return result;
    } catch (Throwable e) {
      transaction.rollback();
      throw e;
    }
  }
}
origin: org.axonframework/axon-core

  /**
   * Invokes the given {@code supplier} in a transaction managed by the current TransactionManager. Upon completion
   * of the call, the transaction will be committed in the case of a regular return value, or rolled back in case an
   * exception occurred.
   * <p>
   * This method is an alternative to {@link #executeInTransaction(Runnable)} in cases where a result needs to be
   * returned from the code to be executed transactionally.
   *
   * @param supplier The supplier of the value to return
   * @param <T>      The type of value to return
   * @return The value returned by the supplier
   */
  default <T> T fetchInTransaction(Supplier<T> supplier) {
    Transaction transaction = startTransaction();
    try {
      T result = supplier.get();
      transaction.commit();
      return result;
    } catch (Throwable e) {
      transaction.rollback();
      throw e;
    }
  }
}
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();
  }
}
origin: org.axonframework/axon-eventsourcing

/**
 * 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: org.axonframework/axon-messaging

  @Override
  public Object handle(UnitOfWork<? extends T> unitOfWork, InterceptorChain interceptorChain) throws Exception {
    Transaction transaction = transactionManager.startTransaction();
    unitOfWork.onCommit(u -> transaction.commit());
    unitOfWork.onRollback(u -> transaction.rollback());
    return interceptorChain.proceed();
  }
}
origin: org.axonframework/axon-core

  @Override
  public Object handle(UnitOfWork<? extends T> unitOfWork, InterceptorChain interceptorChain) throws Exception {
    Transaction transaction = transactionManager.startTransaction();
    unitOfWork.onCommit(u -> transaction.commit());
    unitOfWork.onRollback(u -> transaction.rollback());
    return interceptorChain.proceed();
  }
}
origin: org.axonframework/axon-core

/**
 * Attach a transaction to this Unit of Work, using the given {@code transactionManager}. The transaction will be
 * managed in the lifecycle of this Unit of Work. Failure to start a transaction will cause this Unit of Work
 * to be rolled back.
 *
 * @param transactionManager The Transaction Manager to create, commit and/or rollback the transaction
 */
default void attachTransaction(TransactionManager transactionManager) {
  try {
    Transaction transaction = transactionManager.startTransaction();
    onCommit(u -> transaction.commit());
    onRollback(u -> transaction.rollback());
  } catch (Throwable t) {
    rollback(t);
    throw t;
  }
}
origin: org.axonframework/axon-messaging

/**
 * Attach a transaction to this Unit of Work, using the given {@code transactionManager}. The transaction will be
 * managed in the lifecycle of this Unit of Work. Failure to start a transaction will cause this Unit of Work
 * to be rolled back.
 *
 * @param transactionManager The Transaction Manager to create, commit and/or rollback the transaction
 */
default void attachTransaction(TransactionManager transactionManager) {
  try {
    Transaction transaction = transactionManager.startTransaction();
    onCommit(u -> transaction.commit());
    onRollback(u -> transaction.rollback());
  } catch (Throwable t) {
    rollback(t);
    throw t;
  }
}
org.axonframework.common.transactionTransactioncommit

Javadoc

Commit this transaction.

Popular methods of Transaction

  • rollback
    Roll back this transaction.

Popular in Java

  • Reactive rest calls using spring rest template
  • onRequestPermissionsResult (Fragment)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • requestLocationUpdates (LocationManager)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Top Vim plugins
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