/*
 * Copyright 2015, TeamDev Ltd. 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 org.spine3.server.aggregate;

import com.google.protobuf.Message;
import org.spine3.base.CommandContext;
import org.spine3.base.EventRecord;
import org.spine3.server.Repository;

import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * The common interface for aggregate root repositories.
 *
 * @author Alexander Yevsyukov
 */
public interface AggregateRootRepository<I extends Message, R extends AggregateRoot<I, ?>>
        extends Repository<I, R> {

    /**
     * Loads or creates a root with the passed ID.
     *
     * @param id the id of the aggregate
     * @return loaded or newly created instance of the aggregate root
     */
    @SuppressWarnings({"AbstractMethodOverridesAbstractMethod",
                       "NullableProblems" /* We override the default behavior of loading. */})
    @Nonnull
    R load(I id);

    /**
     * Processes the command by dispatching it to a method of an aggregate root.
     * <p>
     * For more details on writing aggregate commands read
     * <a href="http://github.com/SpineEventEngine/core/wiki/Writing-Aggregate-Commands">"Writing Aggregate Commands"</a>.
     *
     * @param command the command to dispatch
     * @param context context info of the command
     * @return a list of the event records
     * @throws InvocationTargetException if an exception occurs during command dispatching
     *
     * @see <a href="http://github.com/SpineEventEngine/core/wiki/Writing-Aggregate-Commands">Writing Aggregate Commands</a>
     */
    List<EventRecord> dispatch(Message command, CommandContext context) throws InvocationTargetException;

}

@@ -1370,16 +1370,99 @@
 ies.%0A *%0A
+ * @param %3CI%3E the type of IDs of aggregate roots%0A * @param %3CR%3E aggregate root type%0A
  * @auth
@@ -1484,16 +1484,16 @@
 vsyukov%0A
-
  */%0Apubl
@@ -1864,27 +1864,16 @@
 ethod%22,%0A
-           
         
@@ -1948,16 +1948,16 @@
 g. */%7D)%0A
+
     @Non
@@ -2078,16 +2078,17 @@
     * %3Cp
+/
 %3E%0A     *
@@ -2409,16 +2409,16 @@
 records%0A
+
      * @
@@ -2500,23 +2500,16 @@
 atching%0A
-     *%0A
      * @

Document generic types of AggregateRootRepository.