/*
 * Copyright 2019, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package io.spine.server.entity;

import io.spine.annotation.Internal;
import io.spine.base.Error;
import io.spine.core.Event;
import io.spine.validate.NonValidated;

/**
 * A common contract for the {@linkplain Transaction transaction} listeners.
 *
 * <p>Provides an ability to add callbacks to the transaction execution stages.
 *
 * @param <I>
 *         ID type of the entity under transaction
 */
@Internal
public interface TransactionListener<I> {

    /**
     * A callback invoked before applying a {@linkplain Phase transaction phase}.
     *
     * @param phase
     *         the phase which is being applied
     */
    void onBeforePhase(Phase<I> phase);

    /**
     * A callback invoked after applying a {@linkplain Phase transaction phase}.
     *
     * <p>This callback is invoked for both successfully applied and failed phases.
     *
     * @param phase
     *         the phase which was applied before this callback is invoked
     */
    void onAfterPhase(Phase<I> phase);

    /**
     * A callback invoked before committing the transaction.
     *
     * @param entityRecord
     *         the entity modified within the transaction
     */
    void onBeforeCommit(@NonValidated EntityRecord entityRecord);

    /**
     * A callback invoked if the commit has failed.
     *
     * @param cause
     *         the error which caused the commit failure
     * @param entityRecord
     *         the uncommitted entity state
     */
    void onTransactionFailed(Error cause, @NonValidated EntityRecord entityRecord);

    /**
     * A callback invoked if the commit has failed due to a Rejection.
     *
     * @param cause
     *         the rejection which caused the commit failure
     * @param entityRecord
     *         the uncommitted entity state
     */
    void onTransactionFailed(Event cause, @NonValidated EntityRecord entityRecord);

    /**
     * A callback invoked after a successful commit.
     *
     * @param change
     *         the change of the entity under transaction
     */
    void onAfterCommit(EntityRecordChange change);
}

@@ -2161,32 +2161,240 @@
 transaction%0A
+     * @apiNote The %7B@code entityRecord%7D is %7B@code @NonValidated%7D because the changes%0A     *         are not yet committed and the it's not possible to guarantee that the record%0A     *         will be valid.%0A
      */%0A
     void onB
@@ -2373,32 +2373,32 @@
  valid.%0A     */%0A
-
     void onBefor
@@ -2655,32 +2655,205 @@
 ed entity state%0A
+     * @apiNote The %7B@code entityRecord%7D is %7B@code @NonValidated%7D because the transaction%0A     *         failed and it's not possible to guarantee that the record is valid.%0A
      */%0A    void
@@ -3115,32 +3115,32 @@
 am entityRecord%0A
-
      *         t
@@ -3163,24 +3163,197 @@
 ntity state%0A
+     * @apiNote The %7B@code entityRecord%7D is %7B@code @NonValidated%7D because the transaction%0A     *         failed and it's not possible to guarantee that the record is valid.%0A
      */%0A    

Add notes for the `@NonValidated` usage