All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javers.core.commit.Commit Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
package org.javers.core.commit;

import org.javers.common.validation.Validate;
import org.javers.core.Changes;
import org.javers.core.CommitIdGenerator;
import org.javers.core.diff.Change;
import org.javers.core.diff.Diff;
import org.javers.core.graph.Cdo;
import org.javers.core.metamodel.object.CdoSnapshot;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/**
 * JaVers commit is a similar concept to GIT commit.
 * It records snapshots of changed domain objects.
 * 

* * One commit can affect one or more domain objects. *

* * Commit holds following data: *
    *
  • who did change the data - {@link CommitMetadata#getAuthor()}
  • *
  • when the change was made - {@link CommitMetadata#getCommitDate()}
  • *
  • list of atomic changes between two domain object graphs - {@link #getChanges()}
  • *
  • list of Snapshots of affected objects - {@link #getSnapshots()}
  • *
* * @author bartosz walacik */ public final class Commit { private final CommitMetadata commitMetadata; private final List snapshots; private final Diff diff; Commit(CommitMetadata commitMetadata, List snapshots, Diff diff) { Validate.argumentsAreNotNull(commitMetadata, snapshots, diff); this.commitMetadata = commitMetadata; this.snapshots = snapshots; this.diff = diff; } /** * Monotonically increasing id, * e.g. 1.0, 2.0, ... */ public CommitId getId() { return commitMetadata.getId(); } public String getAuthor() { return commitMetadata.getAuthor(); } public Map getProperties() { return commitMetadata.getProperties(); } Diff getDiff() { return diff; } /** * Commit creation timestamp in local time zone */ public LocalDateTime getCommitDate() { return commitMetadata.getCommitDate(); } /** * Commit creation timestamp in UTC. *

* * Since 5.1, commitDateInstant is persisted in JaversRepository * to provide reliable chronological ordering, especially when {@link CommitIdGenerator#RANDOM} * is used. * *

* * Commits persisted by JaVers older then 5.1 * have commitDateInstant guessed from commitDate and current {@link TimeZone} * * @since 5.1 */ public Instant getCommitDateInstant() { return commitMetadata.getCommitDateInstant(); } /** * @return unmodifiableList */ public List getSnapshots() { return Collections.unmodifiableList(snapshots); } /** * @return unmodifiableList */ public Changes getChanges() { return diff.getChanges(); } @Override public String toString() { StringBuilder b = new StringBuilder(); b.append("Commit(id:" + commitMetadata.getId()); b.append(", snapshots:" + snapshots.size()); b.append(", author:" + commitMetadata.getAuthor()); b.append(", " + diff.changesSummary()); b.append(")"); return b.toString(); } @Override public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } Commit other = (Commit) o; return this.getId().equals(other.getId()); } @Override public int hashCode() { return getId().hashCode(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy