org.javers.repository.api.JaversRepository Maven / Gradle / Ivy
package org.javers.repository.api;
import java.time.LocalDateTime;
import java.util.Optional;
import org.javers.common.validation.Validate;
import org.javers.core.commit.Commit;
import org.javers.core.commit.CommitId;
import org.javers.core.commit.CommitMetadata;
import org.javers.core.diff.Change;
import org.javers.core.json.JsonConverter;
import org.javers.core.metamodel.object.CdoSnapshot;
import org.javers.core.metamodel.object.GlobalId;
import org.javers.core.metamodel.type.EntityType;
import org.javers.core.metamodel.type.ManagedType;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* JaversRepository is responsible for persisting {@link Commit}s calculated by Javers core.
*
*
* It should persist {@link CommitMetadata} and Snapshots,
* {@link Change}s should not be persisted as they are recalculated by Javers core as diff between relevant snapshots.
*
*
*
* Hints for JaversRepository implementation
*
* After persisting in database, Commit is considered immutable so it can not be updated.
* Persisting Commit in any kind of database is easy. JaVers provides flexible
* JSON serialization/deserialization engine,
* designed as abstraction layer between Java types and specific database types.
* Essentially, object-oriented data are persisted as JSON.
* Repository impl should leverage {@link JsonConverter}.
*
*
*
* @author bartosz walacik
*/
public interface JaversRepository {
/**
* Snapshots (historical states) of given object
* in reverse chronological order
*
* @param queryParams parameters constraining returned list (size limit, util from/to)
* @return empty List if object is not versioned
*/
List getStateHistory(GlobalId globalId, QueryParams queryParams);
/**
* Snapshots of all ValueObjects owned by given ownerEntity at given path
*/
List getValueObjectStateHistory(EntityType ownerEntity, String path, QueryParams queryParams);
/**
* All snapshots of objects within given managed classes,
* in reverse chronological order
*
* @param queryParams parameters constraining returned list (size limit, util from/to)
* @return empty List if no snapshots found
*/
List getStateHistory(Set givenClasses, QueryParams queryParams);
/**
* Latest snapshot of a given object.
*
* Optional#EMPTY if object is not versioned
*/
Optional getLatest(GlobalId globalId);
default List getLatest(Collection globalIds) {
Validate.argumentsAreNotNull(globalIds);
return globalIds.stream()
.map(id -> getLatest(id))
.filter(it -> it.isPresent())
.map(it -> it.get())
.collect(Collectors.toList());
}
/**
* Snapshots of all objects in reverse chronological order
*
* @param queryParams parameters constraining returned list (size limit, util from/to)
*/
List getSnapshots(QueryParams queryParams);
/**
* Snapshots with specified globalId and version
*/
List getSnapshots(Collection snapshotIdentifiers);
void persist(Commit commit);
CommitId getHeadId();
void setJsonConverter(JsonConverter jsonConverter);
/**
* Called at the end of JaVers bootstrap,
* good place to put database schema update
*/
void ensureSchema();
}