<commit_before>/*
 * Copyright 2017, 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 io.spine.server.entity;

import io.spine.annotation.Internal;
import io.spine.core.EventContext;
import io.spine.core.Version;
import io.spine.core.Versions;

/**
 * The strategy of versioning of {@linkplain Entity entities} during a {@link Transaction.Phase} of
 * a certain {@code Transaction}.
 */
@Internal
public enum EntityVersioning {

    /**
     * This strategy is applied to the {@link Entity} types which represent a sequence of
     * events.
     *
     * <p>One example of such entity is {@link io.spine.server.aggregate.Aggregate Aggregate}.
     * As a sequence of events, an {@code Aggregate} has no own versioning system, thus
     * inherits the versions of the {@linkplain io.spine.server.aggregate.Apply applied}
     * events. In other words, the current version of an {@code Aggregate} is
     * the {@linkplain EventContext#getVersion() version} of last applied event.
     */
    FROM_EVENT {
        @Override
        Version nextVersion(Transaction.Phase<?, ?, ?, ?> phase) {
            final Version fromEvent = phase.getContext().getVersion();
            return fromEvent;
        }
    },

    /**
     * This strategy is applied to the {@link Entity} types which are not the pure Event
     * Sourcing entities, such as {@link io.spine.server.projection.Projection Projection}s.
     *
     * <p>A {@code Projection} represents an arbitrary cast of data in a specific moment in
     * time. The events applied to a {@code Projection} are random, i.e. are produced by
     * different {@code Entities} and have no common versioning. Thus, a {@code Projection} has
     * its own versioning system. Each event makes a {@code Projection} <i>increment</i> its
     * version by one.
     */
    AUTO_INCREMENT {
        @Override
        Version nextVersion(Transaction.Phase<?, ?, ?, ?> phase) {
            final Version current = phase.getUnderlyingTransaction().getVersion();
            final Version newVersion = Versions.increment(current);
            return newVersion;
        }<commit_msg>Enhance JavaDoc.<commit_after>/*
 * Copyright 2017, 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 io.spine.server.entity;

import io.spine.annotation.Internal;
import io.spine.core.EventContext;
import io.spine.core.Version;
import io.spine.core.Versions;

/**
 * The strategy of versioning of {@linkplain Entity entities} during a {@link Transaction.Phase} of
 * a certain {@code Transaction}.
 */
@Internal
public enum EntityVersioning {

    /**
     * This strategy is applied to the {@link Entity} types which represent a sequence of
     * events.
     *
     * <p>One example of such entity is {@link io.spine.server.aggregate.Aggregate Aggregate}.
     * As a sequence of events, an {@code Aggregate} has no own versioning system, thus
     * inherits the versions of the {@linkplain io.spine.server.aggregate.Apply applied}
     * events. In other words, the current version of an {@code Aggregate} is
     * the {@linkplain EventContext#getVersion() version} of last applied event.
     */
    FROM_EVENT {
        @Override
        Version nextVersion(Transaction.Phase<?, ?, ?, ?> phase) {
            final Version fromEvent = phase.getContext().getVersion();
            return fromEvent;
        }
    },

    /**
     * This strategy is applied to the {@link Entity} types which cannot use the event versions,
     * such as {@link io.spine.server.projection.Projection Projection}s.
     *
     * <p>A {@code Projection} represents an arbitrary cast of data in a specific moment in
     * time. The events applied to a {@code Projection} are produced by different {@code Entities}
     * and have no common versioning. Thus, a {@code Projection} has its own versioning system.
     * Each event <i>increments</i> the {@code Projection} version by one.
     */
    AUTO_INCREMENT {
        @Override
        Version nextVersion(Transaction.Phase<?, ?, ?, ?> phase) {
            final Version current = phase.getUnderlyingTransaction().getVersion();
            final Version newVersion = Versions.increment(current);
            return newVersion;
        }
{'fraction_non_alphanumeric': 0.08474020652352074, 'fraction_numerical': 0.0013112604491067037, 'mean_word_length': 3.3276595744680852, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2404158', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1568, 'n_words': 689}