# Interface OperationObserver

All Superinterfaces:
  `OperationHints`

public interface OperationObserver extends OperationHints
Defines a set of callback methods that allow `DataNode` to pass back query results and notify caller about exceptions.

All methods have default implementations: the result callbacks do nothing, the exception callbacks rethrow the reported exception wrapped in a `CayenneRuntimeException`, and `isIteratedResult()` returns false. An implementation only needs to override the callbacks it cares about.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default boolean`
  `isIteratedResult()`
  Returns whether results should be returned as a `ResultIterator`.
  `default void`
  `nextBatchCount(Query query, int[] resultCount)`
  Callback method invoked after a batch update is executed.
  `default void`
  `nextCount(Query query, int resultCount)`
  Callback method invoked after an updating query is executed.
  `default void`
  `nextGeneratedRows(Query query, List<DataRow> keys, List<ObjectId> idsToUpdate)`
  Callback method invoked after each batch of generated values is read during an update.
  `default void`
  `nextGlobalException(Exception ex)`
  Callback method invoked on exceptions that are not tied to a specific query execution, such as JDBC connection exceptions, etc.
  `default void`
  `nextQueryException(Query query, Exception ex)`
  Callback method invoked on exceptions that happen during an execution of a specific query.
  `default void`
  `nextRows(Query query, List<?> dataRows)`
  Callback method invoked for each processed ResultSet.
  `default void`
  `nextRows(Query q, ResultIterator<?> it)`
  Callback method invoked for each opened ResultIterator.
  `default void`
  `nextStatement(Query query, TranslatedStatement statement)`
  Callback invoked with the translated form of a query (its SQL and bindings) just before the statement is executed.
  `default void`
  `onSuccess()`
  Called at the end of a multi-query DataNode operation.

- ## Method Details

  - ### nextStatement

    default void nextStatement(Query query, TranslatedStatement statement)
    Callback invoked with the translated form of a query (its SQL and bindings) just before the statement is executed. It lets a logging observer correlate a statement with the results reported through the other `next*` callbacks. The default implementation does nothing.
    Since:
      5.0

  - ### onSuccess

    default void onSuccess()
    Called at the end of a multi-query DataNode operation.
    Since:
      5.0

  - ### isIteratedResult

    default boolean isIteratedResult()
    Returns whether results should be returned as a `ResultIterator`. Defaults to false.
    Specified by:
      `isIteratedResult` in interface `OperationHints`

  - ### nextCount

    default void nextCount(Query query, int resultCount)
    Callback method invoked after an updating query is executed.

  - ### nextBatchCount

    default void nextBatchCount(Query query, int[] resultCount)
    Callback method invoked after a batch update is executed.

  - ### nextRows

    default void nextRows(Query query, List<?> dataRows)
    Callback method invoked for each processed ResultSet.
    Since:
      3.0

  - ### nextRows

    default void nextRows(Query q, ResultIterator<?> it)
    Callback method invoked for each opened ResultIterator. If this observer requested results to be returned as a ResultIterator, this method is invoked instead of `nextRows(Query, List)`.
    Since:
      3.0

  - ### nextGeneratedRows

    default void nextGeneratedRows(Query query, List<DataRow> keys, List<ObjectId> idsToUpdate)
    Callback method invoked after each batch of generated values is read during an update.
    Since:
      5.0

  - ### nextQueryException

    default void nextQueryException(Query query, Exception ex)
    Callback method invoked on exceptions that happen during an execution of a specific query. The default implementation rethrows the exception wrapped in a `CayenneRuntimeException`.

  - ### nextGlobalException

    default void nextGlobalException(Exception ex)
    Callback method invoked on exceptions that are not tied to a specific query execution, such as JDBC connection exceptions, etc. The default implementation rethrows the exception wrapped in a `CayenneRuntimeException`.