file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
QueryTokenStream.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/QueryTokenStream.java
package org.chronos.chronodb.internal.api.query; import java.util.Iterator; import java.util.NoSuchElementException; import org.chronos.chronodb.internal.impl.query.parser.token.QueryToken; /** * A {@link QueryTokenStream} is a stream of {@link QueryToken}s. * * <p> * Such a stream is very similar to an <code>{@link Iterator}&lt;{@link QueryToken}&gt;</code>, except that it also * allows to {@link #lookAhead()} to the next token (without actually moving to the next token), and also allows to * check if it {@link #isAtStartOfInput()}. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface QueryTokenStream { /** * Returns the current token, and moves to the next token. * * @return The current token. Never <code>null</code>. * * @throws NoSuchElementException * Thrown if there is no token to return, i.e. the stream has reached its end. */ QueryToken getToken() throws NoSuchElementException; /** * Returns the next token (i.e. the token after the one returned by {@link #getToken()}) without moving away from * the current token. * * @return The next token. Never <code>null</code>. * * @throws NoSuchElementException * Thrown if there is no next token to look ahead to. */ QueryToken lookAhead() throws NoSuchElementException; /** * Checks if this stream has a next token to return. * * <p> * If this method returns <code>true</code>, then neither {@link #getToken()} nor {@link #lookAhead()} may throw an * {@link NoSuchElementException} until after {@link #getToken()} has been called at least once. * * @return <code>true</code> if there is a next token to return, <code>false</code> if the stream has reached its * end and there are no further tokens. */ boolean hasNextToken(); /** * Checks if the current token is the first token of the input. * * <p> * This method should return <code>true</code> until {@link #getToken()} has been called once, and * <code>false</code> after the first call to {@link #getToken()}. * * @return <code>true</code> if {@link #getToken()} was never called on this instance, otherwise <code>false</code>. */ boolean isAtStartOfInput(); }
2,242
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBQuery.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/ChronoDBQuery.java
package org.chronos.chronodb.internal.api.query; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.internal.impl.query.parser.ast.QueryElement; /** * A {@link ChronoDBQuery} is a query that can be executed against a {@link ChronoDB} instance. * * <p> * Instances of classes implementing this interface are usually produced by feeding a {@link QueryTokenStream} to a * {@link QueryParser} via {@link QueryParser#parse(QueryTokenStream)}. * * <p> * Please note that all instances of classes that implement this interface are assumed to be <code>immutable</code>! * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface ChronoDBQuery { /** * Returns the keyspace on which this query should be executed. * * @return The name of the keyspace. Never <code>null</code>. */ public String getKeyspace(); /** * Returns the root {@link QueryElement} in the Abstract Syntax Tree (AST) of the query. * * @return The AST root element. Never <code>null</code>. */ public QueryElement getRootElement(); }
1,083
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
QueryParser.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/QueryParser.java
package org.chronos.chronodb.internal.api.query; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.api.exceptions.ChronoDBQuerySyntaxException; /** * A {@link QueryParser} is responsible for converting a {@link QueryTokenStream} into a {@link ChronoDBQuery} by * building an Abstract Syntax Tree (AST) on top of the token stream. * * <p> * Query parser implementations are assumed to be <b>immutalbe</b> (in the ideal case <b>stateless</b>) and therefore * <b>thread-safe</b>! * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface QueryParser { /** * Parses the given {@link QueryTokenStream}. * * <p> * All implementations of this method are assumed to be <b>thread-safe</b> by {@link ChronoDB}! * * @param tokenStream * The token stream to parse. Must not be <code>null</code>, and must not be in use by another parser. * The stream is consumed during the parse process and cannot be reused. * * @return The parsed {@link ChronoDBQuery}. Never <code>null</code>. * * @throws ChronoDBQuerySyntaxException * Thrown if a parse error occurs. */ public ChronoDBQuery parse(QueryTokenStream tokenStream) throws ChronoDBQuerySyntaxException; }
1,276
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
QueryOptimizer.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/QueryOptimizer.java
package org.chronos.chronodb.internal.api.query; import org.chronos.chronodb.api.ChronoDB; /** * A {@link QueryOptimizer} is an object responsible for rewriting a {@link ChronoDBQuery} into another query with equal * semantics but improved resource usage. * * <p> * Usually, this manifests itself in the fact that the returned optimized query produces the same result set as the * input query, but is likely to execute faster and/or is likely to uses fewer memory resources. * * <p> * Please note that an optimizer that simply returns the input query also fulfills the contract and is therefore a valid * (yet not very useful) optimizer. * * <p> * Query optimizer implementations are assumed to be <b>immutalbe</b> (in the ideal case <b>stateless</b>) and therefore * <b>thread-safe</b>! * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface QueryOptimizer { /** * Optimizes the given query. * * <p> * All implementations of this method are assumed to be <b>thread-safe</b> by {@link ChronoDB}! * * @param query * The query to optimize. Will not be modified. Must not be <code>null</code>. * @return The optimized query. May be equal to the input query, may also be the same object (with respect to the * <code>==</code> operator). Never <code>null</code>. */ public ChronoDBQuery optimize(ChronoDBQuery query); }
1,416
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DoubleSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/DoubleSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.NumberCondition; import org.chronos.chronodb.internal.impl.query.DoubleSearchSpecificationImpl; public interface DoubleSearchSpecification extends SearchSpecification<Double, Double> { // ================================================================================================================= // FACTORY METHODS // ================================================================================================================= public static DoubleSearchSpecification create(SecondaryIndex index, final NumberCondition condition, final double searchValue, final double equalityTolerance) { return new DoubleSearchSpecificationImpl(index, condition, searchValue, equalityTolerance); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public NumberCondition getCondition(); public double getEqualityTolerance(); @Override public default boolean matches(final Double value) { return this.getCondition().applies(value, this.getSearchValue(), this.getEqualityTolerance()); } @Override public default String getDescriptiveSearchType() { return "Double"; } }
1,450
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ContainmentLongSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/ContainmentLongSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.LongContainmentCondition; import org.chronos.chronodb.api.query.StringContainmentCondition; import org.chronos.chronodb.internal.impl.query.ContainmentLongSearchSpecificationImpl; import org.chronos.chronodb.internal.impl.query.ContainmentStringSearchSpecificationImpl; import org.chronos.chronodb.internal.impl.query.TextMatchMode; import java.util.Set; public interface ContainmentLongSearchSpecification extends ContainmentSearchSpecification<Long> { // ================================================================================================================= // STATIC FACTORY METHODS // ================================================================================================================= static ContainmentLongSearchSpecification create(SecondaryIndex index, LongContainmentCondition condition, Set<Long> searchValues) { return new ContainmentLongSearchSpecificationImpl(index, condition, searchValues); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public LongContainmentCondition getCondition(); @Override public default boolean matches(final Long value){ return this.getCondition().applies(value, getSearchValue()); } @Override public default String getDescriptiveSearchType() { return "Long"; } }
1,684
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
SearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/SearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import java.util.function.Predicate; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.Condition; public interface SearchSpecification<ELEMENTVALUE, SEARCHVALUE> { // ================================================================================================================= // API // ================================================================================================================= public SecondaryIndex getIndex(); public SEARCHVALUE getSearchValue(); public Condition getCondition(); public Predicate<Object> toFilterPredicate(); public SearchSpecification<ELEMENTVALUE, SEARCHVALUE> onIndex(SecondaryIndex index); public SearchSpecification<ELEMENTVALUE, SEARCHVALUE> negate(); public boolean matches(final ELEMENTVALUE value); public String getDescriptiveSearchType(); }
917
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ContainmentStringSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/ContainmentStringSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.StringContainmentCondition; import org.chronos.chronodb.internal.impl.query.ContainmentStringSearchSpecificationImpl; import org.chronos.chronodb.internal.impl.query.TextMatchMode; import java.util.Set; public interface ContainmentStringSearchSpecification extends ContainmentSearchSpecification<String> { // ================================================================================================================= // FACTORY METHODS // ================================================================================================================= public static ContainmentStringSearchSpecification create(final SecondaryIndex index, final StringContainmentCondition condition, final TextMatchMode matchMode, final Set<String> searchValues) { return new ContainmentStringSearchSpecificationImpl(index, condition, searchValues, matchMode); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public StringContainmentCondition getCondition(); public TextMatchMode getMatchMode(); @Override public default boolean matches(final String value){ return this.getCondition().applies(value, getSearchValue(), getMatchMode()); } @Override public default String getDescriptiveSearchType() { return "String"; } }
1,668
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ContainmentDoubleSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/ContainmentDoubleSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.DoubleContainmentCondition; import org.chronos.chronodb.internal.impl.query.ContainmentDoubleSearchSpecificationImpl; import java.util.Set; public interface ContainmentDoubleSearchSpecification extends ContainmentSearchSpecification<Double> { // ================================================================================================================= // STATIC FACTORY METHODS // ================================================================================================================= static ContainmentDoubleSearchSpecification create(SecondaryIndex index, DoubleContainmentCondition condition, Set<Double> comparisonValues, double equalityTolerance) { return new ContainmentDoubleSearchSpecificationImpl(index, condition, comparisonValues, equalityTolerance); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public DoubleContainmentCondition getCondition(); public double getEqualityTolerance(); @Override public default boolean matches(final Double value){ return this.getCondition().applies(value, getSearchValue(), getEqualityTolerance()); } @Override public default String getDescriptiveSearchType() { return "Double"; } }
1,607
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ContainmentSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/ContainmentSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.query.ContainmentCondition; import java.util.Set; public interface ContainmentSearchSpecification<T> extends SearchSpecification<T, Set<T>> { @Override public ContainmentCondition getCondition(); }
303
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
LongSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/LongSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.NumberCondition; import org.chronos.chronodb.internal.impl.query.LongSearchSpecificationImpl; public interface LongSearchSpecification extends SearchSpecification<Long, Long> { // ================================================================================================================= // FACTORY METHODS // ================================================================================================================= public static LongSearchSpecification create(final SecondaryIndex index, final NumberCondition condition, final long searchValue) { return new LongSearchSpecificationImpl(index, condition, searchValue); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public NumberCondition getCondition(); @Override public default boolean matches(final Long value) { return this.getCondition().applies(value, this.getSearchValue()); } @Override public default String getDescriptiveSearchType() { return "Long"; } }
1,318
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
StringSearchSpecification.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/query/searchspec/StringSearchSpecification.java
package org.chronos.chronodb.internal.api.query.searchspec; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.query.StringCondition; import org.chronos.chronodb.internal.impl.query.StringSearchSpecificationImpl; import org.chronos.chronodb.internal.impl.query.TextMatchMode; public interface StringSearchSpecification extends SearchSpecification<String, String> { // ================================================================================================================= // FACTORY METHODS // ================================================================================================================= public static StringSearchSpecification create(final SecondaryIndex index, final StringCondition condition, final TextMatchMode matchMode, final String searchText) { return new StringSearchSpecificationImpl(index, condition, searchText, matchMode); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= @Override public StringCondition getCondition(); public TextMatchMode getMatchMode(); @Override public default boolean matches(final String value) { return this.getCondition().applies(value, getSearchValue(), getMatchMode()); } @Override public default String getDescriptiveSearchType() { return "String"; } }
1,489
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IPurgeKeyOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/IPurgeKeyOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface IPurgeKeyOperation extends DatebackOperation { String getKeyspace(); String getKey(); long getFromTimestamp(); long getToTimestamp(); }
231
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IPurgeCommitsOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/IPurgeCommitsOperation.java
package org.chronos.chronodb.internal.api.dateback.log; import java.util.Set; public interface IPurgeCommitsOperation extends DatebackOperation { Set<Long> getCommitTimestamps(); }
189
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DatebackOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/DatebackOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface DatebackOperation { public String getId(); public long getWallClockTime(); public String getBranch(); public boolean affectsTimestamp(long timestamp); public long getEarliestAffectedTimestamp(); }
296
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ITransformValuesOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/ITransformValuesOperation.java
package org.chronos.chronodb.internal.api.dateback.log; import java.util.Set; public interface ITransformValuesOperation extends DatebackOperation { Set<Long> getCommitTimestamps(); String getKeyspace(); String getKey(); }
241
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IPurgeEntryOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/IPurgeEntryOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface IPurgeEntryOperation extends DatebackOperation { String getKey(); String getKeyspace(); long getOperationTimestamp(); }
210
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DatebackLogger.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/DatebackLogger.java
package org.chronos.chronodb.internal.api.dateback.log; @FunctionalInterface public interface DatebackLogger { public void logDatebackOperation(DatebackOperation operation); }
183
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IUpdateCommitMetadataOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/IUpdateCommitMetadataOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface IUpdateCommitMetadataOperation extends DatebackOperation { long getCommitTimestamp(); }
168
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IInjectEntriesOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/IInjectEntriesOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface IInjectEntriesOperation extends DatebackOperation { long getOperationTimestamp(); boolean isCommitMetadataOverride(); }
205
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IPurgeKeyspaceOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/IPurgeKeyspaceOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface IPurgeKeyspaceOperation extends DatebackOperation { String getKeyspace(); long getFromTimestamp(); long getToTimestamp(); }
214
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ITransformCommitOperation.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/dateback/log/ITransformCommitOperation.java
package org.chronos.chronodb.internal.api.dateback.log; public interface ITransformCommitOperation extends DatebackOperation { long getCommitTimestamp(); }
163
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ObjectInput.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/stream/ObjectInput.java
package org.chronos.chronodb.internal.api.stream; import java.io.ObjectInputStream; /** * An {@link ObjectInput} is a minimal interface for reading arbitrary objects from a data source. * * <p> * Please note that this interface is different from {@link ObjectInputStream} in that it provides only a fraction of * the methods and functionality. This interface is used to keep the dependency towards the externalization mechanism to * a bare minimum. * * <p> * As this class extends {@link AutoCloseable}, instances of this class must be {@linkplain #close() closed} explicitly. * However, the Java 7 <code>try-with-resources</code> statement may be used for doing so. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface ObjectInput extends CloseableIterator<Object> { }
827
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
CloseableIterator.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/stream/CloseableIterator.java
package org.chronos.chronodb.internal.api.stream; import org.chronos.chronodb.internal.impl.stream.ConcatenatedCloseableIterator; import org.chronos.chronodb.internal.impl.stream.TransformingCloseableIterator; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.function.Consumer; import java.util.function.Function; import static com.google.common.base.Preconditions.*; /** * A {@link CloseableIterator} is simply a regular {@link Iterator} that has to be {@link #close() closed} explicitly. * * <p> * This class does <b>not</b> extend {@link Iterator} for a very good reason. Not implementing {@link Iterator} prevents * assignment of an {@link CloseableIterator} instance to a {@link Iterator} variable. This would be dangerous, because * the {@link Iterator}-typed variable may be passed on as a regular iterator to other code, and {@link #close()} would * never be invoked. * * @param <T> The element type which is returned by {@link #next()}. * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface CloseableIterator<T> extends AutoCloseable { // ===================================================================================================================== // STATIC HELPERS // ===================================================================================================================== /** * Concatenates the two given iterators into one common iterator. * * <p> * Calling {@link #close()} on the resulting iterator will close <b>all</b> of the "child" iterators. The iteration * process itself is lazy: the first iterator will be fully consumed (and closed) before the second iterator is * touched by {@link #next()}. * * @param iterators The iterators to concatenate. Must not be <code>null</code>. * @return The combined concatenated iterator. Never <code>null</code>. */ public static <E> CloseableIterator<E> concat(final Iterator<CloseableIterator<E>> iterators) { checkNotNull(iterators, "Precondition violation - argument 'iterators' must not be NULL!"); return new ConcatenatedCloseableIterator<E>(iterators); } /** * Transforms every element in the given iterator by applying the given function on it, resulting in a new iterator. * * <p> * The given function will be applied in a lazy way, i.e. values will be converted on the fly when they are * requested via {@link #next()}. * * <p> * Closing the resulting iterator will also close the wrapped iterator. * * @param iterator The iterator to transform. Must not be <code>null</code>. * @param function The transformation function to apply to each element of the iterator. Must not be <code>null</code>. * @return The transformed iterator. Never <code>null</code>. */ public static <E, F> CloseableIterator<F> transform(final CloseableIterator<E> iterator, final Function<? super E, ? extends F> function) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); checkNotNull(function, "Precondition violation - argument 'function' must not be NULL!"); return new TransformingCloseableIterator<>(iterator, function); } // ===================================================================================================================== // PUBLIC API // ===================================================================================================================== /** * Same as the regular {@link Iterator#next()}. * * @return The next element in this iterator. Depending on the implementation, this may be <code>null</code>. */ public T next(); /** * Same as the regular {@link Iterator#hasNext()}. * * @return <code>true</code> if there is another element to be returned in {@link #next()}, otherwise * <code>false</code>. */ public boolean hasNext(); /** * Closes this iterator. * * <p> * Any further call to {@link #hasNext()} will return <code>false</code>, and any further call to {@link #next()} * will fail with an exception. * * <p> * Closing a closeable iterator more than once is permitted, but has no effect. */ @Override public void close(); /** * Checks if this iterator has been closed. * * @return <code>true</code> if this iterator has already been closed, otherwise <code>false</code>. */ public boolean isClosed(); // ===================================================================================================================== // EXTENSION METHODS // ===================================================================================================================== /** * Performs the given action for each remaining element in this iterator. * * <p> * <b>/!\ This will NOT close this iterator!</b> The iterator will still need to be {@linkplain #close() closed} * manually afterwards. * * @param action The action to perform for each remaining element. Must not be <code>null</code>. */ public default void forEachRemaining(final Consumer<T> action) { while (this.hasNext()) { action.accept(this.next()); } } /** * Returns a plain {@link Iterator} representation of this closeable iterator. * * <p> * The returned iterator directly forwards calls to {@link #hasNext()} and {@link #next()} to their equivalents in * this object. Therefore, advancing the returned iterator will also advance this closeable iterator. * * <p> * <b>WARNING:</b> Do not invoke this method unless for interoperability with {@link Iterator}-based APIs, because * the information that this iterator needs to be {@link #close() closed} will no longer be present in the returned * iterator. * * @return A plain iterator representation of this closable iterator. */ public default Iterator<T> asIterator() { return new Iterator<T>() { @Override public boolean hasNext() { return CloseableIterator.this.hasNext(); } @Override public T next() { if (!this.hasNext()) { throw new NoSuchElementException("Iterator has no more elements!"); } return CloseableIterator.this.next(); } }; } }
6,659
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBEntry.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/stream/ChronoDBEntry.java
package org.chronos.chronodb.internal.api.stream; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.api.key.ChronoIdentifier; import org.chronos.chronodb.internal.impl.stream.entry.ChronoDBEntryImpl; public interface ChronoDBEntry { // ===================================================================================================================== // STATIC FACTORY // ===================================================================================================================== public static ChronoDBEntry create(final ChronoIdentifier identifier, final byte[] value) { checkNotNull(identifier, "Precondition violation - argument 'identifier' must not be NULL!"); return ChronoDBEntryImpl.create(identifier, value); } // ===================================================================================================================== // PUBLIC API // ===================================================================================================================== public ChronoIdentifier getIdentifier(); public byte[] getValue(); }
1,113
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ObjectOutput.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/stream/ObjectOutput.java
package org.chronos.chronodb.internal.api.stream; import java.io.ObjectOutputStream; /** * An {@link ObjectOutput} is a minimal interface for writing arbitrary objects to a data sink. * * <p> * Please note that this interface is different from {@link ObjectOutputStream} in that it provides only a fraction of * the methods and functionality. This interface is used to keep the dependency towards the externalization mechanism to * a bare minimum. * * <p> * As this class extends {@link AutoCloseable}, instances of this class must be {@linkplain #close() closed} explicitly. * However, the Java 7 <code>try-with-resources</code> statement may be used for doing so. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface ObjectOutput extends AutoCloseable { /** * Writes the given object to the output. * * @param object * The object to write. Some implementations may refuse to write the <code>null</code> object. */ public void write(Object object); /** * Closes this object output. * * <p> * Any further call to {@link #write(Object)} will fail with an appropriate exception. */ @Override public void close(); }
1,208
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoIndexDocument.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/index/ChronoIndexDocument.java
package org.chronos.chronodb.internal.api.index; import org.chronos.chronodb.api.ChronoDBTransaction; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.key.ChronoIdentifier; import org.chronos.chronodb.internal.api.Period; /** * A {@link ChronoIndexDocument} is an abstraction across all indexing backends. * * <p> * This interface is essentially just a (largely immutable) collection of primitive values: * <ul> * <li>Document ID (immutable): {@link #getDocumentId()} * <li>Branch Name (immutable): {@link #getBranch()} * <li>Keyspace Name (immutable): {@link #getKeyspace()} * <li>Key (immutable): {@link #getKey()} * <li>Index Name (immutable): {@link #getIndexName()} * <li>Indexed Value (immutable): {@link #getIndexedValue()} * <li>"Valid From" timestamp (immutable): {@link #getValidFromTimestamp()} * <li>"Valid To" timestamp (mutable): {@link #getValidToTimestamp()}, {@link #setValidToTimestamp(long)} * </ul> * * <p> * Collectively, these properties define a <i>single entry</i> in an index. The entry contains all properties required for a {@link ChronoIdentifier}, alongside the index name to which it belongs, and the value that was retrieved by the indexer for the object in question. In order to allow for temporal indexing, a "valid from" and "valid to" timestamp are used. An index document can only be considered for a transaction if: * <ul> * <li>{@link #getValidFromTimestamp()} <= {@link ChronoDBTransaction#getTimestamp()} * <li>{@link ChronoDBTransaction#getTimestamp()} < {@link #getValidToTimestamp()} * </ul> * * <p> * The general idea behind this validity range is that when a value of a key is changed, the "valid to" timestamp of the currently valid index document is set to the transaction timestamp, and a new index document is spawned for the new value, starting with "valid from" at the transaction timestamp. * * <p> * This class has the following implicit invariants: * <ul> * <li>The "valid from" timestamp must always be strictly smaller than "valid to". * <li>The "valid to" timestamp of a document that is newly created is set to {@link Long#MAX_VALUE}. * <li>The "valid to" timestamp may be changed, but it may only be decreased, never increased. * <li>The "valid to" timestamp may not be decreased to a value lower than or equal to the "now" timestamp of the branch. * </ul> * * <p> * Instances of this class are not to be created by clients; they are created internally by the indexing API (usually by an {@link DocumentBasedIndexManagerBackend}) and should never be exposed to the public API. * * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoIndexDocument { /** * Returns the universally unique id of this document (immutable property). * * @return The UUID of this document as a string. Never <code>null</code>. */ public String getDocumentId(); /** * Returns the name of the index to which this document belongs (immutable property). * * @return The index name. Never <code>null</code>. */ public SecondaryIndex getIndex(); /** * Returns the name of the branch in which the value represented by this document was indexed (immutable property). * * @return The branch name. Never <code>null</code>. */ public String getBranch(); /** * Returns the name of the keyspace in which the value represented by this document was indexed (immutable property). * * @return The keyspace name. Never <code>null</code>. */ public String getKeyspace(); /** * Returns the key that references the indexed value represented by this document (immutable property). * * @return The key. Never <code>null</code>. */ public String getKey(); /** * Returns the indexed value represented by this document (immutable property). * * @return The indexed value. Never <code>null</code>. */ public Object getIndexedValue(); /** * Returns the "valid from" timestamp. This corresponds to the timestamp at which this document was written (immutable property). * * <p> * Any transaction which has "valid from <= timestamp < valid to" may read and must consider this document for index queries. * * @return The "valid from" timestamp. Never negative. */ public long getValidFromTimestamp(); /** * Returns the "valid to" timestamp (mutable property). * * <p> * Initially, this will be set to {@link Long#MAX_VALUE} until a new value is assigned to the key, in which case this value is decremented to indicate the termination of the validity interval. * * <p> * Any transaction which has "valid from <= timestamp < valid to" may read and must consider this document for index queries. * * @return The "valid to" timestamp. */ public long getValidToTimestamp(); /** * Sets the "valid to" timestamp to the given value. * * <p> * Note that the "valid to" timestamp may only be decremented, but never incremented. It must never be decremented to a value lower than the "now" timestamp of the current branch. It must also never be lower than or equal to the "valid from" timestamp. * * <p> * Any transaction which has "valid from <= timestamp < valid to" may read and must consider this document for index queries. * * @param validTo * The new "valid to" value. Subject to the constraints explained above. Must not be negative. */ public void setValidToTimestamp(long validTo); public default Period getValidPeriod(){ return Period.createRange(this.getValidFromTimestamp(), this.getValidToTimestamp()); } }
5,578
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoIndexDocumentModifications.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/index/ChronoIndexDocumentModifications.java
package org.chronos.chronodb.internal.api.index; import static com.google.common.base.Preconditions.*; import java.util.Map; import java.util.Set; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.key.ChronoIdentifier; import org.chronos.chronodb.internal.impl.index.ChronoIndexDocumentModificationsImpl; import com.google.common.collect.Maps; /** * Instances of this class represent a collection of modifications that should be applied on the secondary index. * * <p> * Essentially, this class is a wrapper around a collection of modification objects. The benefit of this class is the easier API compared to plain collections, as well as additional utility methods (e.g. {@link #groupByBranch()}). * * <p> * You can create a new instance of this class via the static factory method {@link #create()}. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoIndexDocumentModifications { // ================================================================================================================= // FACTORY // ================================================================================================================= /** * Creates a new, empty {@link ChronoIndexDocumentModifications} instance. * * @return The newly created instance. Never <code>null</code>. */ public static ChronoIndexDocumentModifications create() { return new ChronoIndexDocumentModificationsImpl(); } // ================================================================================================================= // API // ================================================================================================================= /** * Adds the given document validity termination to this collection of modifications. * * @param termination * The document termination to add. Must not be <code>null</code>. */ public void addDocumentValidityTermination(DocumentValidityTermination termination); /** * Returns the document validity terminations contained in this collection of modifications. * * @return The document validity terminations. Never <code>null</code>, may be empty. */ public Set<DocumentValidityTermination> getDocumentValidityTerminations(); /** * Adds the given document creation to this collection of modifications. * * @param creation * The document creation to add. Must not be <code>null</code>. */ public void addDocumentCreation(DocumentAddition creation); /** * Returns the set of document additions contained in this collection of modifications. * * @return The document additions. Never <code>null</code>, may be empty. */ public Set<DocumentAddition> getDocumentCreations(); /** * Adds the given document deletion to this collection of modifications. * * @param deletion * The document deletion to add. Must not be <code>null</code>. */ public void addDocumentDeletion(DocumentDeletion deletion); /** * Returns the set of document deletions contained in this collection of modifications. * * @return The document deletions. Never <code>null</code>, may be empty. */ public Set<DocumentDeletion> getDocumentDeletions(); /** * Checks if this collection of modifications is empty or not. * * @return <code>true</code> if there are no modifications contained in this collection, otherwise <code>false</code>. */ public boolean isEmpty(); // ================================================================================================================= // CONVENIENCE METHODS // ================================================================================================================= /** * Adds the validity termination of the given document at the given timestamp. * * @param document * The document to terminate the validity range for. Must not be <code>null</code>. * @param timestamp * The timestamp at which the validity should be terminated. Must not be negative. */ public default void addDocumentValidityTermination(final ChronoIndexDocument document, final long timestamp) { checkNotNull(document, "Precondition violation - argument 'document' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); DocumentValidityTermination termination = DocumentValidityTermination.create(document, timestamp); this.addDocumentValidityTermination(termination); } /** * Adds one validity termination for each of the given documents, at the given timestamp. * * @param documents * The documents to terminate the validity for. Must not be <code>null</code>. * @param timestamp * The timestamp at which to terminate the validity of the given documents. Must not be negative. */ public default void addDocumentValidityTermination(final Set<ChronoIndexDocument> documents, final long timestamp) { checkNotNull(documents, "Precondition violation - argument 'documents' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); for (ChronoIndexDocument document : documents) { this.addDocumentValidityTermination(document, timestamp); } } /** * Adds a new document addition with the given parameters. * * @param identifier * The {@link ChronoIdentifier} to which the new document should refer. Must not be <code>null</code>. * @param index * The name of the index to which the new document belongs. Must not be <code>null</code>. * @param indexValue * The indexed value to store in the new document. Must not be <code>null</code>. */ public default void addDocumentAddition(final ChronoIdentifier identifier, final SecondaryIndex index, final Object indexValue) { checkNotNull(identifier, "Precondition violation - argument 'identifier' must not be NULL!"); checkNotNull(index, "Precondition violation - argument 'index' must not be NULL!"); checkNotNull(indexValue, "Precondition violation - argument 'indexValue' must not be NULL!"); this.addDocumentCreation(DocumentAddition.create(identifier, index, indexValue)); } /** * Adds a new {@linkplain DocumentAddition document addition} for the given index document. * * @param indexDocument * The document to create the document addition for. Must not be <code>null</code>. */ public default void addDocumentAddition(final ChronoIndexDocument indexDocument) { checkNotNull(indexDocument, "Precondition violation - argument 'indexDocument' must not be NULL!"); this.addDocumentCreation(DocumentAddition.create(indexDocument)); } /** * Adds a new {@linkplain DocumentDeletion document deletion} for the given document. * * @param document * The document to add the deletion for. Must not be <code>null</code>. */ public default void addDocumentDeletion(final ChronoIndexDocument document) { checkNotNull(document, "Precondition violation - argument 'document' must not be NULL!"); this.addDocumentDeletion(DocumentDeletion.create(document)); } /** * Splits the modifications currently stored in this object into new modifications, grouped by branch. * * <p> * This will <b>not</b> change the current state of this object. Any further modifications to this object will <b>not</b> be reflected in the resulting groups. * * <p> * If a branch has no modifications in this object, there will be <b>no entry</b> for that branch in the resulting map. * * @return The mapping from branch name to modifications. Never <code>null</code>, may be empty. */ public default Map<String, ChronoIndexDocumentModifications> groupByBranch() { Map<String, ChronoIndexDocumentModifications> branchToModifications = Maps.newHashMap(); for (DocumentAddition addition : this.getDocumentCreations()) { String branch = addition.getDocumentToAdd().getBranch(); ChronoIndexDocumentModifications branchModifications = branchToModifications.get(branch); if (branchModifications == null) { branchModifications = ChronoIndexDocumentModifications.create(); branchToModifications.put(branch, branchModifications); } branchModifications.addDocumentCreation(addition); } for (DocumentDeletion deletion : this.getDocumentDeletions()) { String branch = deletion.getDocumentToDelete().getBranch(); ChronoIndexDocumentModifications branchModifications = branchToModifications.get(branch); if (branchModifications == null) { branchModifications = ChronoIndexDocumentModifications.create(); branchToModifications.put(branch, branchModifications); } branchModifications.addDocumentDeletion(deletion); } for (DocumentValidityTermination validityTermination : this.getDocumentValidityTerminations()) { String branch = validityTermination.getDocument().getBranch(); ChronoIndexDocumentModifications branchModifications = branchToModifications.get(branch); if (branchModifications == null) { branchModifications = ChronoIndexDocumentModifications.create(); branchToModifications.put(branch, branchModifications); } branchModifications.addDocumentValidityTermination(validityTermination); } return branchToModifications; } }
9,379
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DocumentValidityTermination.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/index/DocumentValidityTermination.java
package org.chronos.chronodb.internal.api.index; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.internal.impl.index.DocumentValidityTerminationImpl; /** * Change operation that terminates the upper validity limit of a {@link ChronoIndexDocument}. * * <p> * Each index document has a time validity range, expressed as {@linkplain ChronoIndexDocument#getValidFromTimestamp() from} and {@linkplain ChronoIndexDocument#getValidToTimestamp() to} timestamps. This operation "terminates" the validity range by reducing the "to" value from infinity to a fixed value. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface DocumentValidityTermination { /** * Creates a new {@link DocumentValidityTermination} for the given document, at the given timestamp. * * @param document * The document to terminate the validity range for. Must not be <code>null</code>. * @param terminationTimestamp * The timestamp to terminate the upper validity range at. Must not be negative. Must be after the document's "from" value. * * @return The newly created document validity termination. Never <code>null</code>. */ public static DocumentValidityTermination create(final ChronoIndexDocument document, final long terminationTimestamp) { checkNotNull(document, "Precondition violation - argument 'document' must not be NULL!"); checkArgument(terminationTimestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkArgument(terminationTimestamp > document.getValidFromTimestamp(), "Precondition violation - document validity cannot be terminated before/at the documents creation timestamp!"); return new DocumentValidityTerminationImpl(document, terminationTimestamp); } /** * Returns the document to terminate the validity range for when executing this operation. * * @return The document to termintate the validity range for. Never <code>null</code>. */ public ChronoIndexDocument getDocument(); /** * Returns the termination timestamp, i.e. the new "valid to" timestamp for {@linkplain #getDocument() the document}. * * @return The new valid-to timestamp. Always positive, always greater than the "valid from" timestamp of the document. */ public long getTerminationTimestamp(); }
2,406
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DocumentBasedIndexManagerBackend.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/index/DocumentBasedIndexManagerBackend.java
package org.chronos.chronodb.internal.api.index; import java.util.Collection; import java.util.Map; import org.chronos.chronodb.api.Branch; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.key.ChronoIdentifier; import org.chronos.chronodb.internal.api.query.searchspec.SearchSpecification; import com.google.common.collect.SetMultimap; /** * <p> * The basic idea of this kind of indexing comes from Apache Lucene. The document analogy was adapted for ChronoDB indexing. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface DocumentBasedIndexManagerBackend { // ================================================================================================================= // INDEXER MANAGEMENT // ================================================================================================================= /** * Deletes the contents of all indices. * * <p> * The indexers themselves are unaffected by this method. */ public void deleteAllIndexContents(); /** * Deletes the contents of the index with the given name. * * @param index * The index to delete the contents for. Must not be <code>null</code>. */ public void deleteIndexContents(SecondaryIndex index); // ================================================================================================================= // INDEX DOCUMENT MANAGEMENT // ================================================================================================================= /** * Applies the given {@linkplain ChronoIndexDocumentModifications index modifications} to this index. * * @param indexModifications * The index modifications to apply. Must not be <code>null</code>. */ public void applyModifications(ChronoIndexDocumentModifications indexModifications); // ================================================================================================================= // INDEX QUERYING // ================================================================================================================= /** * Returns the set of {@link ChronoIndexDocument}s that match the given search specification at the given timestamp, in the given branch. * * <p> * This method also searches through the origin branches (recursively). It returns only the most recent documents (up to and including the given timestamp). * * @param timestamp * The timestamp up to which the documents should be searched. Must not be negative. * @param branch * The branch in which to start the search. Origin branches will be searched as well (recursively). Must not be <code>null</code>. * @param keyspace * The keyspace to search in. Must not be <code>null</code>. * @param searchSpec * The search specification to fulfill. Must not be <code>null</code>. * * @return The set of documents that match the given search criteria. May be empty, but never <code>null</code>. */ public Collection<ChronoIndexDocument> getMatchingDocuments(long timestamp, Branch branch, String keyspace, SearchSpecification<?,?> searchSpec); /** * Queries the indexer state to return all documents that match the given {@link ChronoIdentifier}. * * <p> * This search does <b>not</b> include origin branches. It only searches directly on the branch indicated by the given identifier. * * @param chronoIdentifier * The identifier to get the index documents for. Must not be <code>null</code>. * @return A mapping from indexer name to a map from indexed value to the index document that holds this value. May be empty, but never <code>null</code>. */ public Map<SecondaryIndex, SetMultimap<Object, ChronoIndexDocument>> getMatchingBranchLocalDocuments( ChronoIdentifier chronoIdentifier); }
3,943
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DocumentAddition.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/index/DocumentAddition.java
package org.chronos.chronodb.internal.api.index; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.api.SecondaryIndex; import org.chronos.chronodb.api.key.ChronoIdentifier; import org.chronos.chronodb.internal.impl.index.DocumentAdditionImpl; /** * Change operation that adds a {@link ChronoIndexDocument} to the secondary index. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface DocumentAddition { /** * Creates a new {@link DocumentAddition} instance with the given parameters. * * <p> * When the addition created by this method is being executed, a new {@link ChronoIndexDocument} with the given parameters will be created on the fly. * * @param identifier * The {@link ChronoIdentifier} to which the new document should refer. Must not be <code>null</code>. * @param index * The index to which the new document should belong. Must not be <code>null</code>. * @param indexValue * The indexed value to store in the new document. Must not be <code>null</code>. * * @return The newly created document addition. Never <code>null</code>. */ public static DocumentAddition create(final ChronoIdentifier identifier, final SecondaryIndex index, final Object indexValue) { checkNotNull(identifier, "Precondition violation - argument 'identifier' must not be NULL!"); checkNotNull(index, "Precondition violation - argument 'index' must not be NULL!"); checkNotNull(indexValue, "Precondition violation - argument 'indexValue' must not be NULL!"); return new DocumentAdditionImpl(identifier, index, indexValue); } /** * Creates a new {@link DocumentAddition} for the given document. * * @param documentToAdd * The document to store in the addition. Must not be <code>null</code>. * * @return The newly created document addition. Never <code>null</code>. */ public static DocumentAddition create(final ChronoIndexDocument documentToAdd) { checkNotNull(documentToAdd, "Precondition violation - argument 'documentToAdd' must not be NULL!"); return new DocumentAdditionImpl(documentToAdd); } /** * Returns the document that should be added. * * @return The document to add when executing this operation. Never <code>null</code>. */ public ChronoIndexDocument getDocumentToAdd(); }
2,377
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DocumentDeletion.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/index/DocumentDeletion.java
package org.chronos.chronodb.internal.api.index; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.internal.impl.index.DocumentDeletionImpl; /** * Change operation that deletes a {@link ChronoIndexDocument} from the secondary index. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface DocumentDeletion { /** * Creates a new {@link DocumentDeletion} for the given document. * * @param documentToDelete * The document to delete from the secondary index. Must not be <code>null</code>. * * @return The newly created document deletion. Never <code>null</code>. */ public static DocumentDeletion create(final ChronoIndexDocument documentToDelete) { checkNotNull(documentToDelete, "Precondition violation - argument 'documentToDelete' must not be NULL!"); return new DocumentDeletionImpl(documentToDelete); } /** * Returns the document to delete when executing this operation. * * @return The document to delete. Never <code>null</code>. */ public ChronoIndexDocument getDocumentToDelete(); }
1,111
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
CacheGetResult.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/cache/CacheGetResult.java
package org.chronos.chronodb.internal.api.cache; import org.chronos.chronodb.api.exceptions.CacheGetResultNotPresentException; import org.chronos.chronodb.internal.impl.cache.CacheGetResultImpl; /** * A {@link CacheGetResult} represents the result of calling * {@link ChronoDBCache#get(String, long, org.chronos.chronodb.api.key.QualifiedKey)}. * * <p> * An instance of this class may either represent a cache <i>hit</i>, in which case {@link #isHit()} returns * <code>true</code> and {@link #getValue()} delivers the actual result data, or it may represent a cache <i>miss</i> , * in which case {@link #isHit()} returns <code>false</code> and {@link #getValue()} will always throw a * {@link CacheGetResultNotPresentException}. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * * @param <T> * The type of the actual result data contained in this cache get result. Used for the return type of * {@link #getValue()}. */ public interface CacheGetResult<T> { /** * Returns the singleton {@link CacheGetResult} instance representing a cache miss. * * <p> * Calling {@link #isHit()} on the returned instance will always return <code>false</code>. Calling * {@link #getValue()} on the returned instance will always throw a {@link CacheGetResultNotPresentException}. * * @return The singleton instance representing a cache miss. Never <code>null</code>. * * @param <T> * The data type of the value returned by {@link #getValue()}. In this case, this parameter is never * used, as {@link #getValue()} always throws a {@link CacheGetResultNotPresentException}. */ public static <T> CacheGetResult<T> miss() { return CacheGetResultImpl.getMiss(); } /** * Creates a new {@link CacheGetResult} instance representing a cache hit. * * <p> * An instance created by this method will never throw a {@link CacheGetResultNotPresentException} on * {@link #getValue()}. * * @param value * The result value to return in {@link #getValue()} in the new instance. * @param validFrom * The insertion timestamp of the given value into the store, i.e. the greatest change timestamp of the * request key that is less than or equal to the transaction timestamp. Must not be negative. * * @return The newly created cache get result instance. Never <code>null</code>. * * @param <T> * The data type of the value returned by {@link #getValue()}. */ public static <T> CacheGetResult<T> hit(final T value, final long validFrom) { return CacheGetResultImpl.getHit(value, validFrom); } /** * Checks if this cache result represents a "cache hit". * * <p> * If this method returns <code>true</code>, then {@link #getValue()} returns the actual result value. If this * method returns <code>false</code>, then {@link #getValue()} will always throw a * {@link CacheGetResultNotPresentException}. * * @return <code>true</code> if this result represents a cache hit, or <code>false</code> if it represents a cache * miss. * * @see #isMiss() */ public boolean isHit(); /** * Returns the value associated with this cache query result. * * <p> * If {@link #isHit()} returns <code>true</code>, then this method will return the actual result value. If * {@link #isHit()} returns <code>false</code>, this method will always throw a * {@link CacheGetResultNotPresentException}. * * @return The actual query result. * * @throws CacheGetResultNotPresentException * Thrown if this instance represents a cache miss (<code>this.</code>{@link #isHit()} returns * <code>false</code>) and <code>this.</code>{@link #getValue()} is called. */ public T getValue() throws CacheGetResultNotPresentException; /** * Returns the timestamp from which onward the {@link #getValue() value} was valid in the store. * * <p> * Please note that the returned value will always be less than or equal to the timestamp of your current * transaction; newer values may have been set on this key after the transaction timestamp. Those newer timestamps * will not be reflected here. In other words, this method returns the greatest change timestamp of the request key * which is less than or equal to the transaction timestamp. * * @return The "valid from" timestamp of the key-value pair. * @throws CacheGetResultNotPresentException * Thrown if this instance represents a cache miss (<code>this.</code>{@link #isHit()} returns * <code>false</code>) and <code>this.</code>{@link #getValidFrom()} is called. */ public long getValidFrom() throws CacheGetResultNotPresentException; /** * Checks if this cache result represents a "cache miss". * * <p> * If this method returns <code>true</code>, then {@link #getValue()} will always throw a * {@link CacheGetResultNotPresentException}. If this method returns <code>false</code>, then {@link #getValue()} * will return the actual result data. * * @return <code>true</code> if this result represents a cache miss, or <code>false</code> if it represents a cache * hit. * * @see #isHit() */ public default boolean isMiss() { return this.isHit() == false; } }
5,297
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBCache.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/api/cache/ChronoDBCache.java
package org.chronos.chronodb.internal.api.cache; import org.chronos.chronodb.api.key.QualifiedKey; import org.chronos.chronodb.internal.api.ChronoDBConfiguration; import org.chronos.chronodb.internal.api.GetResult; import org.chronos.chronodb.internal.impl.cache.bogus.ChronoDBBogusCache; import org.chronos.chronodb.internal.impl.cache.headfirst.HeadFirstCache; import org.chronos.chronodb.internal.impl.cache.mosaic.MosaicCache; import java.util.Map; import java.util.Map.Entry; import static com.google.common.base.Preconditions.*; /** * The {@link ChronoDBCache} is responsible for caching {@link GetResult}s. * * <p> * This helps to reduce accesses to the underlying store, which in turn reduces the need for I/O operations. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoDBCache { // ===================================================================================================================== // FACTORY METHODS // ===================================================================================================================== /** * Creates a new cache according to the settings in the given configuration. * * @param config The configuration to read the cache settings from. Must not be <code>null</code>. * @return A cache instance matching the given configuration. Never <code>null</code>. */ public static ChronoDBCache createCacheForConfiguration(final ChronoDBConfiguration config) { checkNotNull(config, "Precondition violation - argument 'config' must not be NULL!"); if (config.isCachingEnabled()) { switch (config.getCacheType()) { case MOSAIC: return new MosaicCache(config.getCacheMaxSize()); case HEAD_FIRST: return new HeadFirstCache( config.getCacheMaxSize(), config.getCacheHeadFirstPreferredBranch(), config.getCacheHeadFirstPreferredKeyspace() ); } } return new ChronoDBBogusCache(); } // ===================================================================================================================== // PUBLIC API // ===================================================================================================================== /** * Queries the cache for the entry with the given key at the given branch and timestamp. * * @param branch The branch to search in. Must not be <code>null</code>. * @param timestamp The timestamp to search at. Must not be <code>null</code>. * @param qualifiedKey The qualified key to search for. Must not be <code>null</code>. * @return The result. Never <code>null</code>. May be a {@linkplain CacheGetResult#isMiss() cache miss}. */ public <T> CacheGetResult<T> get(String branch, long timestamp, QualifiedKey qualifiedKey); /** * Adds the given {@link GetResult} to this cache. * * @param branch The branch that was requested. Must not be <code>null</code>. * @param queryResult The result of the query that should be cached. Must not be <code>null</code>. */ public void cache(String branch, GetResult<?> queryResult); /** * Writes the given key-value pair through the cache. * * <p> * This is similar to {@link #cache(String, GetResult)}, except that this method works directly on the <code>value</code> object instead of a {@link GetResult}. * * <p> * This method assumes that the validity period of the given key-value pair is open-ended at the righthand side. * * @param branch The branch of the entry to write through the cache. * @param timestamp The timestamp of the entry to write through the cache. * @param key The qualified key of the key-value pair * @param value The value of the key-value pair */ public void writeThrough(String branch, long timestamp, QualifiedKey key, Object value); /** * Retrieves the current number of entries in the cache. * * @return The current size of the cache. Never negative, may be zero. */ public int size(); /** * Returns the maximum number of entries permitted in this cache. * * Implementations that do not have a hard limit should return -1. * * @return The maximum size of this cache. */ public int maxSize(); /** * Returns the statistics of this cache. * * <p> * This method will return a <b>copy</b> of the statistics. Any modifications on the cache (including {@link #resetStatistics()}) will have <b>no influence</b> on the returned statistics object. * * @return A copy of the statistics. Never <code>null</code>. */ public CacheStatistics getStatistics(); /** * Resets the statistics of this cache. */ public void resetStatistics(); /** * Completely clears the contents of this cache, eliminating all entries from it. */ public void clear(); /** * Rolls the cache back to the specified timestamp, i.e. removes all entries that are newer than the specified timestamp. * * @param timestamp The timestamp to roll back to. Must not be negative. */ public void rollbackToTimestamp(long timestamp); /** * Writes the given map of key-value pairs through this cache i.e. adds all entries to the cache. * * <p> * This method assumes that the validity range of all pairs is open-ended on the righthand side. * * @param branch The branch to associate the entries with. Must not be <code>null</code>. * @param timestamp The timestamp to associate the entries with. Must not be <code>null</code>. * @param keyValues The key-value pairs to write through the cache. May be empty, but must not be <code>null</code>. */ public default void writeThrough(final String branch, final long timestamp, final Map<QualifiedKey, Object> keyValues) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(keyValues, "Precondition violation - argument 'keyValues' must not be NULL!"); for (Entry<QualifiedKey, Object> entry : keyValues.entrySet()) { this.writeThrough(branch, timestamp, entry.getKey(), entry.getValue()); } } // ===================================================================================================================== // INNER INTERFACES // ===================================================================================================================== /** * This interface describes a set of statistics that can be retrieved about a {@link ChronoDBCache}. * * <p> * Use {@link ChronoDBCache#getStatistics()} to retrieve an instance of this interface. * * @author martin.haeusler@uibk.ac.at -- Initial contribution and API */ public interface CacheStatistics { /** * Returns the number of cache hits recorded in this cache. * * <p> * A cache hit is a request to {@link ChronoDBCache#get(String, long, QualifiedKey)} that returns a {@linkplain CacheGetResult result} that represents a {@linkplain CacheGetResult#isHit() hit}. * * @return The number of cache hits. Never negative, may be zero. */ public long getCacheHitCount(); /** * Returns the number of cache misses recorded in this cache. * * <p> * A cache miss is a request to {@link ChronoDBCache#get(String, long, QualifiedKey)} that returns a {@linkplain CacheGetResult result} that represents a {@linkplain CacheGetResult#isMiss() miss}. * * @return The number of cache misses. Never negative, may be zero. */ public long getCacheMissCount(); /** * Returns the number of elements that have been evicted from this cache due to limited population size. * * Evictions due to cache clearing or rollback do not count towards this number. * * Implementations without a hard limit on the population size should return 0. * * @return The number of elements removed from the cache due to the eviction policy. */ public long getEvictionCount(); /** * Returns the number of times a rollback has occurred on this cache. * * @return The number of times a rollback has occurred so far. */ public long getRollbackCount(); /** * Returns the number of times this cache has been explicitly cleared. * * @return The number of times this cache has been explicitly cleared. */ public long getClearCount(); /** * Returns the request count, i.e. the number of {@link ChronoDBCache#get(String, long, QualifiedKey)} calls received by this cache. * * @return The request count. May be zero, but never negative. */ public default long getRequestCount() { return getCacheHitCount() + getCacheMissCount(); } /** * Returns the cache hit ratio. * * <p> * The cache hit ratio is the {@link #getCacheHitCount()} divided by the {@link #getRequestCount()}. * * <p> * The sum of the {@linkplain #getCacheHitRatio() hit ratio} and the {@linkplain #getCacheMissRatio() miss ratio} is always equal to 1 (modulo precision errors), except when the {@linkplain #getRequestCount() request count} is zero. * * @return The cache hit count. Will be {@link Double#NaN NaN} if the {@linkplain #getRequestCount() request count} is zero. */ public default double getCacheHitRatio() { long requestCount = this.getRequestCount(); if (requestCount == 0) { // by definition, if we have no requests, we have no hit ratio return Double.NaN; } return ((double) getCacheHitCount()) / requestCount; } /** * Returns the cache miss ratio. * * <p> * The cache miss ratio is the {@link #getCacheMissCount()} divided by the {@link #getRequestCount()}. * * <p> * The sum of the {@linkplain #getCacheHitRatio() hit ratio} and the {@linkplain #getCacheMissRatio() miss ratio} is always equal to 1 (modulo precision errors), except when the {@linkplain #getRequestCount() request count} is zero. * * @return The cache miss count. Will be {@link Double#NaN NaN} if the {@linkplain #getRequestCount() request count} is zero. */ public default double getCacheMissRatio() { long requestCount = this.getRequestCount(); if (requestCount == 0) { // by definition, if we have no requests, we have no miss ratio return Double.NaN; } return ((double) getCacheMissCount()) / requestCount; } } }
11,408
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
KeySetModifications.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/KeySetModifications.java
package org.chronos.chronodb.internal.util; import static com.google.common.base.Preconditions.*; import java.util.Collections; import java.util.Set; import com.google.common.collect.Sets; public class KeySetModifications { private final Set<String> additions; private final Set<String> removals; public KeySetModifications(Set<String> additions, Set<String> removals) { checkNotNull(additions, "Precondition violation - argument 'additions' must not be NULL!"); checkNotNull(removals, "Precondition violation - argument 'removals' must not be NULL!"); this.additions = Collections.unmodifiableSet(Sets.newHashSet(additions)); this.removals = Collections.unmodifiableSet(Sets.newHashSet(removals)); } public Set<String> getAdditions() { return this.additions; } public Set<String> getRemovals() { return this.removals; } public void apply(Set<String> baseSet) { baseSet.addAll(this.additions); baseSet.removeAll(this.removals); } }
968
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronosFileUtils.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/ChronosFileUtils.java
package org.chronos.chronodb.internal.util; import com.google.common.base.Charsets; import com.google.common.collect.Lists; import com.google.common.collect.Streams; import com.google.common.hash.HashCode; import com.google.common.hash.Hashing; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.file.Files; import java.util.List; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; import static com.google.common.base.Preconditions.*; public class ChronosFileUtils { private static final int UNZIP_BUFFER_SIZE_BYTES = 4096; private static final Logger log = LoggerFactory.getLogger(ChronosFileUtils.class); private ChronosFileUtils() { throw new UnsupportedOperationException("Do not instantiate this class!"); } public static boolean isGZipped(final File file) { // code taken from: http://stackoverflow.com/a/30507742/3094906 int magic = 0; try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { magic = raf.read() & 0xff | raf.read() << 8 & 0xff00; } catch (Exception e) { log.error("Failed to read file '" + file.getAbsolutePath() + "'!", e); } return magic == GZIPInputStream.GZIP_MAGIC; } public static boolean isExistingFile(final File file) { if (file == null) { return false; } if (file.exists() == false) { return false; } if (file.isFile() == false) { return false; } return true; } /** * Extracts the given zip file into the given target directory. * * @param zipFile The *.zip file to extract. Must not be <code>null</code>, must refer to an existing file. * @param targetDirectory The target directory to extract the data to. Must not be <code>null</code>, must be an existing directory. * @throws IOException Thrown if an I/O error occurs during the process. */ public static void extractZipFile(final File zipFile, final File targetDirectory) throws IOException { checkNotNull(zipFile, "Precondition violation - argument 'zipFile' must not be NULL!"); checkNotNull(targetDirectory, "Precondition violation - argument 'targetDirectory' must not be NULL!"); checkArgument(zipFile.exists(), "Precondition violation - argument 'zipFile' must refer to an existing file!"); checkArgument(targetDirectory.exists(), "Precondition violation - argument 'targetDirectory' must refer to an existing file!"); checkArgument(zipFile.isFile(), "Precondition violation - argument 'zipFile' must point to a file (not a directory)!"); checkArgument(targetDirectory.isDirectory(), "Precondition violation - argument 'targetDirectory' must point to a directory (not a file)!"); try (ZipInputStream zin = new ZipInputStream(new FileInputStream(zipFile))) { ZipEntry entry; String name; String dir; while ((entry = zin.getNextEntry()) != null) { name = entry.getName(); if (entry.isDirectory()) { mkdirs(targetDirectory, name); continue; } /* * this part is necessary because file entry can come before directory entry where is file located i.e.: /foo/foo.txt /foo/ */ dir = dirpart(name); if (dir != null) { mkdirs(targetDirectory, dir); } extractFile(zin, targetDirectory, name); } } } private static void extractFile(final ZipInputStream in, final File outdir, final String name) throws IOException { byte[] buffer = new byte[UNZIP_BUFFER_SIZE_BYTES]; try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(outdir, name)))) { int count = -1; while ((count = in.read(buffer)) != -1) { out.write(buffer, 0, count); } } } private static void mkdirs(final File outdir, final String path) { File d = new File(outdir, path); if (!d.exists()) { d.mkdirs(); } } private static String dirpart(final String name) { int s = name.lastIndexOf(File.separatorChar); return s == -1 ? null : name.substring(0, s); } /** * Zips the given file and stores the result in the given target file. * * @param fileToZip The file to zip. Must not be <code>null</code>. Must exist. May be a file or a directory. Zipping a directory will recursively zip all contents. * @param targetZipFile The target zip file to hold the compressed contents. Must not be <code>null</code>, must not be a directory. Will be created if it doesn't exist. Existing files will be overwritten. */ public static void createZipFile(File fileToZip, File targetZipFile) throws IOException { checkNotNull(fileToZip, "Precondition violation - argument 'fileToZip' must not be NULL!"); checkArgument(fileToZip.exists(), "Precondition violation - argument 'fileToZip' must exist!"); checkNotNull(targetZipFile, "Precondition violation - argument 'targetZipFile' must not be NULL!"); if (targetZipFile.exists()) { checkArgument(targetZipFile.isFile(), "Precondition violation - argument 'targetZipFile' must not be a directory!"); Files.delete(targetZipFile.toPath()); } Files.createFile(targetZipFile.toPath()); try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(targetZipFile))) { zipFile(fileToZip, fileToZip.getName(), zipOut); } } private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException { if (fileToZip.isHidden()) { return; } if (fileToZip.isDirectory()) { if (fileName.endsWith("/")) { zipOut.putNextEntry(new ZipEntry(fileName)); zipOut.closeEntry(); } else { zipOut.putNextEntry(new ZipEntry(fileName + "/")); zipOut.closeEntry(); } File[] children = fileToZip.listFiles(); for (File childFile : children) { zipFile(childFile, fileName + "/" + childFile.getName(), zipOut); } } else { try (FileInputStream fis = new FileInputStream(fileToZip)) { ZipEntry zipEntry = new ZipEntry(fileName); zipOut.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zipOut.write(bytes, 0, length); } } } } /** * Calculates the sha256 hash of the given file or directory * * @param file a folder or file * @return the calculated sha256 hash */ public static HashCode sha256OfContent(File file) { checkNotNull(file, "Precondition violation - argument 'file' must not be NULL!"); return sha256Internal(file, null); } /** * Calculates the sha256 hash of the given file or directory * * @param file a folder or file * @param pathPrefix the prefix to ignore when calculating the hash for filepaths * @return the calculated sha256 hash */ public static HashCode sha256OfContentAndFileName(File file, String pathPrefix) { checkNotNull(file, "Precondition violation - argument 'file' must not be NULL!"); checkNotNull(pathPrefix, "Precondition violation - argument 'pathPrefix' must not be NULL!"); return sha256Internal(file, pathPrefix); } private static HashCode sha256Internal(File file, String pathPrefix){ checkNotNull(file, "Precondition violation - argument 'file' must not be NULL!"); checkArgument(file.exists(), "Precondition violation - argument 'file' must exist!"); try { if(file.isFile()){ HashCode hash = getContentHashCode(file); if(pathPrefix != null){ HashCode pathHash = getPathHashCode(file, pathPrefix); return Hashing.combineUnordered(Lists.newArrayList(hash, pathHash)); }else{ return hash; } } else { Iterable<File> files = com.google.common.io.Files.fileTraverser() .depthFirstPostOrder(file); List<HashCode> hashCodes = Streams.stream(files).map(f -> { if(f.isFile()){ return sha256Internal(f, pathPrefix); }else{ return getPathHashCode(f, pathPrefix); } }).collect(Collectors.toList()); return Hashing.combineUnordered(hashCodes); } } catch (IOException e) { throw new IllegalArgumentException("The given file \"" + file.getName() + "\" is not an archive and thus can not be extracted"); } } private static HashCode getContentHashCode(final File file) throws IOException { return com.google.common.io.Files.asByteSource(file).hash(Hashing.sha256()); } private static HashCode getPathHashCode(final File file, final String pathPrefix) { String absolutePath = file.getAbsolutePath(); String path; if(absolutePath.startsWith(pathPrefix)){ path = absolutePath.substring(pathPrefix.length()); }else{ path = absolutePath; } return Hashing.sha256().hashString(path.replaceAll("[\\\\/]", ""), Charsets.UTF_8); } }
10,180
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ThreadBound.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/ThreadBound.java
package org.chronos.chronodb.internal.util; import static com.google.common.base.Preconditions.*; import java.lang.ref.WeakReference; import java.util.Map; import com.google.common.collect.MapMaker; /** * A {@link ThreadBound} object is similar to a {@link ThreadLocal}, except that the memory management is different. * * <p> * In a regular {@link ThreadLocal}, the value is stored in the thread until the thread dies. This is true even if there is no way to access this value in regular Java code anymore. In a {@link ThreadBound} object, the value is cleared if: * * <ul> * <li>The thread dies and is GC'ed <b>OR</b> * <li>the object owning the {@link ThreadBound} is no longer reachable and GC'ed. * </ul> * * In contrast to {@link ThreadLocal}, this class also allows to clear the contained value for <b>all</b> threads via {@link #clearValueForAllThreads()}. * * @author martin.haeusler@uibk.ac.at * * @param <T> * The type of element contained in this object. */ public class ThreadBound<T> { // ================================================================================================================= // STATIC FACTORY METHODS // ================================================================================================================= /** * Creates a new {@link ThreadBound} instance. * * @return The newly created instance. Never <code>null</code>. */ public static <T> ThreadBound<T> create() { MapMaker mapMaker = new MapMaker(); Map<Thread, T> map = mapMaker.weakKeys().makeMap(); return new ThreadBound<>(map); } /** * Creates a new {@link ThreadBound} instance with {@linkplain WeakReference weakly referenced} values. * * @return The newly created instance. Never <code>null</code>. */ public static <T> ThreadBound<T> createWeakReference() { MapMaker mapMaker = new MapMaker(); Map<Thread, T> map = mapMaker.weakKeys().weakValues().makeMap(); return new ThreadBound<>(map); } // ================================================================================================================= // FIELDS // ================================================================================================================= /** This is the internal mapping from thread to bound value. Note that it is a weak hash map, i.e. GC'ed threads will be removed from the map. */ private final Map<Thread, T> map; // ================================================================================================================= // PUBLIC API // ================================================================================================================= /** * Creates a new {@link ThreadBound} instance. * * @param map * The map to use internally. Must not be <code>null</code>. */ private ThreadBound(final Map<Thread, T> map) { // private on purpose; use the static factory methods. checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); this.map = map; } /** * Returns the value associated with the current thread. * * @return The value. May be <code>null</code> if the thread does not have a value yet (or was explicitly assigned a <code>null</code> value). */ public synchronized T get() { return this.map.get(Thread.currentThread()); } /** * Associates the given value with the current thread. * * @param value * The value to store. May be <code>null</code>. * * @return The previous value. May be <code>null</code>. If no previous value existed for the given thread, <code>null</code> will be returned. */ public synchronized T set(final T value) { if (value == null) { return this.unset(); } return this.map.put(Thread.currentThread(), value); } /** * Removes the value associated with the current thread. * * <p> * After invoking this method, calls to {@link #get()} will always return <code>null</code> until a new, non-<code>null</code> value is assigned via {@link #set(Object)}. * * @return The previously assigned value. May be <code>null</code>. If no previous value existed for the given thread, <code>null</code> will be returned. */ public synchronized T unset() { return this.map.remove(Thread.currentThread()); } /** * Clears the stored value for all threads. * * <p> * After invoking this method, calls to {@link #get()} will always return <code>null</code> for all threads until a new, non-<code>null</code> value is assigned via {@link #set(Object)}. * */ public synchronized void clearValueForAllThreads() { this.map.clear(); } }
4,611
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ImmutableMapEntry.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/ImmutableMapEntry.java
package org.chronos.chronodb.internal.util; import java.util.Map; public class ImmutableMapEntry<K, V> implements Map.Entry<K, V> { public static <K, V> ImmutableMapEntry<K, V> create(final K key, final V value) { return new ImmutableMapEntry<K, V>(key, value); } private final K key; private final V value; public ImmutableMapEntry(final K key, final V value) { this.key = key; this.value = value; } @Override public K getKey() { return this.key; } @Override public V getValue() { return this.value; } @Override public V setValue(final V value) { throw new UnsupportedOperationException("setValue() is not supported on an ImmutableMapEntry!"); } }
684
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
Quadruple.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/Quadruple.java
package org.chronos.chronodb.internal.util; public class Quadruple<A, B, C, D> { public static <A, B, C, D> Quadruple<A, B, C, D> of(final A a, final B b, final C c, final D d) { return new Quadruple<>(a, b, c, d); } private final A a; private final B b; private final C c; private final D d; public Quadruple(final A a, final B b, final C c, final D d) { this.a = a; this.b = b; this.c = c; this.d = d; } public A getA() { return this.a; } public B getB() { return this.b; } public C getC() { return this.c; } public D getD() { return this.d; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (this.a == null ? 0 : this.a.hashCode()); result = prime * result + (this.b == null ? 0 : this.b.hashCode()); result = prime * result + (this.c == null ? 0 : this.c.hashCode()); result = prime * result + (this.d == null ? 0 : this.d.hashCode()); return result; } @Override @SuppressWarnings("rawtypes") public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } Quadruple other = (Quadruple) obj; if (this.a == null) { if (other.a != null) { return false; } } else if (!this.a.equals(other.a)) { return false; } if (this.b == null) { if (other.b != null) { return false; } } else if (!this.b.equals(other.b)) { return false; } if (this.c == null) { if (other.c != null) { return false; } } else if (!this.c.equals(other.c)) { return false; } if (this.d == null) { if (other.d != null) { return false; } } else if (!this.d.equals(other.d)) { return false; } return true; } @Override public String toString() { return "Quadruple [a=" + this.a + ", b=" + this.b + ", c=" + this.c + ", d=" + this.d + "]"; } }
1,932
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DataMatrixUtil.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/DataMatrixUtil.java
package org.chronos.chronodb.internal.util; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.chronos.chronodb.api.Order; import org.chronos.chronodb.api.key.QualifiedKey; import org.chronos.chronodb.api.key.TemporalKey; import org.chronos.chronodb.internal.api.GetResult; import org.chronos.chronodb.internal.api.Period; import org.chronos.chronodb.internal.impl.temporal.InverseUnqualifiedTemporalKey; import org.chronos.chronodb.internal.impl.temporal.UnqualifiedTemporalEntry; import org.chronos.chronodb.internal.impl.temporal.UnqualifiedTemporalKey; import org.chronos.common.exceptions.UnknownEnumLiteralException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.*; public class DataMatrixUtil { private static final Logger log = LoggerFactory.getLogger(DataMatrixUtil.class); public static GetResult<byte[]> get(final NavigableMap<String, byte[]> map, final String keyspace, final long timestamp, final String key) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); if(log.isTraceEnabled()){ log.trace("[GTR] keyspace = '" + keyspace + "', key = '" + key + "', timestamp = " + timestamp); } QualifiedKey qKey = QualifiedKey.create(keyspace, key); String temporalKey = UnqualifiedTemporalKey.create(key, timestamp).toSerializableFormat(); Entry<String, byte[]> floorEntry = map.floorEntry(temporalKey); Entry<String, byte[]> ceilEntry = map.higherEntry(temporalKey); UnqualifiedTemporalKey floorKey = null; if (floorEntry != null) { floorKey = UnqualifiedTemporalKey.parseSerializableFormat(floorEntry.getKey()); } UnqualifiedTemporalKey ceilKey = null; if (ceilEntry != null) { ceilKey = UnqualifiedTemporalKey.parseSerializableFormat(ceilEntry.getKey()); } if (floorEntry == null || floorKey.getKey().equals(key) == false) { // we have no "next lower" bound -> we already know that the result will be empty. // now we need to check if we have an upper bound for the validity of our empty result... if (ceilEntry == null || ceilKey.getKey().equals(key) == false) { // there is no value for this key (at all, not at any timestamp) return GetResult.createNoValueResult(qKey, Period.eternal()); } else if (ceilEntry != null && ceilKey.getKey().equals(key)) { // there is no value for this key, until a certain timestamp is reached Period period = Period.createRange(0, ceilKey.getTimestamp()); return GetResult.createNoValueResult(qKey, period); } } else { // we have a "next lower" bound -> we already know that the result will be non-empty. // now we need to check if we have an upper bound for the validity of our result... if (ceilEntry == null || ceilKey.getKey().equals(key) == false) { // there is no further value for this key, therefore we have an open-ended period Period range = Period.createOpenEndedRange(floorKey.getTimestamp()); byte[] value = floorEntry.getValue(); if (value != null && value.length <= 0) { // value is non-null, but empty -> it's effectively null value = null; } return GetResult.create(qKey, value, range); } else if (ceilEntry != null && ceilKey.getKey().equals(key)) { // the value of the result is valid between the floor and ceiling entries long floorTimestamp = floorKey.getTimestamp(); long ceilTimestamp = ceilKey.getTimestamp(); if (floorTimestamp >= ceilTimestamp) { log.error("Invalid 'getRanged' state - floor timestamp (" + floorTimestamp + ") >= ceil timestamp (" + ceilTimestamp + ")! Requested: '" + key + "@" + timestamp + "', floor: '" + floorKey + "', ceil: '" + ceilKey + "'"); } Period period = Period.createRange(floorKey.getTimestamp(), ceilKey.getTimestamp()); byte[] value = floorEntry.getValue(); if (value != null && value.length <= 0) { // value is non-null, but empty -> it's effectively null value = null; } return GetResult.create(qKey, value, period); } } // this code is effectively unreachable throw new RuntimeException("Unreachable code has been reached!"); } public static void put(final NavigableMap<String, byte[]> map, final NavigableMap<String, Boolean> inverseMap, final String keyspace, final long time, final Map<String, byte[]> contents) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(inverseMap, "Precondition violation - argument 'inverseMap' must not be NULL!"); for (Entry<String, byte[]> entry : contents.entrySet()) { String key = entry.getKey(); byte[] value = entry.getValue(); UnqualifiedTemporalKey tk = UnqualifiedTemporalKey.create(key, time); if (value != null) { if(log.isTraceEnabled()){ log.trace("[PUT] Key = '" + key + "', value = byte[" + value.length + "], timestamp = " + time); } map.put(tk.toSerializableFormat(), value); } else { if(log.isTraceEnabled()){ log.trace("[PUT] Key = '" + key + "', value = NULL, timestamp = " + time); } map.put(tk.toSerializableFormat(), new byte[0]); } InverseUnqualifiedTemporalKey itk = InverseUnqualifiedTemporalKey.create(time, key); if (value != null) { inverseMap.put(itk.toSerializableFormat(), true); } else { inverseMap.put(itk.toSerializableFormat(), false); } } } public static KeySetModifications keySetModifications(final NavigableMap<String, byte[]> map, final String keyspace, final long timestamp) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); // entry set is sorted in ascending order! Set<Entry<String, byte[]>> entrySet = map.entrySet(); Set<String> additions = Sets.newHashSet(); Set<String> removals = Sets.newHashSet(); // iterate over the full B-Tree key set (ascending order) Iterator<Entry<String, byte[]>> allEntriesIterator = entrySet.iterator(); while (allEntriesIterator.hasNext()) { Entry<String, byte[]> currentEntry = allEntriesIterator.next(); UnqualifiedTemporalKey currentKey = UnqualifiedTemporalKey.parseSerializableFormat(currentEntry.getKey()); if (currentKey.getTimestamp() > timestamp) { continue; } String plainKey = currentKey.getKey(); if (currentEntry.getValue() == null || currentEntry.getValue().length <= 0) { // removal additions.remove(plainKey); removals.add(plainKey); } else { // put additions.add(plainKey); removals.remove(plainKey); } } return new KeySetModifications(additions, removals); } public static Iterator<Long> history(final NavigableMap<String, byte[]> map, final String keyspace, final long maxTime, final String key) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkArgument(maxTime >= 0, "Precondition violation - argument 'maxTime' must not be negative!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); if(log.isTraceEnabled()){ log.trace("[HST] Retrieving history of key '" + key + "' in keyspace '" + keyspace + "' at timestamp " + maxTime); } String tkMin = UnqualifiedTemporalKey.createMin(key).toSerializableFormat(); String tkMax = UnqualifiedTemporalKey.create(key, maxTime).toSerializableFormat(); NavigableMap<String, byte[]> subMap = map.subMap(tkMin, true, tkMax, true); List<Long> timestamps = subMap.descendingKeySet().stream() .map(stringKey -> UnqualifiedTemporalKey.parseSerializableFormat(stringKey).getTimestamp()) .collect(Collectors.toList()); return timestamps.iterator(); } public static Iterator<Long> history(final NavigableMap<String,byte[]> map, final String keyspace, final String key, final long lowerBound, final long upperBound, final Order order) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); checkArgument(lowerBound >= 0, "Precondition violation - argument 'lowerBound' must not be negative!"); checkArgument(upperBound >= 0, "Precondition violation - argument 'upperBound' must not be negative!"); checkArgument(lowerBound <= upperBound, "Precondition violation - argument 'lowerBound' must be less than or equal to argument 'upperBound'!"); checkNotNull(order, "Precondition violation - argument 'order' must not be NULL!"); if(log.isTraceEnabled()){ log.trace("[HST] Retrieving history of key '" + key + "' in keyspace '" + keyspace + "' at range " + lowerBound + ":" + upperBound); } String tkMin = UnqualifiedTemporalKey.create(key, lowerBound).toSerializableFormat(); String tkMax = UnqualifiedTemporalKey.create(key, upperBound).toSerializableFormat(); NavigableMap<String, byte[]> subMap = map.subMap(tkMin, true, tkMax, true); switch(order){ case ASCENDING: return subMap.keySet().stream() .map(stringKey -> UnqualifiedTemporalKey.parseSerializableFormat(stringKey).getTimestamp()) // note: DO NOT replace this with Stream#iterator()! The surrounding transaction will close, and unless // we loaded the stream into an in-memory list first, the iterator will be broken! .collect(Collectors.toList()).iterator(); case DESCENDING: return subMap.descendingKeySet().stream() .map(stringKey -> UnqualifiedTemporalKey.parseSerializableFormat(stringKey).getTimestamp()) // note: DO NOT replace this with Stream#iterator()! The surrounding transaction will close, and unless // we loaded the stream into an in-memory list first, the iterator will be broken! .collect(Collectors.toList()).iterator(); default: throw new UnknownEnumLiteralException(order); } } public static void insertEntries(final NavigableMap<String, byte[]> map, final NavigableMap<String, Boolean> inverseMap, final String keyspace, final Set<UnqualifiedTemporalEntry> entries) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(entries, "Precondition violation - argument 'entries' must not be NULL!"); if(log.isTraceEnabled()){ log.trace("[INS] Inserting " + entries.size() + " entries into keyspace '" + keyspace + "'."); } for (UnqualifiedTemporalEntry entry : entries) { UnqualifiedTemporalKey tKey = entry.getKey(); byte[] value = entry.getValue(); map.put(tKey.toSerializableFormat(), value); InverseUnqualifiedTemporalKey itk = InverseUnqualifiedTemporalKey.create(tKey.getTimestamp(), tKey.getKey()); inverseMap.put(itk.toSerializableFormat(), value != null); } } public static long lastCommitTimestamp(final NavigableMap<String, byte[]> map, final String keyspace, final String key, long upperBound) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); checkArgument(upperBound >= 0, "Precondition violation - argument 'upperBound' must not be negative!"); if(log.isTraceEnabled()){ log.trace("[LCT] Retrieving last commit timestamp in keyspace '" + keyspace + "' on key '" + key + "'"); } String kMax = UnqualifiedTemporalKey.create(key, upperBound).toSerializableFormat(); String lastKey = map.floorKey(kMax); if (lastKey == null) { return -1; } UnqualifiedTemporalKey lastKeyParsed = UnqualifiedTemporalKey.parseSerializableFormat(lastKey); if (lastKeyParsed.getKey().equals(key) == false) { return -1; } return lastKeyParsed.getTimestamp(); } public static void rollback(final NavigableMap<String, byte[]> map, final NavigableMap<String, Boolean> inverseMap, final long timestamp) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(inverseMap, "Precondition violation - argument 'inverseMap' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); Iterator<Entry<String, byte[]>> iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, byte[]> entry = iterator.next(); UnqualifiedTemporalKey key = UnqualifiedTemporalKey.parseSerializableFormat(entry.getKey()); if (key.getTimestamp() > timestamp) { iterator.remove(); } } Iterator<Entry<String, Boolean>> iterator2 = inverseMap.entrySet().iterator(); while (iterator2.hasNext()) { Entry<String, Boolean> entry = iterator2.next(); InverseUnqualifiedTemporalKey key = InverseUnqualifiedTemporalKey.parseSerializableFormat(entry.getKey()); if (key.getTimestamp() > timestamp) { iterator2.remove(); } } } public static Iterator<TemporalKey> getModificationsBetween(final NavigableMap<String, Boolean> inverseMap, final String keyspace, final long timestampLowerBound, final long timestampUpperBound) { checkArgument(timestampLowerBound >= 0, "Precondition violation - argument 'timestampLowerBound' must not be negative!"); checkArgument(timestampUpperBound >= 0, "Precondition violation - argument 'timestampUpperBound' must not be negative!"); checkArgument(timestampLowerBound <= timestampUpperBound, "Precondition violation - argument 'timestampLowerBound' must be less than or equal to 'timestampUpperBound'!"); InverseUnqualifiedTemporalKey itkLow = InverseUnqualifiedTemporalKey.createMinInclusive(timestampLowerBound); InverseUnqualifiedTemporalKey itkHigh = InverseUnqualifiedTemporalKey.createMaxExclusive(timestampUpperBound); List<String> descendingKeySet = null; String low = itkLow.toSerializableFormat(); String high = itkHigh.toSerializableFormat(); NavigableMap<String, Boolean> subMap = inverseMap.subMap(low, true, high, false); descendingKeySet = Lists.newArrayList(subMap.descendingKeySet()); List<TemporalKey> resultList = Lists.newArrayList(); for (String string : descendingKeySet) { InverseUnqualifiedTemporalKey itk = InverseUnqualifiedTemporalKey.parseSerializableFormat(string); resultList.add(TemporalKey.create(itk.getTimestamp(), keyspace, itk.getKey())); } return resultList.iterator(); } }
17,019
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
NavigableMapUtils.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/NavigableMapUtils.java
package org.chronos.chronodb.internal.util; import static com.google.common.base.Preconditions.*; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.NavigableMap; import java.util.function.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Maps; public class NavigableMapUtils { public static <K extends Comparable<K>, V> List<Entry<K, V>> entriesAround(final NavigableMap<K, V> map, final K key, final int count) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); checkArgument(count >= 0, "Precondition violation - argument 'count' must not be negative!"); NavigableMap<K, V> smallerMap = map.headMap(key, false).descendingMap(); NavigableMap<K, V> largerMap = map.tailMap(key, true); List<Entry<K, V>> resultList = Lists.newArrayList(); int sizeLower = count / 2; int sizeLarger = count - sizeLower; if (smallerMap.size() < sizeLower) { if (largerMap.size() < sizeLarger) { // we don't have enough entries anyways; throw everything into the list resultList.addAll(smallerMap.entrySet()); resultList.addAll(largerMap.entrySet()); } else { // we don't have enough entries on the "smaller" side, but enough entries // on the other side. // take everything from the smaller side resultList.addAll(smallerMap.entrySet()); // take the remaining entries from the larger side (if we have enough) int limit = count - smallerMap.size(); int added = 0; for (Entry<K, V> binaryEntry : largerMap.entrySet()) { if (added >= limit) { break; } resultList.add(binaryEntry); added++; } } } else { if (largerMap.size() < sizeLarger) { // we don't have enough entries on the "larger" side, but enough entries on // the other side. // take everything from the larger side resultList.addAll(largerMap.entrySet()); // take the remaining entries from the smaller side (if we have enough) int limit = count - largerMap.size(); int added = 0; for (Entry<K, V> binaryEntry : smallerMap.entrySet()) { if (added >= limit) { break; } resultList.add(binaryEntry); added++; } } else { // enough entries on both sides int added = 0; for (Entry<K, V> binaryEntry : smallerMap.entrySet()) { if (added >= sizeLower) { break; } resultList.add(binaryEntry); added++; } added = 0; for (Entry<K, V> binaryEntry : largerMap.entrySet()) { if (added >= sizeLarger) { break; } resultList.add(binaryEntry); added++; } } } return resultList; } }
2,753
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IteratorUtils.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/IteratorUtils.java
package org.chronos.chronodb.internal.util; import com.google.common.collect.Sets; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; import java.util.Spliterator; import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; import static com.google.common.base.Preconditions.*; public class IteratorUtils { private IteratorUtils() { throw new UnsupportedOperationException("Do not instantiate this class!"); } // ================================================================================================================= // PUBLIC API // ================================================================================================================= public static <T> Iterator<T> skipLast(final Iterator<T> iterator) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); return new SkipLastIterator<>(iterator); } public static <T> Iterator<T> unique(final Iterator<T> iterator) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); return new UniqueIterator<>(iterator); } public static <T> Stream<T> stream(final Iterator<T> iterator) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); Spliterator<T> spliterator = Spliterators.spliteratorUnknownSize(iterator, Spliterator.IMMUTABLE | Spliterator.ORDERED); return StreamSupport.stream(spliterator, false); } // ================================================================================================================= // INNER CLASSES // ================================================================================================================= private static class SkipLastIterator<T> implements Iterator<T> { private Iterator<T> innerIterator; private T nextElement; public SkipLastIterator(final Iterator<T> iterator) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); this.innerIterator = iterator; this.tryFetchNext(); } private void tryFetchNext() { this.nextElement = null; if (this.innerIterator.hasNext()) { T element = this.innerIterator.next(); this.nextElement = element; if (this.innerIterator.hasNext() == false) { // we found the last element, mark iterator as exhausted this.nextElement = null; } } } @Override public boolean hasNext() { return this.nextElement != null; } @Override public T next() { if (!this.hasNext()) { throw new NoSuchElementException("Iterator has no more elements!"); } T element = this.nextElement; this.tryFetchNext(); return element; } } private static class UniqueIterator<T> implements Iterator<T> { private Iterator<T> innerIterator; private Set<T> visited; private T nextElement; public UniqueIterator(final Iterator<T> iterator) { checkNotNull(iterator, "Precondition violation - argument 'iterator' must not be NULL!"); this.innerIterator = iterator; this.visited = Sets.newHashSet(); this.tryFetchNext(); } private void tryFetchNext() { this.nextElement = null; while (this.innerIterator.hasNext()) { T element = this.innerIterator.next(); if (this.visited.contains(element)) { // we have already seen this element; continue with the next one continue; } // this is a new (unseen) element. Register it this.visited.add(element); this.nextElement = element; break; } } @Override public boolean hasNext() { return this.nextElement != null; } @Override public T next() { if (!this.hasNext()) { throw new NoSuchElementException("Iterator has no more elements!"); } T current = this.nextElement; this.tryFetchNext(); return current; } } }
4,558
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
MultiMapUtil.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/MultiMapUtil.java
package org.chronos.chronodb.internal.util; import static com.google.common.base.Preconditions.*; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import com.google.common.collect.HashMultimap; import com.google.common.collect.Maps; import com.google.common.collect.SetMultimap; import com.google.common.collect.Sets; public class MultiMapUtil { public static <K, V> void put(final Map<K, Set<V>> multimap, final K key, final V value) { checkNotNull(multimap, "Precondition violation - argument 'multimap' must not be NULL!"); Set<V> set = multimap.get(key); if (set == null) { set = Sets.newHashSet(); multimap.put(key, set); } set.add(value); } public static <K, V> Map<K, Set<V>> copyToMap(final SetMultimap<K, V> multimap) { checkNotNull(multimap, "Precondition violation - argument 'multimap' must not be NULL!"); Map<K, Set<V>> resultMap = Maps.newHashMap(); for (Entry<K, V> entry : multimap.entries()) { K key = entry.getKey(); V value = entry.getValue(); Set<V> set = resultMap.get(key); if (set == null) { set = Sets.newHashSet(); resultMap.put(key, set); } set.add(value); } return resultMap; } public static <K, V> Map<K, Set<V>> copy(final Map<K, Set<V>> multimap) { checkNotNull(multimap, "Precondition violation - argument 'multimap' must not be NULL!"); Map<K, Set<V>> resultMap = Maps.newHashMap(); for (Entry<K, Set<V>> entry : multimap.entrySet()) { K key = entry.getKey(); Set<V> values = entry.getValue(); Set<V> newValues = Sets.newHashSet(values); resultMap.put(key, newValues); } return resultMap; } public static <K, V> SetMultimap<K, V> copyToMultimap(final Map<K, Set<V>> map) { checkNotNull(map, "Precondition violation - argument 'map' must not be NULL!"); SetMultimap<K, V> resultMap = HashMultimap.create(); for (Entry<K, Set<V>> entry : map.entrySet()) { K key = entry.getKey(); Set<V> values = entry.getValue(); for (V value : values) { resultMap.put(key, value); } } return resultMap; } }
2,062
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ResolvedFuture.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/internal/util/concurrent/ResolvedFuture.java
package org.chronos.chronodb.internal.util.concurrent; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class ResolvedFuture<T> implements Future<T> { private T result; public ResolvedFuture(final T result) { this.result = result; } @Override public boolean cancel(final boolean mayInterruptIfRunning) { return false; } @Override public boolean isCancelled() { return false; } @Override public boolean isDone() { return true; } @Override public T get() throws InterruptedException, ExecutionException { return this.result; } @Override public T get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return this.result; } }
847
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
MaintenanceManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/MaintenanceManager.java
package org.chronos.chronodb.api; import java.util.function.Predicate; /** * The {@link MaintenanceManager} offers maintenance operations on the database. * * <p> * In general, {@link ChronoDB} is intended as a low-maintenance database, therefore the number of operations in this class is limited. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface MaintenanceManager { /** * Performs a rollover on the branch with the given name. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} ()} first to check if this operation is supported or not. * * @param branchName * The branch name to roll over. Must not be <code>null</code>, must refer to an existing branch. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public default void performRolloverOnBranch(String branchName){ performRolloverOnBranch(branchName, true); } /** * Performs a rollover on the branch with the given name. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} ()} first to check if this operation is supported or not. * * @param branchName * The branch name to roll over. Must not be <code>null</code>, must refer to an existing branch. * @param updateIndices * Use <code>true</code> to update all clean indices to match the data content at the new head revision. Using <code>false</code> will instead mark all indices as dirty. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public void performRolloverOnBranch(String branchName, boolean updateIndices); /** * Performs a rollover on the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} first to check if this operation is supported or not. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public default void performRolloverOnMaster() { this.performRolloverOnBranch(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER); } /** * Performs a rollover on the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} first to check if this operation is supported or not. * * @param updateIndices * Use <code>true</code> to update all clean indices to match the data content at the new head revision. Using <code>false</code> will instead mark all indices as dirty. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public default void performRolloverOnMaster(boolean updateIndices) { this.performRolloverOnBranch(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER, updateIndices); } /** * Performs a rollover on all existing branches. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} first to check if this operation is supported or not. * * <p> * <b>Important note:</b> This method is <b>not guaranteed to be ACID safe</b>. Rollovers will be executed one after the other. If an unexpected event (such as JVM crash, exceptions, power supply failure...) occurs, then some branches may have been rolled over while others have not. * * <p> * This is a <b>very</b> expensive operation that can substantially increase the memory footprint of the database on disk. Use with care. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public default void performRolloverOnAllBranches() { this.performRolloverOnAllBranches(true); } /** * Performs a rollover on all existing branches. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} first to check if this operation is supported or not. * * <p> * <b>Important note:</b> This method is <b>not guaranteed to be ACID safe</b>. Rollovers will be executed one after the other. If an unexpected event (such as JVM crash, exceptions, power supply failure...) occurs, then some branches may have been rolled over while others have not. * * <p> * This is a <b>very</b> expensive operation that can substantially increase the memory footprint of the database on disk. Use with care. * * @param updateIndices * Use <code>true</code> to update all clean indices to match the data content at the new head revision. Using <code>false</code> will instead mark all indices as dirty. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public void performRolloverOnAllBranches(boolean updateIndices); /** * Performs a rollover on all branches that match the given predicate. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} first to check if this operation is supported or not. * * <p> * <b>Important note:</b> This method is <b>not guaranteed to be ACID safe</b>. Rollovers will be executed one after the other. If an unexpected event (such as JVM crash, exceptions, power supply failure...) occurs, then some branches may have been rolled over while others have not. * * <p> * This is a potentially <b>very</b> expensive operation that can substantially increase the memory footprint of the database on disk. Use with care. * * @param branchPredicate * The predicate that decides whether or not to roll over the branch in question. Must not be <code>null</code>. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public default void performRolloverOnAllBranchesWhere(Predicate<String> branchPredicate){ this.performRolloverOnAllBranchesWhere(branchPredicate, true); } /** * Performs a rollover on all branches that match the given predicate. * * <p> * Not all backends support this operation. Please use {@link ChronoDBFeatures#isRolloverSupported()} first to check if this operation is supported or not. * * <p> * <b>Important note:</b> This method is <b>not guaranteed to be ACID safe</b>. Rollovers will be executed one after the other. If an unexpected event (such as JVM crash, exceptions, power supply failure...) occurs, then some branches may have been rolled over while others have not. * * <p> * This is a potentially <b>very</b> expensive operation that can substantially increase the memory footprint of the database on disk. Use with care. * * @param branchPredicate * The predicate that decides whether or not to roll over the branch in question. Must not be <code>null</code>. * @param updateIndices * Use <code>true</code> to update all clean indices to match the data content at the new head revision. Using <code>false</code> will instead mark all indices as dirty. * * @throws UnsupportedOperationException * Thrown if this backend {@link ChronoDBFeatures#isRolloverSupported() does not support rollovers}. */ public void performRolloverOnAllBranchesWhere(Predicate<String> branchPredicate, boolean updateIndices); }
7,862
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChangeSetEntry.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChangeSetEntry.java
package org.chronos.chronodb.api; import static com.google.common.base.Preconditions.*; import java.util.Set; import org.chronos.chronodb.api.key.QualifiedKey; import org.chronos.chronodb.internal.impl.ChangeSetEntryImpl; /** * Represents a single entry in the set of changes made by a {@link ChronoDBTransaction} before committing. * * <p> * Instances of this interface are always held in-memory. Upon commit, they are forwarded to the data store to persist the changes. * * <p> * Instances of this interface are simple data structures with no logic, and are assumed to be immutable. * * <p> * Instances of this interface <b>must</b> implement {@link #hashCode()} and {@link #equals(Object)} based only on the QualifiedKey. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface ChangeSetEntry { /** * Creates a regular change instance, i.e. any change that is not a deletion. * * <p> * For deletions, please use {@link #createDeletion(QualifiedKey)} instead. * * @param key * The key that was modified (inserted or altered). Must not be <code>null</code>. * @param newValue * The new value that is assigned to the given key. Must not be <code>null</code>. * @param options * The options to store alongside the change. May be empty, must not be <code>null</code>. * @return The newly created change set entry. Never <code>null</code>. */ public static ChangeSetEntry createChange(final QualifiedKey key, final Object newValue, final PutOption... options) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); checkNotNull(newValue, "Precondition violation - argument 'newValue' must not be NULL!"); checkNotNull(options, "Precondition violation - argument 'options' must not be NULL!"); return ChangeSetEntryImpl.createChange(key, newValue, options); } /** * Creates a new deletion instance. * * <p> * For insertions or modifications, please use {@link #createChange(QualifiedKey, Object, PutOption...)} instead. * * @param key * The key to be marked as deleted. Must not be <code>null</code>. * @return The newly created change set entry. Never <code>null</code>. */ public static ChangeSetEntry createDeletion(final QualifiedKey key) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return ChangeSetEntryImpl.createDeletion(key); } /** * Returns the key that was changed. * * @return The qualified key. Never <code>null</code>. */ public String getKey(); /** * Returns the name of the keyspace where the change occurred. * * @return The name of the keyspace. Never <code>null</code>. */ public String getKeyspace(); /** * Returns the new value associated with the key. * * <p> * If this method returns <code>null</code>, it indicates the deletion of the key. * * @return The value, or <code>null</code> if the key was deleted. */ public Object getValue(); /** * Returns the (put-)options for this change. * * @return The immutable set of options. Never <code>null</code>. May be empty. */ public Set<PutOption> getOptions(); /** * Checks if this change entry corresponds to a "set" operation that changed the value of a key. * * <p> * The term "set" is interpreted here as in "set key X to value Y", where X and Y are non-<code>null</code>. It is mutually exclusive with {@link #isRemove()}. * * @return <code>true</code> if this is a "set" operation, otherwise <code>false</code>. */ public boolean isSet(); /** * Checks if this change entry corresponds to a "remove" operation that removed a key altogether. * * <p> * The term "remove" is interpreted here as in "remove key X", where X is non-<code>null</code>. It is mutually exclusive with {@link #isSet()}. * * @return <code>true</code> if this is a "remove" operation, otherwise <code>false</code>. */ public boolean isRemove(); }
4,000
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
StatisticsManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/StatisticsManager.java
package org.chronos.chronodb.api; /** * The {@link StatisticsManager} is the entry point to all statistic-related capabilities in the public API. * * <p> * The primary purpose of this class is to produce statistic report objects. * * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface StatisticsManager { /** * Calculates and returns the global statistics for this {@link ChronoDB} instance. * * <p> * Please note that running this method can potentially take a while. The returned object is immutable. Every invocation of this method will produce a new, independent statistics object. * * @return The global statistics. Never <code>null</code>. */ public ChronoDBStatistics getGlobalStatistics(); /** * Returns the statistics for the "head portion" of the {@linkplain ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. * * <p> * The definition of what the "head portion" is, is up to the backend at hand. In general, it refers to the more recent history. * * @return The statistics. Never <code>null</code>. */ public default BranchHeadStatistics getMasterBranchHeadStatistics(){ return this.getBranchHeadStatistics(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER); } /** * Returns the statistics for the "head portion" of the given branch. * * <p> * The definition of what the "head portion" is, is up to the backend at hand. In general, it refers to the more recent history. * * @param branchName * The name of the branch to retrieve the statistics for. Must not be <code>null</code>, must refer to an existing branch. * * @return The statistics. Never <code>null</code>. */ public BranchHeadStatistics getBranchHeadStatistics(String branchName); }
1,774
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
Dateback.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/Dateback.java
package org.chronos.chronodb.api; import com.google.common.annotations.VisibleForTesting; import org.chronos.chronodb.api.exceptions.DatebackException; import org.chronos.chronodb.api.key.QualifiedKey; import java.util.Map; import java.util.Set; import java.util.function.BiFunction; import java.util.function.BiPredicate; import java.util.function.Function; public interface Dateback { /** * Marker object. Used by several transformation methods to indicate that the transformation does not change the * value at hand. */ public static final Object UNCHANGED = new Object(); /** * Purges the entry at the given coordinates from the store, eliminating it completely from the history. * * @param keyspace The keyspace of the entry to purge. Must not be <code>null</code>. * @param key The key of the entry to purge. Must not be <code>null</code>. * @param timestamp The (exact) timestamp of the entry to purge. Must not be negative. * @return <code>true</code> if the entry was purged successfully from the store, or <code>false</code> if there was * no entry to purge at the given coordinates. */ public boolean purgeEntry(String keyspace, String key, long timestamp); /** * Purges the given key from the store, eliminating it completely from the history. * * <p> * In contrast to {@link #purgeEntry(String, String, long)}, this method will remove ALL occurrences of the key. In * other words, after calling this method, the history of the key will be empty. * * @param keyspace The keyspace in which the key resides. Must not be <code>null</code>. * @param key The key to (unconditionally) purge from the store. Must not be <code>null</code>. */ public void purgeKey(String keyspace, String key); /** * Purges all entries with the given key from the store which match the given predicate, eliminating them completely * from the history. * * <p> * In contrast to {@link #purgeEntry(String, String, long)}, this method can potentially remove multiple occurrences * of the key. * * @param keyspace The keyspace where the key resides. Must not be <code>null</code>. * @param key The key to purge from the store. Must not be <code>null</code>. * @param predicate The predicate to use for deciding whether to purge an entry or not. Must not be <code>null</code>. * Must be a pure, side-effect free function. The first parameter is the timestamp of the entry at hand, * the second parameter is the value associated with the key at this timestamp (which may be * <code>null</code> to indicate that this entry is a deletion). The function should return * <code>true</code> if the entry should be purged, or <code>false</code> if the entry should remain * untouched. */ public void purgeKey(String keyspace, String key, BiPredicate<Long, Object> predicate); /** * Purges all entries with the given key from the store that reside in the given time range, eliminating them * completely from the history. * * @param keyspace The keyspace where the key resides. Must not be <code>null</code>. * @param key The key to purge from the store. Must not be <code>null</code>. * @param purgeRangeStart The lower bound of the range to purge entries from (inclusive). Must not be negative, must not be * larger than <code>purgeRangeEnd</code>. * @param purgeRangeEnd The upper bound of the range to purge entries from (inclusive). Must not be negative, must be greater * than or equal to <code>purgeRangeStart</code>. */ public void purgeKey(String keyspace, String key, long purgeRangeStart, long purgeRangeEnd); /** * Purges all entries in the given keyspace that reside in the given time range, eliminating them completely from the history. * * @param keyspace The keyspace to purge the entries from. Must not be <code>null</code>. * @param purgeRangeStart The lower bound of the range to purge entries from (inclusive). Must not be negative, must not be * larger than <code>purgeRangeEnd</code>. * @param purgeRangeEnd The upper bound of the range to purge entries from (inclusive). Must not be negative, must be greater * than or equal to <code>purgeRangeStart</code>. */ public void purgeKeyspace(String keyspace, long purgeRangeStart, long purgeRangeEnd); /** * Purges the given commit from the store, eliminating it (and its associated changes) completely from the history. * * <p> * This will also delete the commit metadata associated with the commit. * * @param commitTimestamp The (exact) timestamp of the commit to purge. Must not be negative. */ public void purgeCommit(long commitTimestamp); /** * Purges all commits in the given time range (and their associated changes and metadata), eliminating them * completely from the store. * * @param purgeRangeStart The lower bound of the timestamp range to perform the purging in (inclusive). Must not be negative, * must not be larger than <code>purgeRangeEnd</code>. * @param purgeRangeEnd The upper bound of the timestamp range to perform the purging in (inclusive). Must not be negative, * must not be smaller than <code>purgeRangeStart</code>. */ public void purgeCommits(long purgeRangeStart, long purgeRangeEnd); /** * Injects an entry with the given properties into the store. * * <p> * Please keep in mind the following properties of this operation: * <ul> * <li>If an entry existed at the specified coordinates, this entry will be <b>overwritten</b>. * <li>Using <code>null</code> as the <code>value</code> parameter inserts a "deletion" entry. * <li>This method can potentially introduce a new commit in the commit log. * <li>This method can <b>not</b> be used to inject entries in the future. * <li>This method can <b>not</b> be used to inject entries historically before the branching timestamp of the * current branch. * <li>This method <b>can</b> be used to create new keyspaces by specifying a previously unused keyspace name. * <li>This method <b>can</b> be used to inject entries after the current "now" timestamp, but not after * {@link System#currentTimeMillis()}. Injecting entries after "now" will advance the "now" timestamp. * </ul> * * @param keyspace The keyspace in which the new entry should be created. Must not be <code>null</code>. If the keyspace * did not exist before, it will be created. * @param key The key at which the new entry should be created. Must not be <code>null</code>. * @param timestamp The timestamp at which the new entry should be inserted. Any existing entry at this timestamp will be * overwritten. Must not be negative. Must be larger than the branching timestamp of this branch. Must * not be in the future. * @param value The value to insert. May be <code>null</code> to indicate that the key was deleted from the store at * these coordinates. */ public void inject(String keyspace, String key, long timestamp, Object value); /** * Injects an entry with the given properties into the store. * * <p> * Please keep in mind the following properties of this operation: * <ul> * <li>If an entry existed at the specified coordinates, this entry will be <b>overwritten</b>. * <li>Using <code>null</code> as the <code>value</code> parameter inserts a "deletion" entry. * <li>This method can potentially introduce a new commit in the commit log. * <li>This method can <b>not</b> be used to inject entries in the future. * <li>This method can <b>not</b> be used to inject entries historically before the branching timestamp of the * current branch. * <li>This method <b>can</b> be used to create new keyspaces by specifying a previously unused keyspace name. * <li>This method <b>can</b> be used to inject entries after the current "now" timestamp, but not after * {@link System#currentTimeMillis()}. Injecting entries after "now" will advance the "now" timestamp. * </ul> * * @param keyspace The keyspace in which the new entry should be created. Must not be <code>null</code>. If the keyspace * did not exist before, it will be created. * @param key The key at which the new entry should be created. Must not be <code>null</code>. * @param timestamp The timestamp at which the new entry should be inserted. Any existing entry at this timestamp will be * overwritten. Must not be negative. Must be larger than the branching timestamp of this branch. Must * not be in the future. * @param value The value to insert. May be <code>null</code> to indicate that the key was deleted from the store at * these coordinates. * @param commitMetadata The commit metadata to use for the entry. Will override pre-existing commit metadata, in case that * there was a commit at the given timestamp. May be <code>null</code>. */ public void inject(String keyspace, String key, long timestamp, Object value, Object commitMetadata); /** * Injects an entry with the given properties into the store. * * <p> * Please keep in mind the following properties of this operation: * <ul> * <li>If an entry existed at the specified coordinates, this entry will be <b>overwritten</b>. * <li>Using <code>null</code> as the <code>value</code> parameter inserts a "deletion" entry. * <li>This method can potentially introduce a new commit in the commit log. * <li>This method can <b>not</b> be used to inject entries in the future. * <li>This method can <b>not</b> be used to inject entries historically before the branching timestamp of the * current branch. * <li>This method <b>can</b> be used to create new keyspaces by specifying a previously unused keyspace name. * <li>This method <b>can</b> be used to inject entries after the current "now" timestamp, but not after * {@link System#currentTimeMillis()}. Injecting entries after "now" will advance the "now" timestamp. * </ul> * * @param keyspace The keyspace in which the new entry should be created. Must not be <code>null</code>. If the keyspace * did not exist before, it will be created. * @param key The key at which the new entry should be created. Must not be <code>null</code>. * @param timestamp The timestamp at which the new entry should be inserted. Any existing entry at this timestamp will be * overwritten. Must not be negative. Must be larger than the branching timestamp of this branch. Must * not be in the future. * @param value The value to insert. May be <code>null</code> to indicate that the key was deleted from the store at * these coordinates. * @param commitMetadata The commit metadata to use for the entry. May be <code>null</code>. * @param overrideCommitMetadata Decides whether or not to override pre-existing commit metadata (if there is a commit at the given * timestamp). Use <code>true</code> to override existing metadata, or <code>false</code> to keep it * intact if it exists. If no commit metadata exists at the given timestamp, this parameter will be * ignored. */ public void inject(String keyspace, String key, long timestamp, Object value, Object commitMetadata, boolean overrideCommitMetadata); /** * Injects multiple entries at the given timestamp into the store. * * <p> * This is a multiplicity-many version of {@link #inject(String, String, long, Object)}; the same restrictions * regarding the entries apply here. * * @param timestamp The timestamp at which to inject the entries. Must not be negative. Must be greater than the branching * timestamp of the current branch. Must not be in the future. * @param entries The entries to insert at the given timestamp. The map entries contain the keyspace/key combination in * the first component and the corresponding value in the second component. <code>null</code> is a legal * entry value and can be used to indicate a deletion in the store. The map itself must not be * <code>null</code>. */ public void inject(long timestamp, Map<QualifiedKey, Object> entries); /** * Injects multiple entries at the given timestamp into the store. * * <p> * This is a multiplicity-many version of {@link #inject(String, String, long, Object)}; the same restrictions * regarding the entries apply here. * * @param timestamp The timestamp at which to inject the entries. Must not be negative. Must be greater than the branching * timestamp of the current branch. Must not be in the future. * @param entries The entries to insert at the given timestamp. The map entries contain the keyspace/key combination in * the first component and the corresponding value in the second component. <code>null</code> is a legal * entry value and can be used to indicate a deletion in the store. The map itself must not be * <code>null</code>. * @param commitMetadata The commit metadata to store for this timestamp. This will override pre-existing metadata, if there * has been a previous commit on this timestamp. */ public void inject(long timestamp, Map<QualifiedKey, Object> entries, Object commitMetadata); /** * Injects multiple entries at the given timestamp into the store. * * <p> * This is a multiplicity-many version of {@link #inject(String, String, long, Object)}; the same restrictions * regarding the entries apply here. * * @param timestamp The timestamp at which to inject the entries. Must not be negative. Must be greater than the branching * timestamp of the current branch. Must not be in the future. * @param entries The entries to insert at the given timestamp. The map entries contain the keyspace/key combination in * the first component and the corresponding value in the second component. <code>null</code> is a legal * entry value and can be used to indicate a deletion in the store. The map itself must not be * <code>null</code>. * @param commitMetadata The commit metadata to store for this timestamp. This will override pre-existing metadata, if there * has been a previous commit on this timestamp. * @param overrideCommitMetadata Decides whether or not to override pre-existing commit metadata (if there is a commit at the given * timestamp). Use <code>true</code> to override existing metadata, or <code>false</code> to keep it * intact if it exists. If no commit metadata exists at the given timestamp, this parameter will be * ignored. */ public void inject(long timestamp, Map<QualifiedKey, Object> entries, Object commitMetadata, boolean overrideCommitMetadata); /** * Transforms the entry at the given coordinates by applying the given transformation function. * * <p> * Please note that the transformation function may return the {@link Dateback#UNCHANGED} constant to indicate that * the transformation does not change the value. * * @param keyspace The keyspace of the entry to transform. Must not be <code>null</code>. * @param key The key of the entry to transform. Must not be <code>null</code>. * @param timestamp The timestamp of the entry to transform. Must match the entry <b>exactly</b>. Must not be negative. * @param transformation The transformation to apply. Must not be <code>null</code>. May return {@link Dateback#UNCHANGED} to * indicate that the value should remain unchanged. The passed value may be <code>null</code> to indicate * that the entry marks a deletion. The function has to be a pure function, i.e. free of side effects and * depending only on the passed parameters. */ public void transformEntry(String keyspace, String key, long timestamp, Function<Object, Object> transformation); /** * Transforms all values of the given key by applying the given transformation function. * * <p> * Please note that the transformation function may return the {@link Dateback#UNCHANGED} constant to indicate that * the transformation does not change the value. * * @param keyspace The keyspace of the entries to transform. Must not be <code>null</code>. * @param key The key of the entries to transform. Must not be <code>null</code>. * @param transformation The transformation function to apply. It receives the timestamp and the value of the entry as * parameters and should return the new value to assign to the given timestamp. The function may return * <code>null</code> in order to indicate a deletion. The passed value may be <code>null</code> to * indicate that the entry marks a deletion. The function should return {@link Dateback#UNCHANGED} to * indicate that the current entry remains unchanged. The function has to be a pure function, i.e. free * of side effects and depending only on the passed parameters. */ public void transformValuesOfKey(String keyspace, String key, BiFunction<Long, Object, Object> transformation); /** * Transforms all entries that belong to a given commit. * * <p> * The transformation function <b>may</b>: * <ul> * <li>Add new entries to the map. Those will be injected into the commit. * <li>Remove entries from the map. Those will be removed from the commit. * <li>Change the values associated with keys. Those will be updated. * <li>Assign the {@link Dateback#UNCHANGED} value to a key. This will leave the entry untouched in the commit. * </ul> * * The map passed to the transformation function as parameter is <b>immutable</b>. The transformation function * should construct a new map internally and return it. * * @param commitTimestamp The (precise) timestamp of the commit to transform. Must not be negative. If there is no commit at the * specified timestamp, this method is a no-op and will return immediately. * @param transformation The transformation function to apply. Must not be <code>null</code>. Must be a pure, side-effect free * function. */ public void transformCommit(long commitTimestamp, Function<Map<QualifiedKey, Object>, Map<QualifiedKey, Object>> transformation); /** * Transforms the values of the given keyspace. * * <p> * This method <b>is allowed</b> to: * <ul> * <li>Update existing values</li> * <li>Leave existing values the same</li> * </ul> * </p> * * <p> * This method is <b>not allowed</b> to: * <ul> * <li>Replace a value with a deletion marker</li> * <li>Delete existing entries</li> * <li>Introduce new entries at coordinates which previously had no entry</li> * </ul> * * </p> * * @param keyspace The keyspace to transform. Must not be <code>null</code>. * @param valueTransformation The value transformation to apply. Must not be <code>null</code>. */ public void transformValuesOfKeyspace(String keyspace, KeyspaceValueTransformation valueTransformation); /** * Updates the metadata of the given commit, replacing it with the given one. * * @param commitTimestamp The timestamp of the commit to update the metadata for. Must not be <code>null</code>, must refer to * an existing commit in the store. * @param newMetadata The new metadata object to assign to the commit. May be <code>null</code>. * @throws DatebackException Thrown if there is no commit in the store at the given timestamp. */ public void updateCommitMetadata(long commitTimestamp, Object newMetadata); /** * Performs cleanup operations on the underlying store (if necessary). * * <p> * Users can call this operation in order to flush changes into the store and freeing RAM. * * <p> * Cleanup will also be performed automatically at the end of a dateback process. */ public void cleanup(); /** * Returns the highest timestampthat is not yet affected by changes performed by the dateback process. * * @return The highest unaffected timestamp. May be -1 if all timestamps have been affected. */ public long getHighestUntouchedTimestamp(); /** * Returns the value at the given coordinates (just like {@link ChronoDBTransaction#get(String, String)}). * * @param timestamp The timestamp at which to perform the lookup. Must be positive, must be less than or equal to {@link #getHighestUntouchedTimestamp()}. * @param keyspace The keyspace to search in. Must not be <code>null</code>. * @param key The key to search for. Must not be <code>null</code>. * @return The object located at the given coordinates, or <code>null</code> if no object was found. */ public Object get(long timestamp, String keyspace, String key); /** * Returns the keyset at the given timestamp. * * @param timestamp The timestamp at which to calculate the keyset. Must be positive, must be less than or equal to {@link #getHighestUntouchedTimestamp()}. * @param keyspace The keyspace to calculate the keyset for. Must not be <code>null</code>. * @return The keyset. May be empty, but never <code>null</code>. */ public Set<String> keySet(long timestamp, String keyspace); /** * Returns the keyspaces which existed at the given timestamp. * * <p> * Works similarly to {@link ChronoDBTransaction#keyspaces()}. * </p> * * @param timestamp The timestamp at which to calculate the set of keyspaces. Must be positive, must be less than or equal to {@link #getHighestUntouchedTimestamp()}. * @return The set of keyspaces at the given timestamp. May be empty, but never <code>null</code>. */ public Set<String> keyspaces(long timestamp); /** * For testing purposes only. Checks if this dateback instance is still accessible or already closed. * * @return <code>true</code> if this dateback instance has already been closed, or <code>false</code> if it is still * open. */ @VisibleForTesting public boolean isClosed(); public interface KeyspaceValueTransformation { /** * Transforms the value at the given coordinates. * * @param key The key which holds the value. Never <code>null</code>. * @param timestamp The timestamp at which the operation occurs. * @param oldValue The old value. Never <code>null</code>. * @return The new value. Use {@link #UNCHANGED} if you want to keep the old value. Never <code>null</code>. */ public Object transformValue(String key, long timestamp, Object oldValue); } }
24,777
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
SerializationManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/SerializationManager.java
package org.chronos.chronodb.api; /** * The {@link SerializationManager} is responsible for conversion between {@link Object} and <code>byte[]</code> * representation. * * <p> * Every {@link ChronoDB} instance has its own SerializationManager, which can be retrieved via * {@link ChronoDB#getSerializationManager()}. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface SerializationManager { /** * Serializes the given object into its <code>byte[]</code> representation. * * @param object * The object to serialize. Must not be <code>null</code>. * * @return The serial form of the passed object. */ public byte[] serialize(Object object); /** * Deserializes the given <code>byte[]</code> back into its {@link Object} representation. * * @param serialForm * The byte array to deserialize. Must not be <code>null</code>. * * @return The object representation of the passed byte array. */ public Object deserialize(byte[] serialForm); }
1,044
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DatebackManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/DatebackManager.java
package org.chronos.chronodb.api; import org.chronos.chronodb.internal.api.dateback.log.DatebackOperation; import java.util.List; import java.util.function.Consumer; public interface DatebackManager { /** * Executes a set of dateback operations on the {@linkplain ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} * branch. * * <p> * Dateback operations allow to modify the history of the database content. It is <b>strongly discouraged</b> to * execute any dateback operation while the database is online and accessible for regular transactions. * * <p> * <u><b>/!\ WARNING /!\</b></u><br> * Dateback operations should be a last resort and should be avoided at all costs during regular database operation. * They have the following properties: * <ul> * <li>They are <b>not</b> ACID safe. Back up your database before attempting any dateback operation. * <li>They require an <b>exclusive lock</b> on the entire database. * <li>They <b>invalidate</b> all currently ongoing transactions. Transactions which are continued after a dateback * operation are <b>not guaranteed</b> to be ACID anymore. * <li>They <b>cannot</b> be undone. * <li>They provide <b>direct access</b> to the temporal stores. There is <b>no safety net</b> to prevent erroneous * states. * <li>They will always (unconditionally) dirty all secondary indices. Call {@link IndexManager#reindexAll()} after performing your dateback operations.</li> * </ul> * * <b>DO NOT USE THE DATEBACK API UNLESS YOU KNOW <u>EXACTLY</u> WHAT YOU ARE DOING.</b><br> * * The name of the branch to operate on. Must refer to an existing branch. Must not be <code>null</code>. * * @param function The function that contains the dateback instructions. Must not be <code>null</code>. */ public default void datebackOnMaster(final Consumer<Dateback> function) { this.dateback(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER, function); } /** * Executes a set of dateback operations on the given branch. * * <p> * Dateback operations allow to modify the history of the database content. It is <b>strongly discouraged</b> to * execute any dateback operation while the database is online and accessible for regular transactions. * * <p> * <u><b>/!\ WARNING /!\</b></u><br> * Dateback operations should be a last resort and should be avoided at all costs during regular database operation. * They have the following properties: * <ul> * <li>They are <b>not</b> ACID safe. Back up your database before attempting any dateback operation. * <li>They require an <b>exclusive lock</b> on the entire database. * <li>They <b>invalidate</b> all currently ongoing transactions. Transactions which are continued after a dateback * operation are <b>not guaranteed</b> to be ACID anymore. * <li>They <b>cannot</b> be undone. * <li>They provide <b>direct access</b> to the temporal stores. There is <b>no safety net</b> to prevent erroneous * states. * <li>They will always (unconditionally) dirty all secondary indices. Call {@link IndexManager#reindexAll()} after performing your dateback operations.</li> * </ul> * * <b>DO NOT USE THE DATEBACK API UNLESS YOU KNOW <u>EXACTLY</u> WHAT YOU ARE DOING.</b><br> * * @param branch The name of the branch to operate on. Must refer to an existing branch. Must not be <code>null</code>. * @param function The function that contains the dateback instructions. Must not be <code>null</code>. */ public void dateback(String branch, Consumer<Dateback> function); /** * Checks if a dateback process is running on the current thread. * * @return <code>true</code> if a databack process is running, otherwise <code>false</code>. */ public boolean isDatebackRunning(); /** * Returns a list of all dateback operations which have been performed so far on this database instance. * * @return The list of all performed dateback operations. May be empty, but never <code>null</code>. */ public List<DatebackOperation> getAllPerformedDatebackOperations(); /** * Returns a list of all dateback operations which have been executed within the given time range. * * <p> * The given time range reflects the <b>wall clock time</b> of the operation execution, <i>not</i> the timestamp at which the operation is aimed! * </p> * * @param branch The branch on which the operation has occurred. Operations on origin branches will also be considered. * @param dateTimeMin The lower bound of the wall clock time range to search for (inclusive). Must not be negative. Must be less than <code>dateTimeMax</code>. * @param dateTimeMax The upper bound of the wall clock time range to search for (inclusive). Must not be negative. Must be greater than <code>dateTimeMin</code>. * @return The list of operations on the given <code>branch</code> within the given wall clock time range. May be empty but never <code>null</code>. */ public List<DatebackOperation> getDatebackOperationsPerformedBetween(String branch, long dateTimeMin, long dateTimeMax); /** * Returns a list of all dateback operations which affect the given <code>branch</code> and <code>timestamp</code>. * * @param branch The branch on which the operation has occurred. Operations on origin branches will also be considered. * @param timestamp The (commit) timestamp in question. All dateback operations aimed at this (or an earlier) timestamp will be returned. * @return The list of operations on the given <code>branch</code> which affect the given timestamp. May be empty but never <code>null</code>. */ public List<DatebackOperation> getDatebackOperationsAffectingTimestamp(String branch, long timestamp); }
5,975
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
CommitMetadataFilter.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/CommitMetadataFilter.java
package org.chronos.chronodb.api; /** * A simple filter interface for determining whether or not a given commit metadata object is valid. * * <p> * Clients are encouraged to provide their own implementation. An active instance of this interface will * always be created using reflection and therefore requires a default constructor. * </p> * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface CommitMetadataFilter { /** * Checks if this filter permits the given commit metadata object. * * @param branch The branch at which the commit is aimed. Must not be <code>null</code>. * @param timestamp The intended timestamp of the commit. Never negative. * @param metadata The commit metadata object. May be <code>null</code>. * @return <code>true</code> if the filter accepts the given object as valid, or <code>false</code> if the given object does not pass the filter. */ public boolean doesAccept(String branch, long timestamp, Object metadata); }
1,039
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DuplicateVersionEliminationMode.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/DuplicateVersionEliminationMode.java
package org.chronos.chronodb.api; import static com.google.common.base.Preconditions.*; import java.util.Collections; import java.util.Set; import com.google.common.collect.Sets; /** * The mode in which duplicate versions are eliminated by {@link ChronoDB}. * * <p> * "Duplicated versions" occur when the same value for the same key is committed several times, without any other values * in between. In other words, if a commit on a key occurs, and the committed value is exactly the same as the previous * one, then a duplicate version is created. Duplicate versions are not "harmful" in and on themselves, but they also * offer no additional information - they merely add more data to the database, reducing query performance in the * process. * * <p> * This enumeration describes how {@link ChronoDB} should attempt to eliminate such duplicated versions. * * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public enum DuplicateVersionEliminationMode { /** * Completely disables duplicate version elimination. * * <p> * For a definition of the "Duplicate Version Elimination" process, please see * {@link DuplicateVersionEliminationMode}. * * <p> * This means that a commit will be treated "as is", without even attempting to detect duplicated versions. This * results in the best write performance, but may reduce query performance and needlessly increase the size of the * database, as duplicated versions provide no additional information value. * * <p> * This setting is recommended under the following circumstances: * <ul> * <li>The write performance of a database or transaction has absolute priority over read performance. * <li>The application logic which uses this ChronoDB instance performs duplicate version checks on its own. * </ul> */ DISABLED("disabled", "off", "false"), /** * Duplicate version elimination will be performed when {@link ChronoDBTransaction#commit()} is called. * * <p> * For a definition of the "Duplicate Version Elimination" process, please see * {@link DuplicateVersionEliminationMode}. * * <p> * This introduces a performance penalty on the <code>commit()</code> operation, as every key-value pair that has * been added in this transaction via {@link ChronoDBTransaction#put(String, Object)} will be checked for version * duplicates. * */ ON_COMMIT("onCommit", "commit", "on_commit", "true"); // ===================================================================================================================== // FIELDS // ===================================================================================================================== /** The primary name for this mode. */ private final String primaryName; /** A set of aliases (alternative names) for this mode. */ private final Set<String> aliases; /** The set of all possible names for this mode. The union of {@link #primaryName} and {@link #aliases}. */ private final Set<String> allNames; /** * Creates a new enum literal instance, for internal use only. * * @param primaryName * The primary name for the mode. Must not be <code>null</code>. * @param aliases * The aliases (alternative names) to assign to this mode. May be empty, must not be <code>null</code>. */ private DuplicateVersionEliminationMode(final String primaryName, final String... aliases) { checkNotNull(primaryName, "Precondition violation - argument 'primaryName' must not be NULL!"); this.primaryName = primaryName; Set<String> myAliases = Sets.newHashSet(); if (aliases != null && aliases.length > 0) { for (String alias : aliases) { myAliases.add(alias); } } this.aliases = Collections.unmodifiableSet(myAliases); Set<String> myNames = Sets.newHashSet(); myNames.add(primaryName); myNames.addAll(this.aliases); this.allNames = Collections.unmodifiableSet(myNames); } @Override public String toString() { return this.primaryName; } /** * This method parses a string value into a {@link DuplicateVersionEliminationMode}. * * <p> * This method takes all aliases into account and is therefore more fault tolerant than the default * {@link #valueOf(String)} method. * * @param stringValue * The string value to parse. Must not be <code>null</code>. * @return The Duplicate Version Elimination mode described in the string. Never <code>null</code>. * * @throws IllegalArgumentException * Thrown if the parsing process failed. */ public static DuplicateVersionEliminationMode fromString(final String stringValue) { checkNotNull(stringValue, "Precondition violation - argument 'stringValue' must not be NULL!"); String token = stringValue.toLowerCase().trim(); if (token.isEmpty()) { throw new IllegalArgumentException("Cannot parse DuplicateVersionEliminationMode from empty string!"); } for (DuplicateVersionEliminationMode mode : DuplicateVersionEliminationMode.values()) { for (String name : mode.allNames) { if (name.equalsIgnoreCase(token)) { return mode; } } } throw new IllegalArgumentException("Unknown DuplicateVersionEliminationMode: '" + token + "'!"); } }
5,229
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
BackupManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/BackupManager.java
package org.chronos.chronodb.api; import org.chronos.chronodb.api.dump.IncrementalBackupInfo; import org.chronos.chronodb.api.dump.IncrementalBackupResult; import java.io.File; import java.util.Arrays; import java.util.List; import static com.google.common.base.Preconditions.*; public interface BackupManager { // ================================================================================================================= // FULL DUMP WRITING / LOADING // ================================================================================================================= /** * Creates a database dump of the entire current database state. * * <p> * Please note that the database is not available for write operations while the dump process is running. Read operations will work concurrently as usual. * * <p> * <b>WARNING:</b> The file created by this process may be very large (several gigabytes), depending on the size of the database. It is the responsibility of the user of this API to ensure that enough disk space is available; this method does not perform any checks regarding disk space availability! * * <p> * <b>WARNING:</b> The given file will be <b>overwritten</b> without further notice! * * @param dumpFile The file to store the dump into. Must not be <code>null</code>. Must point to a file (not a directory). The standard file extension <code>*.chronodump</code> is recommmended, but not required. If the file does not exist, the file (and any missing parent directory) will be created. * @param dumpOptions The options to use for this dump (optional). Please refer to the documentation of the invididual constants for details. */ public void writeDump(File dumpFile, DumpOption... dumpOptions); /** * Reads the contents of the given dump file into this database. * * <p> * This is a management operation; it completely locks the database. No concurrent writes or reads will be permitted while this operation is being executed. * * <p> * <b>WARNING:</b> The current contents of the database will be <b>merged</b> with the contents of the dump! In case of conflicts, the data stored in the dump file will take precedence. It is <i>strongly recommended</i> to perform this operation only on an <b>empty</b> database! * * <p> * <b>WARNING:</b> As this is a management operation, there is no rollback or undo option! * * @param dumpFile The dump file to read the data from. Must not be <code>null</code>, must exist, and must point to a file (not a directory). * @param options The options to use while reading (optional). May be empty. */ public void readDump(File dumpFile, DumpOption... options); // ================================================================================================================= // INCREMENTAL COMMIT METHODS // ================================================================================================================= public IncrementalBackupResult createIncrementalBackup(long minTimestamp, long lastRequestWallClockTime); public void loadIncrementalBackups(List<File> cibFiles); public default void loadIncrementalBackupsFromDirectory(File directory){ checkNotNull(directory, "Precondition violation - argument 'directory' must not be NULL!"); if(!directory.isDirectory()){ throw new IllegalArgumentException("Precondition violation - argument 'directory' must be an existing directory: " + directory.getAbsolutePath()); } // we are sure that the path exists and it is a directory // look for all '.cib' files File[] files = directory.listFiles(f -> f.getName().endsWith(ChronoDBConstants.INCREMENTAL_BACKUP_FILE_ENDING)); if(files == null || files.length <= 0){ return; } List<File> cibFiles = Arrays.asList(files); loadIncrementalBackups(cibFiles); } }
4,037
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDB.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChronoDB.java
package org.chronos.chronodb.api; import org.chronos.chronodb.internal.api.ChronoDBConfiguration; import org.chronos.chronodb.internal.api.cache.ChronoDBCache; import org.chronos.common.version.ChronosVersion; import java.io.File; /** * The top-level interface for interaction with a {@link ChronoDB} instance. * * <p> * This interface represents the entire database instance. Its primary purpose is to spawn instances of {@link ChronoDBTransaction}. Instances of this interface represent (and abstract from) an active connection to a backing datastore. * * <p> * You can acquire an instance of this class by using the static {@link #FACTORY} variable, like so: * * <pre> * ChronoDB db = ChronoDB.FACTORY... ; * </pre> * * <p> * Note that this interface extends {@link AutoCloseable}. The {@link #close()} method is used to close this database. As a database instance may hold resources that do not get released automatically upon garbage collection, <b>calling {@link #close()} is mandatory</b>. * * <p> * Instances of this class are guaranteed to be thread-safe and may be shared freely among threads. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoDB extends TransactionSource, AutoCloseable { /** * Provides access to the factory for this class. */ public static final ChronoDBFactory FACTORY = ChronoDBFactory.INSTANCE; /** * Returns the configuration of this {@link ChronoDB} instance. * * @return The configuration. Never <code>null</code>. */ public ChronoDBConfiguration getConfiguration(); /** * Returns the branch manager associated with this database instance. * * @return The branch manager. Never <code>null</code>. */ public BranchManager getBranchManager(); /** * Returns the index manager for this {@link ChronoDB} instance. * * @return The index manager. Never <code>null</code>. */ public IndexManager getIndexManager(); /** * Returns the serialization manager associated with this database instance. * * @return The serialization manager. Never <code>null</code>. */ public SerializationManager getSerializationManager(); /** * Returns the maintenance manager associated with this database instance. * * @return The maintenance manager. Never <code>null</code>. */ public MaintenanceManager getMaintenanceManager(); /** * Returns the statistics manager associated with this database instance. * * @return The statistics manager. Never <code>null</code>. */ public StatisticsManager getStatisticsManager(); /** * Returns the dateback manager associated with this database instance. * * <p> * Dateback operations allow to modify the history of the database content. It is <b>strongly discouraged</b> to execute any dateback operation while the database is online and accessible for regular transactions. * * <p> * <u><b>/!\ WARNING /!\</b></u><br> * Dateback operations should be a last resort and should be avoided at all costs during regular database operation. They have the following properties: * <ul> * <li>They are <b>not</b> ACID safe. Back up your database before attempting any dateback operation. * <li>They require an <b>exclusive lock</b> on the entire database. * <li>They <b>invalidate</b> all currently ongoing transactions. Transactions which are continued after a dateback operation are <b>not guaranteed</b> to be ACID anymore. * <li>They <b>cannot</b> be undone. * <li>They provide <b>direct access</b> to the temporal stores. There is <b>no safety net</b> to prevent erroneous states. * </ul> * * <b>DO NOT USE THE DATEBACK API UNLESS YOU KNOW <u>EXACTLY</u> WHAT YOU ARE DOING.</b><br> * * @return The dateback manager. Never <code>null</code>. */ public DatebackManager getDatebackManager(); /** * Returns the backup manager associated with this ChronoDB instance. * * @return The backup manager associated with this ChronoDB instance. Never <code>null</code>. */ public BackupManager getBackupManager(); /** * Returns the cache of this database instance. * * @return The cache. Never <code>null</code>. May be a bogus instance if caching is disabled. */ public ChronoDBCache getCache(); /** * Creates a database dump of the entire current database state. * * <p> * Please note that the database is not available for write operations while the dump process is running. Read operations will work concurrently as usual. * * <p> * <b>WARNING:</b> The file created by this process may be very large (several gigabytes), depending on the size of the database. It is the responsibility of the user of this API to ensure that enough disk space is available; this method does not perform any checks regarding disk space availability! * * <p> * <b>WARNING:</b> The given file will be <b>overwritten</b> without further notice! * * @param dumpFile The file to store the dump into. Must not be <code>null</code>. Must point to a file (not a directory). The standard file extension <code>*.chronodump</code> is recommmended, but not required. If the file does not exist, the file (and any missing parent directory) will be created. * @param dumpOptions The options to use for this dump (optional). Please refer to the documentation of the invididual constants for details. * * @deprecated Use {@link #getBackupManager()} methods instead. */ @Deprecated public default void writeDump(File dumpFile, DumpOption... dumpOptions){ this.getBackupManager().writeDump(dumpFile, dumpOptions); } /** * Reads the contents of the given dump file into this database. * * <p> * This is a management operation; it completely locks the database. No concurrent writes or reads will be permitted while this operation is being executed. * * <p> * <b>WARNING:</b> The current contents of the database will be <b>merged</b> with the contents of the dump! In case of conflicts, the data stored in the dump file will take precedence. It is <i>strongly recommended</i> to perform this operation only on an <b>empty</b> database! * * <p> * <b>WARNING:</b> As this is a management operation, there is no rollback or undo option! * * @param dumpFile The dump file to read the data from. Must not be <code>null</code>, must exist, and must point to a file (not a directory). * @param options The options to use while reading (optional). May be empty. * * @deprecated Use {@link #getBackupManager()} methods instead. */ @Deprecated public default void readDump(File dumpFile, DumpOption... options){ this.getBackupManager().readDump(dumpFile, options); } /** * Closes this instance of ChronoDB. * * <p> * This completely shuts down the database. Any further calls to retrieve or store data will fail. * * <p> * Users are responsible for calling this method when the interaction with the database stops in order to allow ChronoDB to shutdown gracefully. */ @Override public void close(); /** * Checks if this instance of ChronoDB has already been closed or not. * * <p> * This method is safe to call even after {@link #close()} has been called. * * @return <code>true</code> if this ChronoDB instance is closed, otherwise <code>false</code>. */ public boolean isClosed(); /** * Checks if this {@link ChronoDB} instance relies on a file-based backend. * * @return <code>true</code> if the backend is file-based, otherwise <code>false</code>. * @since 0.6.0 */ public boolean isFileBased(); /** * Returns the current version of Chronos, as used by this binary. * * <p> * Note that this version might be different from the version of chronos which * has last written to this database (see {@link #getStoredChronosVersion()}. * </p> * * @return The chronos version of this binary. Never <code>null</code>. */ public ChronosVersion getCurrentChronosVersion(); /** * Returns the version of Chronos which was last used to write to this database. * * @return The last version of Chronos used to write to this database. May be <code>null</code> if it was never written. */ public ChronosVersion getStoredChronosVersion(); /** * Returns the features supported by this database. * * @return The supported features. Never <code>null</code>. */ public ChronoDBFeatures getFeatures(); }
8,866
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBConstants.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChronoDBConstants.java
package org.chronos.chronodb.api; import org.chronos.common.exceptions.NotInstantiableException; /** * A static collection of constants used throughout the {@link ChronoDB} API. * * <p> * This class is merely a container for the constants and must not be instantiated. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public final class ChronoDBConstants { /** The identifier for the master branch. The master branch is predefined and always exists. */ public static final String MASTER_BRANCH_IDENTIFIER = "master"; /** The name for the default keyspace. The default keyspace is predefined and always exists. */ public static final String DEFAULT_KEYSPACE_NAME = "default"; /** The file ending for incremental backup files (<b>C</b>hronos <b>I</b>ncremental <b>B</b>ackup).*/ public static final String INCREMENTAL_BACKUP_FILE_ENDING = ".cib"; private ChronoDBConstants() { throw new NotInstantiableException("This class must not be instantiated!"); } public static final class IncrementalBackup { private IncrementalBackup(){ throw new NotInstantiableException("This class must not be instantiated!"); } public static final String METADATA_KEY_CHRONOS_VERSION = "org.chronos.chronodb.backup.incremental.chronos-version"; public static final String METADATA_KEY_FORMAT_VERSION = "org.chronos.chronodb.backup.incremental.format-version"; public static final String METADATA_KEY_REQUEST_START_TIMESTAMP = "org.chronos.chronodb.backup.incremental.request.start-timestamp"; public static final String METADATA_KEY_REQUEST_PREVIOUS_WALL_CLOCK_TIME = "org.chronos.chronodb.backup.incremental.request.previous-wall-clock-time"; public static final String METADATA_KEY_RESPONSE_WALL_CLOCK_TIME = "org.chronos.chronodb.backup.incremental.response.wall-clock-time"; public static final String METADATA_KEY_RESPONSE_NOW = "org.chronos.chronodb.backup.incremental.response.now"; } }
1,947
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBFactory.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChronoDBFactory.java
package org.chronos.chronodb.api; import org.chronos.chronodb.api.builder.database.ChronoDBBaseBuilder; import org.chronos.chronodb.internal.impl.builder.database.ChronoDBFactoryImpl; /** * Acts as a singleton factory for instances of {@link ChronoDB}. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoDBFactory { // ================================================================================================================= // STATIC PART // ================================================================================================================= /** The static factory instance. */ public static final ChronoDBFactory INSTANCE = new ChronoDBFactoryImpl(); // ================================================================================================================= // API METHODS // ================================================================================================================= /** * Starting point of the fluent API for database construction. * * @return The fluent database builder. Never <code>null</code>. */ public ChronoDBBaseBuilder create(); }
1,173
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
TransactionSource.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/TransactionSource.java
package org.chronos.chronodb.api; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.api.builder.transaction.ChronoDBTransactionBuilder; import org.chronos.chronodb.api.exceptions.InvalidTransactionBranchException; import org.chronos.chronodb.api.exceptions.InvalidTransactionTimestampException; /** * A {@link TransactionSource} is an object capable of producing a variety of {@link ChronoDBTransaction}s. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface TransactionSource { /** * Produces and returns a new instance of {@link ChronoDBTransaction} on the <i>master</i> branch <i>head</i> * version. * * <p> * Opening a read transaction is a cheap operation and can be executed deliberately. Also, there is no need to * explicitly close or terminate a read transaction. * * <p> * Note that transactions are in general not thread-safe and must not be shared among threads. * * @return The transaction. Never <code>null</code>. */ public default ChronoDBTransaction tx() { return this.txBuilder().build(); } /** * Produces and returns a new instance of {@link ChronoDBTransaction} on the <i>master</i> branch at the given * timestamp. * * <p> * Please note that implementations may choose to refuse opening a transaction on certain timestamps, e.g. when the * desired timestamp is in the future. In such cases, an {@link InvalidTransactionTimestampException} is thrown. * * <p> * Opening a transaction is a cheap operation and can be executed deliberately. Also, there is no need to explicitly * close or terminate a transaction. * * <p> * Note that transactions are in general not thread-safe and must not be shared among threads. * * @param timestamp * The timestamp to use. Must not be negative. * * @return The transaction. Never <code>null</code>. * * @throws InvalidTransactionTimestampException * Thrown if the transaction could not be opened due to an invalid timestamp. */ public default ChronoDBTransaction tx(final long timestamp) throws InvalidTransactionTimestampException { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must be >= 0 (value: " + timestamp + ")!"); return this.txBuilder().atTimestamp(timestamp).build(); } /** * Produces and returns a new instance of {@link ChronoDBTransaction} on the <i>head</i> version of the given * branch. * * <p> * Opening a transaction is a cheap operation and can be executed deliberately. Also, there is no need to explicitly * close or terminate a read transaction. * * <p> * Note that transactions are in general not thread-safe and must not be shared among threads. * * @param branchName * The name of the branch to start a transaction on. Must not be <code>null</code>. Must be the name of * an existing branch. * * @return The transaction. Never <code>null</code>. * * @throws InvalidTransactionBranchException * Thrown if the transaction could not be opened due to an invalid branch name. */ public default ChronoDBTransaction tx(final String branchName) throws InvalidTransactionBranchException { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); return this.txBuilder().onBranch(branchName).build(); } /** * Produces and returns a new instance of {@link ChronoDBTransaction} at the given timestamp on the given branch. * * <p> * Please note that implementations may choose to refuse opening a transaction on certain timestamps, e.g. when the * desired timestamp is in the future. In such cases, an {@link InvalidTransactionTimestampException} is thrown. * * <p> * Opening a transaction is a cheap operation and can be executed deliberately. Also, there is no need to explicitly * close or terminate a transaction. * * <p> * Note that transactions are in general not thread-safe and must not be shared among threads. * * @param branchName * The name of the branch to start a transaction on. Must not be <code>null</code>. Must be the name of * an existing branch. * @param timestamp * The timestamp to use. Must not be negative. * * @return The transaction. Never <code>null</code>. * * @throws InvalidTransactionBranchException * Thrown if the transaction could not be opened due to an invalid branch. * @throws InvalidTransactionTimestampException * Thrown if the transaction could not be opened due to an invalid timestamp. */ public default ChronoDBTransaction tx(final String branchName, final long timestamp) throws InvalidTransactionBranchException, InvalidTransactionTimestampException { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must be >= 0 (value: " + timestamp + ")!"); return this.txBuilder().onBranch(branchName).atTimestamp(timestamp).build(); } /** * Creates a new {@link ChronoDBTransactionBuilder} for fluent transaction configuration. * * <p> * When you have called all relevant configuration methods, use {@link ChronoDBTransactionBuilder#build()} to * receive the configured {@link ChronoDBTransaction}. * * @return The transaction builder. */ public ChronoDBTransactionBuilder txBuilder(); }
5,498
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBFeatures.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChronoDBFeatures.java
package org.chronos.chronodb.api; /** * This interface describes the features supported by a {@link ChronoDB} instance. * * <p> * To get an instance of this class, please use {@link ChronoDB#getFeatures()}. * </p> * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoDBFeatures { /** * Checks if this database is persistent, i.e. has a representation on disk. * * <p> * If this method returns <code>false</code>, the database is in-memory only. * </p> * * @return <code>true</code> if the database is persistent, otherwise <code>false</code>. */ public boolean isPersistent(); /** * Checks if this database supports the rollover mechanism. * * @return <code>true</code> if rollovers are supported, otherwise <code>false</code>. */ public boolean isRolloverSupported(); /** * Checks if this database supports incremental backups. * * @return <code>true</code> if incremental backups are supported, otherwise <code>false</code>. */ public boolean isIncrementalBackupSupported(); }
1,140
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBTransaction.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChronoDBTransaction.java
package org.chronos.chronodb.api; import org.chronos.chronodb.api.builder.query.QueryBuilderFinalizer; import org.chronos.chronodb.api.builder.query.QueryBuilderStarter; import org.chronos.chronodb.api.conflict.ConflictResolutionStrategy; import org.chronos.chronodb.api.exceptions.ChronoDBCommitException; import org.chronos.chronodb.api.exceptions.TransactionIsReadOnlyException; import org.chronos.chronodb.api.exceptions.UnknownKeyspaceException; import org.chronos.chronodb.api.exceptions.ValueTypeMismatchException; import org.chronos.chronodb.api.key.TemporalKey; import org.chronos.chronodb.internal.api.TemporalKeyValueStore; import org.chronos.chronodb.internal.api.query.ChronoDBQuery; import java.util.*; import java.util.Map.Entry; /** * A {@link ChronoDBTransaction} encapsulates a set of queries and/or change operations on a {@link ChronoDB}. * <p> * <p> * Instances of this interface are produced by a {@link TransactionSource}. API users should make use of the methods of * {@link ChronoDB}, which implements TransactionSource. * <p> * <p> * Instances of this class are in general not guaranteed to be thread-safe, and should not be shared among threads. * <p> * <p> * Note that opening a ChronoTransaction does not imply any further obligations. In particular, ChronoTransactions do * not have to be closed or terminated in any way. * <p> * <p> * Changes made to the transaction will not be persisted immediately. They will be kept in-memory until * {@link #commit()} is invoked. Calling {@link #rollback()} will clear this in-memory cache. * <p> * <p> * Users may continue to use a {@link ChronoDBTransaction} after calling {@link #commit()} or {@link #rollback()} on it. * It will behave as if it had been newly instantiated. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface ChronoDBTransaction { // ===================================================================================================================== // TRANSACTION METADATA // ===================================================================================================================== /** * Returns the timestamp on which this transaction operates. * * @return The timestamp, which is always a number greater than (or equal to) zero. */ public long getTimestamp(); /** * Returns an identifier for the branch on which this transaction operates. * * @return The branch identifier */ public String getBranchName(); // ===================================================================================================================== // DATA RETRIEVAL // ===================================================================================================================== /** * Returns the value of the given key in the <i>default</i> keyspace, at the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * // note the automatic cast to the expected type * String value = tx.get(&quot;Hello&quot;); * </pre> * * @param key The key to get the value for. Must not be <code>null</code>. * @return The value associated with the given key, cast to the given generic argument. Returns <code>null</code> if * there is no value for the given key. * @throws ValueTypeMismatchException Thrown if the stored value cannot be cast to the expected type argument. */ public <T> T get(String key) throws ValueTypeMismatchException; /** * Returns the value of the given key in the <i>default</i> keyspace in binary (serialized) format, at the timestamp of this transaction. * <p> * <p> * <p> * Usage example: * <p> * <pre> * byte[] value = tx.getBinary(&quot;Hello&quot;); * </pre> * * The returned byte array can be passed to the {@link SerializationManager#deserialize(byte[])} method of {@link ChronoDB#getSerializationManager()}. * Deserialization may fail under certain circumstances (e.g. when the class of the serialized object has changed since the serialization). * * @param key The key to get the value for. Must not be <code>null</code>. * @return The value associated with the given key, as byte array. Returns <code>null</code> if there is no value for the given key. * @throws UnknownKeyspaceException Thrown if the specified keyspace name does not refer to an existing keyspace. */ public byte[] getBinary(String key) throws UnknownKeyspaceException; /** * Returns the value of the given key in the given keyspace, at the timestamp of this transaction. * <p> * <p> * <p> * Usage example: * <p> * <pre> * // note the automatic cast to the expected type * String value = tx.get(&quot;MyKeyspace&quot;, &quot;Hello&quot;); * </pre> * * @param keyspaceName The name of the keyspace to search in. Must not be <code>null</code>. * @param key The key to get the value for. Must not be <code>null</code>. * @return The value associated with the given key, cast to the given generic argument. Returns <code>null</code> if * there is no value for the given key. * @throws ValueTypeMismatchException Thrown if the stored value cannot be cast to the expected type argument. * @throws UnknownKeyspaceException Thrown if the specified keyspace name does not refer to an existing keyspace. */ public <T> T get(String keyspaceName, String key) throws ValueTypeMismatchException, UnknownKeyspaceException; /** * Returns the value of the given key in the given keyspace in binary (serialized) format, at the timestamp of this transaction. * <p> * <p> * <p> * Usage example: * <p> * <pre> * byte[] value = tx.getBinary(&quot;MyKeyspace&quot;, &quot;Hello&quot;); * </pre> * * The returned byte array can be passed to the {@link SerializationManager#deserialize(byte[])} method of {@link ChronoDB#getSerializationManager()}. * Deserialization may fail under certain circumstances (e.g. when the class of the serialized object has changed since the serialization). * * @param keyspaceName The name of the keyspace to search in. Must not be <code>null</code>. * @param key The key to get the value for. Must not be <code>null</code>. * @return The value associated with the given key, as byte array. Returns <code>null</code> if there is no value for the given key. * @throws UnknownKeyspaceException Thrown if the specified keyspace name does not refer to an existing keyspace. */ public byte[] getBinary(String keyspaceName, String key) throws UnknownKeyspaceException; /** * Checks if there is a value for the given key in the <i>default</i> keyspace, at the timestamp of this * transaction. * <p> * <p> * Usage example: * <p> * <pre> * boolean keyExists = tx.exists("MyKey") * </pre> * * @param key The key to check the existence of a value for. Must not be <code>null</code>. * @return <code>true</code> if there is a value for the given key, otherwise <code>false</code>. */ public boolean exists(String key); /** * Checks if there is a value for the given key in the given keyspace, at the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * boolean keyExists = tx.exists("MyKeyspace", "MyKey") * </pre> * * @param keyspaceName The name of the keyspace to search in. Must not be <code>null</code>. * @param key The key to check the existence of a value for. Must not be <code>null</code>. * @return <code>true</code> if there is a value for the given key, otherwise <code>false</code>. */ public boolean exists(String keyspaceName, String key); /** * Returns the set of all keys present in the <i>default</i> keyspace at the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * for (String key : tx.keySet()) { * tx.exists(key); // is always true * } * </pre> * * @return The key set. May be empty, but never <code>null</code>. */ public Set<String> keySet(); /** * Returns the set of all keys present in the given keyspace at the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * for (String key : tx.keySet(&quot;MyKeyspace&quot;)) { * tx.exists(key); // is always true * } * </pre> * * @param keyspaceName The name of the keyspace to scan. Must not be <code>null</code>. * @return The key set. May be empty, but never <code>null</code>. */ public Set<String> keySet(String keyspaceName); /** * Returns the timestamps in the past at which the value for the given key has changed in the <i>default</i> * keyspace, up to the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * Iterator&lt;Long&gt; iterator = tx.history(&quot;MyKey&quot;); * while (iterator.hasNext()) { * long timestamp = iterator.next(); * Object pastValue = chronoDB.tx(timestamp).get(&quot;MyKey&quot;); * String msg = &quot;At timestamp &quot; + timestamp + &quot;, the value of 'MyKey' was changed to '&quot; + pastValue + &quot;'&quot;; * System.out.println(msg); * } * </pre> * * @param key The key to get the history for. Must not be <code>null</code>. * @return An iterator over the history timestamps in descending order (highest first). May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String key){ if(this.getTimestamp() == 0){ // this database is empty -> history is also empty. return Collections.emptyIterator(); } return this.history(ChronoDBConstants.DEFAULT_KEYSPACE_NAME, key, 0, this.getTimestamp(), Order.DESCENDING); } /** * Returns the timestamps in the past at which the value for the given key has changed in the <i>default</i> * keyspace, up to the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * Iterator&lt;Long&gt; iterator = tx.history(&quot;MyKey&quot;); * while (iterator.hasNext()) { * long timestamp = iterator.next(); * Object pastValue = chronoDB.tx(timestamp).get(&quot;MyKey&quot;); * String msg = &quot;At timestamp &quot; + timestamp + &quot;, the value of 'MyKey' was changed to '&quot; + pastValue + &quot;'&quot;; * System.out.println(msg); * } * </pre> * * @param key The key to get the history for. Must not be <code>null</code>. * @param order The order of the resulting iterator. Must not be <code>null</code>. * @return An iterator over the history timestamps in the given order. May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String key, Order order){ return this.history(ChronoDBConstants.DEFAULT_KEYSPACE_NAME, key, 0, this.getTimestamp(), order); } /** * Returns the history of the given key (in the default keyspace) in the given time frame (both bounds inclusive). * * @param key The key to get the history for. Must not be <code>null</code>. * @param lowerBound The (inclusive) lower bound to search for. Must not be negative. Must be less than or equal to <code>upperBound</code>. Must be less than or equal to the transaction timestamp. * @param upperBound The (inclusive) upper bound to search for. Must not be negative. Must be greater than or equal to <code>lowerBound</code>. Must be less than or equal to the transaction timestamp. * @return An iterator over the history timestamps in the given range in descending order (highest first). May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String key, long lowerBound, long upperBound){ return this.history(ChronoDBConstants.DEFAULT_KEYSPACE_NAME, key, lowerBound, upperBound, Order.DESCENDING); } /** * Returns the history of the given key (in the default keyspace) in the given time frame (both bounds inclusive). * * @param key The key to get the history for. Must not be <code>null</code>. * @param lowerBound The (inclusive) lower bound to search for. Must not be negative. Must be less than or equal to <code>upperBound</code>. Must be less than or equal to the transaction timestamp. * @param upperBound The (inclusive) upper bound to search for. Must not be negative. Must be greater than or equal to <code>lowerBound</code>. Must be less than or equal to the transaction timestamp. * @param order The order of the resulting iterator. Must not be <code>null</code>. * @return An iterator over the history timestamps in the given range in descending order (highest first). May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String key, long lowerBound, long upperBound, Order order){ return this.history(ChronoDBConstants.DEFAULT_KEYSPACE_NAME, key, lowerBound, upperBound, order); } /** * Returns the timestamps in the past at which the value for the given key has changed in the given keyspace, up to * the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * Iterator&lt;Long&gt; iterator = tx.history(&quot;MyKeyspace&quot;, &quot;MyKey&quot;); * while (iterator.hasNext()) { * long timestamp = iterator.next(); * Object pastValue = chronoDB.tx(timestamp).get(&quot;MyKey&quot;); * String msg = &quot;At timestamp &quot; + timestamp + &quot;, the value of 'MyKey' was changed to '&quot; + pastValue + &quot;'&quot;; * System.out.println(msg); * } * </pre> * * @param key The key to get the history for. Must not be <code>null</code>. * @param keyspaceName The name of the keyspace to scan. Must not be <code>null</code>. * @return An iterator over the history timestamps in descending order (highest first). May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String keyspaceName, String key){ return this.history(keyspaceName, key, 0, this.getTimestamp(), Order.DESCENDING); } /** * Returns the history of the given key in the given keyspace and time frame (both bounds inclusive). * * @param keyspaceName The name of the keyspace the key resides in. Must not be <code>null</code>. * @param key The key to get the history for. Must not be <code>null</code>. * @param lowerBound The (inclusive) lower bound to search for. Must not be negative. Must be less than or equal to <code>upperBound</code>. Must be less than or equal to the transaction timestamp. * @param upperBound The (inclusive) upper bound to search for. Must not be negative. Must be greater than or equal to <code>lowerBound</code>. Must be less than or equal to the transaction timestamp. * @return An iterator over the history timestamps in the given range in descending order (highest first). May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String keyspaceName, String key, long lowerBound, long upperBound){ return this.history(keyspaceName, key, lowerBound, upperBound, Order.DESCENDING); } /** * Returns the timestamps in the past at which the value for the given key has changed in the given keyspace, up to * the timestamp of this transaction. * <p> * <p> * Usage example: * <p> * <pre> * Iterator&lt;Long&gt; iterator = tx.history(&quot;MyKeyspace&quot;, &quot;MyKey&quot;, Order.DESCENDING); * while (iterator.hasNext()) { * long timestamp = iterator.next(); * Object pastValue = chronoDB.tx(timestamp).get(&quot;MyKey&quot;); * String msg = &quot;At timestamp &quot; + timestamp + &quot;, the value of 'MyKey' was changed to '&quot; + pastValue + &quot;'&quot;; * System.out.println(msg); * } * </pre> * * @param key The key to get the history for. Must not be <code>null</code>. * @param keyspaceName The name of the keyspace to scan. Must not be <code>null</code>. * @param order The order of the history. Must not be <code>null</code>. * @return An iterator over the history timestamps in descending order (highest first). May be empty, but never <code>null</code>. */ public default Iterator<Long> history(String keyspaceName, String key, Order order){ return this.history(keyspaceName, key, 0, this.getTimestamp(), order); } /** * Returns the history of the given key in the given keyspace and time frame (both bounds inclusive). * * @param keyspaceName The name of the keyspace the key resides in. Must not be <code>null</code>. * @param key The key to get the history for. Must not be <code>null</code>. * @param lowerBound The (inclusive) lower bound to search for. Must not be negative. Must be less than or equal to <code>upperBound</code>. Must be less than or equal to the transaction timestamp. * @param upperBound The (inclusive) upper bound to search for. Must not be negative. Must be greater than or equal to <code>lowerBound</code>. Must be less than or equal to the transaction timestamp. * @param order The order of the history. Must not be <code>null</code>. * @return An iterator over the history timestamps in the given range in the given order. May be empty, but never <code>null</code>. */ public Iterator<Long> history(String keyspaceName, String key, long lowerBound, long upperBound, Order order); /** * Returns the most recent (highest) timestamp at which the given key (in the default keyspace) was last modified. * * <p> * Modifications which occurred at a timestamp which is than the transaction timestamp will not be considered. * </p> * * <p> * If the key has been modified exactly at the transaction timestamp, the transaction timestamp will be returned. * </p> * * <p> * If the key does not exist (yet), then -1 will be returned. * </p> * * <p> * Note that the key does not need to have a value associated with it at the transaction timestamp: if the latest operation on the key was a deletion, the timestamp of the deletion will be reported. * </p> * * @param key The key (in the default keyspace) to get the last modification timestamp for. Must not be <code>null</code>. * @return The latest timestamp at which the value associated with the given key was modified which is less than or equal to the transaction timestamp, or -1 if the key does not exist (yet). */ public default long getLastModificationTimestamp(String key){ return this.getLastModificationTimestamp(ChronoDBConstants.DEFAULT_KEYSPACE_NAME, key); } /** * Returns the most recent (highest) timestamp at which the given key was last modified. * * <p> * Modifications which occurred at a timestamp which is than the transaction timestamp will not be considered. * </p> * * <p> * If the key has been modified exactly at the transaction timestamp, the transaction timestamp will be returned. * </p> * * <p> * If the key does not exist (yet), then -1 will be returned. * </p> * * <p> * Note that the key does not need to have a value associated with it at the transaction timestamp: if the latest operation on the key was a deletion, the timestamp of the deletion will be reported. * </p> * * @param keyspace The keyspace in which the key resides. Must not be <code>null</code>. * @param key The key to get the last modification timestamp for. Must not be <code>null</code>. * @return The latest timestamp at which the value associated with the given key was modified which is less than or equal to the transaction timestamp, or -1 if the key does not exist (yet). */ public long getLastModificationTimestamp(String keyspace, String key); /** * Returns an iterator over the modified keys in the given timestamp range. * <p> * <p> * Please note that <code>timestampLowerBound</code> and <code>timestampUpperBound</code> must not be larger than * the timestamp of this transaction, i.e. you can only look for timestamp ranges in the past with this method. * * @param keyspace The keyspace to look for changes in. Must not be <code>null</code>. For non-existing keyspaces, the * resulting iterator will be empty. * @param timestampLowerBound The lower bound on the time range to look for. Must not be negative. Must be less than or equal to * <code>timestampUpperBound</code>. Must be less than or equal to the timestamp of this transaction. * @param timestampUpperBound The upper bound on the time range to look for. Must not be negative. Must be greater than or equal to * <code>timestampLowerBound</code>. Must be less than or equal to the timestamp of this transaction. * @return An iterator containing the {@link TemporalKey}s that reflect the modifications. May be empty, but never * <code>null</code>. */ public Iterator<TemporalKey> getModificationsInKeyspaceBetween(String keyspace, long timestampLowerBound, long timestampUpperBound); /** * Returns the metadata object stored alongside the commit at the given timestamp. * <p> * <p> * It is important that the given timestamp matches the commit timestamp <b>exactly</b>. Commit timestamps can be * retrieved for example via {@link #getModificationsInKeyspaceBetween(String, long, long)}. * * @param commitTimestamp The commit timestamp to get the metadata object for. Must match the commit timestamp exactly. Must not * be negative. Must be less than or equal to the timestamp of this transaction (i.e. must be in the * past). * @return The object stored alongside that commit. Will be <code>null</code> for all timestamps that are not * associated with a commit. May also be <code>null</code> in cases where no metadata object was given for * the commit by the user. */ public Object getCommitMetadata(long commitTimestamp); /** * Returns an iterator over all timestamps where commits have occurred, bounded between <code>from</code> and * <code>to</code>, in descending order. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @return The iterator over the commit timestamps in the given time range, in descending order. May be empty, but * never <code>null</code>. */ default Iterator<Long> getCommitTimestampsBetween(final long from, final long to) { return getCommitTimestampsBetween(from, to, false); } /** * Returns an iterator over all timestamps where commits have occurred, bounded between <code>from</code> and * <code>to</code>, in descending order. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return The iterator over the commit timestamps in the given time range, in descending order. May be empty, but * never <code>null</code>. */ public default Iterator<Long> getCommitTimestampsBetween(final long from, final long to, final boolean includeSystemInternalCommits) { return this.getCommitTimestampsBetween(from, to, Order.DESCENDING, includeSystemInternalCommits); } /** * Returns an iterator over all timestamps where commits have occurred, bounded between <code>from</code> and * <code>to</code>. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param order The order of the returned timestamps. Must not be <code>null</code>. * @return The iterator over the commit timestamps in the given time range. May be empty, but never * <code>null</code>. */ default Iterator<Long> getCommitTimestampsBetween(long from, long to, Order order) { return getCommitTimestampsBetween(from, to, order, false); } /** * Returns an iterator over all timestamps where commits have occurred, bounded between <code>from</code> and * <code>to</code>. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param order The order of the returned timestamps. Must not be <code>null</code>. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return The iterator over the commit timestamps in the given time range. May be empty, but never * <code>null</code>. */ public Iterator<Long> getCommitTimestampsBetween(long from, long to, Order order, final boolean includeSystemInternalCommits); /** * Returns an iterator over the entries of commit timestamp and associated metadata, bounded between * <code>from</code> and <code>to</code>, in descending order. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * <p> * <p> * Please keep in mind that some commits may not have any metadata attached. In this case, the * {@linkplain Entry#getValue() value} component of the {@link Entry} will be set to <code>null</code>. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @return An iterator over the commits in the given time range in descending order. The contained entries have the * timestamp as the {@linkplain Entry#getKey() key} component and the associated metadata as their * {@linkplain Entry#getValue() value} component (which may be <code>null</code>). May be empty, but never * <code>null</code>. */ default Iterator<Entry<Long, Object>> getCommitMetadataBetween(final long from, final long to) { return getCommitMetadataBetween(from, to, false); } /** * Returns an iterator over the entries of commit timestamp and associated metadata, bounded between * <code>from</code> and <code>to</code>, in descending order. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * <p> * <p> * Please keep in mind that some commits may not have any metadata attached. In this case, the * {@linkplain Entry#getValue() value} component of the {@link Entry} will be set to <code>null</code>. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return An iterator over the commits in the given time range in descending order. The contained entries have the * timestamp as the {@linkplain Entry#getKey() key} component and the associated metadata as their * {@linkplain Entry#getValue() value} component (which may be <code>null</code>). May be empty, but never * <code>null</code>. */ public default Iterator<Entry<Long, Object>> getCommitMetadataBetween(final long from, final long to, final boolean includeSystemInternalCommits) { return this.getCommitMetadataBetween(from, to, Order.DESCENDING, includeSystemInternalCommits); } /** * Returns an iterator over the entries of commit timestamp and associated metadata, bounded between * <code>from</code> and <code>to</code>. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * <p> * <p> * Please keep in mind that some commits may not have any metadata attached. In this case, the * {@linkplain Entry#getValue() value} component of the {@link Entry} will be set to <code>null</code>. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param order The order of the returned commits. Must not be <code>null</code>. * @return An iterator over the commits in the given time range. The contained entries have the timestamp as the * {@linkplain Entry#getKey() key} component and the associated metadata as their * {@linkplain Entry#getValue() value} component (which may be <code>null</code>). May be empty, but never * <code>null</code>. */ default Iterator<Entry<Long, Object>> getCommitMetadataBetween(long from, long to, Order order) { return getCommitMetadataBetween(from, to, order, false); } /** * Returns an iterator over the entries of commit timestamp and associated metadata, bounded between * <code>from</code> and <code>to</code>. * <p> * <p> * If the <code>from</code> value is greater than the <code>to</code> value, this method always returns an empty * iterator. * <p> * <p> * Please keep in mind that some commits may not have any metadata attached. In this case, the * {@linkplain Entry#getValue() value} component of the {@link Entry} will be set to <code>null</code>. * * @param from The lower bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param to The upper bound of the time range to look for commits in (inclusive). Must not be negative. Must be * less than or equal to the timestamp of this transaction. * @param order The order of the returned commits. Must not be <code>null</code>. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return An iterator over the commits in the given time range. The contained entries have the timestamp as the * {@linkplain Entry#getKey() key} component and the associated metadata as their * {@linkplain Entry#getValue() value} component (which may be <code>null</code>). May be empty, but never * <code>null</code>. */ public Iterator<Entry<Long, Object>> getCommitMetadataBetween(long from, long to, Order order, final boolean includeSystemInternalCommits); /** * Returns an iterator over commit timestamps in a paged fashion. * <p> * <p> * For example, calling {@code getCommitTimestampsPaged(10000, 100, 0, Order.DESCENDING)} will give the latest 100 * commit timestamps that have occurred before timestamp 10000. Calling * {@code getCommitTimestampsPaged(123456, 200, 2, Order.DESCENDING} will return 200 commit timestamps, skipping the * 400 latest commit timestamps, which are smaller than 123456. * * @param minTimestamp The minimum timestamp to consider (inclusive). All lower timestamps will be excluded from the * pagination. Must be less than or equal to the timestamp of this transaction. * @param maxTimestamp The highest timestamp to consider (inclusive). All higher timestamps will be excluded from the * pagination. Must be less than or equal to the timestamp of this transaction. * @param pageSize The size of the page, i.e. the maximum number of elements allowed to be contained in the resulting * iterator. Must be greater than zero. * @param pageIndex The index of the page to retrieve. Must not be negative. * @param order The desired ordering for the commit timestamps * @return An iterator that contains the commit timestamps for the requested page. Never <code>null</code>, may be * empty. If the requested page does not exist, this iterator will always be empty. */ default Iterator<Long> getCommitTimestampsPaged(final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order) { return getCommitTimestampsPaged(minTimestamp, maxTimestamp, pageSize, pageIndex, order, false); } /** * Returns an iterator over commit timestamps in a paged fashion. * <p> * <p> * For example, calling {@code getCommitTimestampsPaged(10000, 100, 0, Order.DESCENDING)} will give the latest 100 * commit timestamps that have occurred before timestamp 10000. Calling * {@code getCommitTimestampsPaged(123456, 200, 2, Order.DESCENDING} will return 200 commit timestamps, skipping the * 400 latest commit timestamps, which are smaller than 123456. * * @param minTimestamp The minimum timestamp to consider (inclusive). All lower timestamps will be excluded from the * pagination. Must be less than or equal to the timestamp of this transaction. * @param maxTimestamp The highest timestamp to consider (inclusive). All higher timestamps will be excluded from the * pagination. Must be less than or equal to the timestamp of this transaction. * @param pageSize The size of the page, i.e. the maximum number of elements allowed to be contained in the resulting * iterator. Must be greater than zero. * @param pageIndex The index of the page to retrieve. Must not be negative. * @param order The desired ordering for the commit timestamps * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return An iterator that contains the commit timestamps for the requested page. Never <code>null</code>, may be * empty. If the requested page does not exist, this iterator will always be empty. */ public Iterator<Long> getCommitTimestampsPaged(final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits); /** * Returns an iterator over commit timestamps and associated metadata in a paged fashion. * <p> * <p> * For example, calling {@code getCommitTimestampsPaged(10000, 100, 0, Order.DESCENDING)} will give the latest 100 * commit timestamps that have occurred before timestamp 10000. Calling * {@code getCommitTimestampsPaged(123456, 200, 2, Order.DESCENDING} will return 200 commit timestamps, skipping the * 400 latest commit timestamps, which are smaller than 123456. * <p> * <p> * The {@link Entry Entries} returned by the iterator always have the commit timestamp as their first component and * the metadata associated with this commit as their second component. The second component can be <code>null</code> * if the commit was executed without providing metadata. * * @param minTimestamp The minimum timestamp to consider (inclusive). All lower timestamps will be excluded from the * pagination. Must be less than or equal to the timestamp of this transaction. * @param maxTimestamp The highest timestamp to consider. All higher timestamps will be excluded from the pagination. Must be * less than or equal to the timestamp of this transaction. * @param pageSize The size of the page, i.e. the maximum number of elements allowed to be contained in the resulting * iterator. Must be greater than zero. * @param pageIndex The index of the page to retrieve. Must not be negative. * @param order The desired ordering for the commit timestamps * @return An iterator that contains the commits for the requested page. Never <code>null</code>, may be empty. If * the requested page does not exist, this iterator will always be empty. */ default Iterator<Entry<Long, Object>> getCommitMetadataPaged(final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order) { return getCommitMetadataPaged(minTimestamp, maxTimestamp, pageSize, pageIndex, order, false); } /** * Returns an iterator over commit timestamps and associated metadata in a paged fashion. * <p> * <p> * For example, calling {@code getCommitTimestampsPaged(10000, 100, 0, Order.DESCENDING)} will give the latest 100 * commit timestamps that have occurred before timestamp 10000. Calling * {@code getCommitTimestampsPaged(123456, 200, 2, Order.DESCENDING} will return 200 commit timestamps, skipping the * 400 latest commit timestamps, which are smaller than 123456. * <p> * <p> * The {@link Entry Entries} returned by the iterator always have the commit timestamp as their first component and * the metadata associated with this commit as their second component. The second component can be <code>null</code> * if the commit was executed without providing metadata. * * @param minTimestamp The minimum timestamp to consider (inclusive). All lower timestamps will be excluded from the * pagination. Must be less than or equal to the timestamp of this transaction. * @param maxTimestamp The highest timestamp to consider. All higher timestamps will be excluded from the pagination. Must be * less than or equal to the timestamp of this transaction. * @param pageSize The size of the page, i.e. the maximum number of elements allowed to be contained in the resulting * iterator. Must be greater than zero. * @param pageIndex The index of the page to retrieve. Must not be negative. * @param order The desired ordering for the commit timestamps * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return An iterator that contains the commits for the requested page. Never <code>null</code>, may be empty. If * the requested page does not exist, this iterator will always be empty. */ public Iterator<Entry<Long, Object>> getCommitMetadataPaged(final long minTimestamp, final long maxTimestamp, final int pageSize, final int pageIndex, final Order order, final boolean includeSystemInternalCommits); /** * Returns pairs of commit timestamp and commit metadata which are "around" the given timestamp on the time axis. * <p> * <p> * By default, this method will attempt to return the closest <code>count/2</code> commits before and after the * given timestamp. However, if there are not enough elements on either side, the other side will have more entries * in the result list (e.g. if the request count is 10 and there are only two commits before the request timestamp, * the list of commits after the request timestamp will have 8 entries instead of 5 to create a list of total length * 10). In other words, the result list will always have as many entries as the request <code>count</code>, except * when there are not as many commits on the store yet. * * @param timestamp The request timestamp around which the commits should be centered. Must not be negative. * @param count How many commits to retrieve around the request timestamp. By default, the closest * <code>count/2</code> commits will be taken on both sides of the request timestamp. Must not be * negative. * @return A list of pairs. The keys are commit timsetamps, the corresponding values are the commit metadata objects * (which may be <code>null</code>). The list itself will never be <code>null</code>, but may be empty (if * there are no commits to report). The list is sorted in descending order by timestamps. */ default List<Entry<Long, Object>> getCommitMetadataAround(final long timestamp, final int count) { return getCommitMetadataAround(timestamp, count, false); } /** * Returns pairs of commit timestamp and commit metadata which are "around" the given timestamp on the time axis. * <p> * <p> * By default, this method will attempt to return the closest <code>count/2</code> commits before and after the * given timestamp. However, if there are not enough elements on either side, the other side will have more entries * in the result list (e.g. if the request count is 10 and there are only two commits before the request timestamp, * the list of commits after the request timestamp will have 8 entries instead of 5 to create a list of total length * 10). In other words, the result list will always have as many entries as the request <code>count</code>, except * when there are not as many commits on the store yet. * * @param timestamp The request timestamp around which the commits should be centered. Must not be negative. * @param count How many commits to retrieve around the request timestamp. By default, the closest * <code>count/2</code> commits will be taken on both sides of the request timestamp. Must not be * negative. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return A list of pairs. The keys are commit timsetamps, the corresponding values are the commit metadata objects * (which may be <code>null</code>). The list itself will never be <code>null</code>, but may be empty (if * there are no commits to report). The list is sorted in descending order by timestamps. */ public List<Entry<Long, Object>> getCommitMetadataAround(final long timestamp, final int count, final boolean includeSystemInternalCommits); /** * Returns pairs of commit timestamp and commit metadata which are strictly before the given timestamp on the time * axis. * <p> * <p> * For example, calling {@link #getCommitMetadataBefore(long, int)} with a timestamp and a count of 10, this method * will return the latest 10 commits (strictly) before the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve before the given request timestamp. Must not be negative. * @return A list of pairs. The keys are commit timsetamps, the corresponding values are the commit metadata objects * (which may be <code>null</code>). The list itself will never be <code>null</code>, but may be empty (if * there are no commits to report). The list is sorted in descending order by timestamps. */ default List<Entry<Long, Object>> getCommitMetadataBefore(final long timestamp, final int count) { return getCommitMetadataBefore(timestamp, count, false); } /** * Returns pairs of commit timestamp and commit metadata which are strictly before the given timestamp on the time * axis. * <p> * <p> * For example, calling {@link #getCommitMetadataBefore(long, int)} with a timestamp and a count of 10, this method * will return the latest 10 commits (strictly) before the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve before the given request timestamp. Must not be negative. * @param includeSytemInternalCommits Whether or not to include system-internal commits. * @return A list of pairs. The keys are commit timsetamps, the corresponding values are the commit metadata objects * (which may be <code>null</code>). The list itself will never be <code>null</code>, but may be empty (if * there are no commits to report). The list is sorted in descending order by timestamps. */ public List<Entry<Long, Object>> getCommitMetadataBefore(final long timestamp, final int count, final boolean includeSytemInternalCommits); /** * Returns pairs of commit timestamp and commit metadata which are strictly after the given timestamp on the time * axis. * <p> * <p> * For example, calling {@link #getCommitMetadataAfter(long, int)} with a timestamp and a count of 10, this method * will return the oldest 10 commits (strictly) after the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve after the given request timestamp. Must not be negative. * @return A list of pairs. The keys are commit timsetamps, the corresponding values are the commit metadata objects * (which may be <code>null</code>). The list itself will never be <code>null</code>, but may be empty (if * there are no commits to report). The list is sorted in descending order by timestamps. */ default List<Entry<Long, Object>> getCommitMetadataAfter(final long timestamp, final int count) { return getCommitMetadataAfter(timestamp, count, false); } /** * Returns pairs of commit timestamp and commit metadata which are strictly after the given timestamp on the time * axis. * <p> * <p> * For example, calling {@link #getCommitMetadataAfter(long, int)} with a timestamp and a count of 10, this method * will return the oldest 10 commits (strictly) after the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve after the given request timestamp. Must not be negative. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return A list of pairs. The keys are commit timsetamps, the corresponding values are the commit metadata objects * (which may be <code>null</code>). The list itself will never be <code>null</code>, but may be empty (if * there are no commits to report). The list is sorted in descending order by timestamps. */ public List<Entry<Long, Object>> getCommitMetadataAfter(final long timestamp, final int count, final boolean includeSystemInternalCommits); /** * Returns a list of commit timestamp which are "around" the given timestamp on the time axis. * <p> * <p> * By default, this method will attempt to return the closest <code>count/2</code> commits before and after the * given timestamp. However, if there are not enough elements on either side, the other side will have more entries * in the result list (e.g. if the request count is 10 and there are only two commits before the request timestamp, * the list of commits after the request timestamp will have 8 entries instead of 5 to create a list of total length * 10). In other words, the result list will always have as many entries as the request <code>count</code>, except * when there are not as many commits on the store yet. * * @param timestamp The request timestamp around which the commits should be centered. Must not be negative. * @param count How many commits to retrieve around the request timestamp. By default, the closest * <code>count/2</code> commits will be taken on both sides of the request timestamp. Must not be * negative. * @return A list of timestamps. Never be <code>null</code>, but may be empty (if there are no commits to report). * The list is sorted in descending order. */ default List<Long> getCommitTimestampsAround(final long timestamp, final int count) { return getCommitTimestampsAround(timestamp, count, false); } /** * Returns a list of commit timestamp which are "around" the given timestamp on the time axis. * <p> * <p> * By default, this method will attempt to return the closest <code>count/2</code> commits before and after the * given timestamp. However, if there are not enough elements on either side, the other side will have more entries * in the result list (e.g. if the request count is 10 and there are only two commits before the request timestamp, * the list of commits after the request timestamp will have 8 entries instead of 5 to create a list of total length * 10). In other words, the result list will always have as many entries as the request <code>count</code>, except * when there are not as many commits on the store yet. * * @param timestamp The request timestamp around which the commits should be centered. Must not be negative. * @param count How many commits to retrieve around the request timestamp. By default, the closest * <code>count/2</code> commits will be taken on both sides of the request timestamp. Must not be * negative. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return A list of timestamps. Never be <code>null</code>, but may be empty (if there are no commits to report). * The list is sorted in descending order. */ public List<Long> getCommitTimestampsAround(final long timestamp, final int count, final boolean includeSystemInternalCommits); /** * Returns a list of commit timestamps which are strictly before the given timestamp on the time axis. * <p> * <p> * For example, calling {@link #getCommitTimestampsBefore(long, int)} with a timestamp and a count of 10, this * method will return the latest 10 commits (strictly) before the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve before the given request timestamp. Must not be negative. * @return A list of timestamps. Never be <code>null</code>, but may be empty (if there are no commits to report). * The list is sorted in descending order. */ default List<Long> getCommitTimestampsBefore(final long timestamp, final int count) { return getCommitTimestampsBefore(timestamp, count, false); } /** * Returns a list of commit timestamps which are strictly before the given timestamp on the time axis. * <p> * <p> * For example, calling {@link #getCommitTimestampsBefore(long, int)} with a timestamp and a count of 10, this * method will return the latest 10 commits (strictly) before the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve before the given request timestamp. Must not be negative. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return A list of timestamps. Never be <code>null</code>, but may be empty (if there are no commits to report). * The list is sorted in descending order. */ public List<Long> getCommitTimestampsBefore(final long timestamp, final int count, final boolean includeSystemInternalCommits); /** * Returns a list of commit timestamps which are strictly after the given timestamp on the time axis. * <p> * <p> * For example, calling {@link #getCommitTimestampsAfter(long, int)} with a timestamp and a count of 10, this method * will return the oldest 10 commits (strictly) after the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve after the given request timestamp. Must not be negative. * @return A list of timestamps. Never be <code>null</code>, but may be empty (if there are no commits to report). * The list is sorted in descending order. */ default List<Long> getCommitTimestampsAfter(final long timestamp, final int count) { return getCommitTimestampsAfter(timestamp, count, false); } /** * Returns a list of commit timestamps which are strictly after the given timestamp on the time axis. * <p> * <p> * For example, calling {@link #getCommitTimestampsAfter(long, int)} with a timestamp and a count of 10, this method * will return the oldest 10 commits (strictly) after the given request timestamp. * * @param timestamp The timestamp to investigate. Must not be negative. * @param count How many commits to retrieve after the given request timestamp. Must not be negative. * @param includeSystemInternalCommits Whether or not to include system-internal commits. * @return A list of timestamps. Never be <code>null</code>, but may be empty (if there are no commits to report). * The list is sorted in descending order. */ public List<Long> getCommitTimestampsAfter(final long timestamp, final int count, final boolean includeSystemInternalCommits); /** * Counts the number of commit timestamps between <code>from</code> (inclusive) and <code>to</code> (inclusive). * <p> * <p> * If <code>from</code> is greater than <code>to</code>, this method will always return zero. * * @param from The minimum timestamp to include in the search (inclusive). Must not be negative. Must be less than or * equal to the timestamp of this transaction. * @param to The maximum timestamp to include in the search (inclusive). Must not be negative. Must be less than or * equal to the timestamp of this transaction. * @return The number of commits that have occurred in the specified time range. May be zero, but never negative. */ default int countCommitTimestampsBetween(long from, long to) { return countCommitTimestampsBetween(from, to, false); } /** * Counts the number of commit timestamps between <code>from</code> (inclusive) and <code>to</code> (inclusive). * <p> * <p> * If <code>from</code> is greater than <code>to</code>, this method will always return zero. * * @param from The minimum timestamp to include in the search (inclusive). Must not be negative. Must be less than or * equal to the timestamp of this transaction. * @param to The maximum timestamp to include in the search (inclusive). Must not be negative. Must be less than or * equal to the timestamp of this transaction. * @param includeSystemIternalCommits Whether or not to include system-internal commits. * @return The number of commits that have occurred in the specified time range. May be zero, but never negative. */ public int countCommitTimestampsBetween(long from, long to, final boolean includeSystemIternalCommits); /** * Counts the total number of commit timestamps in the store. * * @return The total number of commits in the store. */ default int countCommitTimestamps() { return countCommitTimestamps(false); } /** * Counts the total number of commit timestamps in the store. * * @return The total number of commits in the store. * @param includeSystemInternalCommits Whether or not to include system-internal commits. */ public int countCommitTimestamps(final boolean includeSystemInternalCommits); /** * Returns an iterator over the keys in the default keyspace which changed their value at the given commit * timestamp. * * @param timestamp The commit timestamp to analyze. Must exactly match a commit timestamp in the history, otherwise the * resulting iterator will be empty. Use one of the commit timestamp retrieval methods to find the commit * timestamps (e.g. {@link #getCommitTimestampsBetween(long, long)}). Must not be negative. Must not be * larger than the timestamp of this transaction. * @return An iterator over the keys which changed in the default keyspace at the commit with the given timestamp. * Never <code>null</code>. Will be empty if there have been no changes in the default keyspace at the given * commit or if no commit has taken place at the specified timestamp. */ public Iterator<String> getChangedKeysAtCommit(long timestamp); /** * Returns an iterator over the keys in the given keyspace which changed their value at the given commit timestamp. * * @param commitTimestamp The commit timestamp to analyze. Must exactly match a commit timestamp in the history, otherwise the * resulting iterator will be empty. Use one of the commit timestamp retrieval methods to find the commit * timestamps (e.g. {@link #getCommitTimestampsBetween(long, long)}). Must not be negative. Must not be * larger than the timestamp of this transaction. * @param keyspace The keyspace to scan for changes. Must not be <code>null</code>. * @return An iterator over the keys which changed in the given keyspace at the commit with the given timestamp. * Never <code>null</code>. Will be empty if there have been no changes in the given keyspace at the given * commit, if no commit has taken place at the specified timestamp, or a keyspace with the given name did * not exist at that timestamp. */ public Iterator<String> getChangedKeysAtCommit(long commitTimestamp, String keyspace); /** * Returns the set of keyspace names currently used by the database on this branch. * * @return An unmodifiable set of keyspace names. May be empty, but never <code>null</code>. */ public Set<String> keyspaces(); /** * Returns a {@link QueryBuilderStarter} that allows for fluent design of queries. * <p> * <p> * For usage examples, please check the individual methods of the QueryBuilder. * * @return A query builder. */ public QueryBuilderStarter find(); /** * Returns a {@link QueryBuilderFinalizer} that allows to execute the given query in various ways. * <p> * <p> * Usage example: * <p> * <pre> * // prepare a query * ChronoDBQuery query = tx.find().inDefaultKeyspace().where("name").contains("Simon").toQuery(); * // this query can now be executed anywhere, even on another transaction! * Iterator&lt;Object&gt; values = tx.find(query).getValues(); * </pre> * * @param query The prebuilt query to execute. Must not be <code>null</code>. * @return A finalizer builder for the query. */ public QueryBuilderFinalizer find(ChronoDBQuery query); // ===================================================================================================================== // DATA MODIFICATION // ===================================================================================================================== /** * Sets the given key in the <i>default</i> keyspace to the given value. * <p> * <p> * Usage example: * <p> * <pre> * tx.put(&quot;Pi&quot;, 3.1415); * </pre> * <p> * Note that the {@link #get(String)} method and its overloads (as well as {@link #find()}) will <b>not</b> return * the values assigned by this method, until {@link #commit()} is called. * * @param key The key to modify. Must not be <code>null</code>. * @param value The new value to assign to the given key. Must not be <code>null</code>. */ public void put(String key, Object value); /** * Sets the given key in the <i>default</i> keyspace to the given value. * <p> * <p> * Usage example: * <p> * <pre> * tx.put(&quot;Pi&quot;, 3.1415); * </pre> * <p> * Note that the {@link #get(String)} method and its overloads (as well as {@link #find()}) will <b>not</b> return * the values assigned by this method, until {@link #commit()} is called. * * @param key The key to modify. Must not be <code>null</code>. * @param value The new value to assign to the given key. Must not be <code>null</code>. * @param options The options to apply. May be empty. */ public void put(String key, Object value, PutOption... options); /** * Sets the given key in the given keyspace to the given value. * <p> * <p> * If the keyspace with the given name does not yet exist, it will be created on-the-fly when this change is * successfully committed. * <p> * <p> * Usage example: * <p> * <pre> * tx.put(&quot;MyKeyspace&quot;, &quot;Pi&quot;, 3.1415); * </pre> * <p> * Note that the {@link #get(String)} method and its overloads (as well as {@link #find()}) will <b>not</b> return * the values assigned by this method, until {@link #commit()} is called. * * @param keyspaceName The name of the keyspace to modify. Must not be <code>null</code>. * @param key The key to modify. Must not be <code>null</code>. * @param value The new value to assign to the given key. Must not be <code>null</code>. */ public void put(String keyspaceName, String key, Object value); /** * Sets the given key in the given keyspace to the given value. * <p> * <p> * If the keyspace with the given name does not yet exist, it will be created on-the-fly when this change is * successfully committed. * <p> * <p> * Usage example: * <p> * <pre> * tx.put(&quot;MyKeyspace&quot;, &quot;Pi&quot;, 3.1415, PutOption.NONE); * </pre> * <p> * Note that the {@link #get(String)} method and its overloads (as well as {@link #find()}) will <b>not</b> return * the values assigned by this method, until {@link #commit()} is called. * * @param keyspaceName The name of the keyspace to modify. Must not be <code>null</code>. * @param key The key to modify. Must not be <code>null</code>. * @param value The new value to assign to the given key. Must not be <code>null</code>. * @param options The options to apply. May be empty. */ public void put(String keyspaceName, String key, Object value, PutOption... options); /** * Removes the given key from the <i>default</i> keyspace. * <p> * <p> * If the key given by the parameter does not exist in the keyspace, this method does nothing. * * @param key The key to remove. Must not be <code>null</code>. */ public void remove(String key); /** * Removes the given key from the given keyspace. * <p> * <p> * If the key given by the parameter does not exist in the keyspace, this method does nothing. * * @param keyspaceName The name of the keyspace to modify. Must not be <code>null</code>. * @param key The key to remove. Must not be <code>null</code>. */ public void remove(String keyspaceName, String key); // ===================================================================================================================== // TRANSACTION CONTROL // ===================================================================================================================== /** * Commits the changes made to this transaction to the {@link ChronoDB} instance. * <p> * <p> * This is an <i>atomic</i>, <i>consistent</i>, <i>isolated</i> and <i>durable</i> operation: * <ul> * <li>Either the entire change set is committed, or nothing is committed. * <li>Changes to commit will be validated against certain constraints, which may cause the commit to fail to ensure * database consistency. * <li>No other transactions will see partial results of the commit. * <li>Once this method returns successfully, the results of the commit are persisted and durable. * </ul> * <p> * <p> * After calling {@link #commit()}, the transaction will receive a new timestamp, i.e. it will be forwarded in time * to the time after the commit it just performed. Clients may continue to use transactions after calling * <code>commit()</code> on them. * * @returns the timestamp of the commit. * * @throws ChronoDBCommitException Thrown if a commit failed due to consistency violations. */ public long commit() throws ChronoDBCommitException; /** * Commits the changes made to this transaction to the {@link ChronoDB} instance. * <p> * <p> * This is an <i>atomic</i>, <i>consistent</i>, <i>isolated</i> and <i>durable</i> operation: * <ul> * <li>Either the entire change set is committed, or nothing is committed. * <li>Changes to commit will be validated against certain constraints, which may cause the commit to fail to ensure * database consistency. * <li>No other transactions will see partial results of the commit. * <li>Once this method returns successfully, the results of the commit are persisted and durable. * </ul> * <p> * <p> * After calling {@link #commit()}, the transaction will receive a new timestamp, i.e. it will be forwarded in time * to the time after the commit it just performed. Clients may continue to use transactions after calling * <code>commit()</code> on them. * * @param commitMetadata The metadata object to store alongside this commit. May be <code>null</code>. Will be serialized using * the {@link SerializationManager} associated with this {@link ChronoDB} instance. Using primitives, * collections of primitives or maps of primitives is recommended. * @returns the timestamp of the commit. * @throws ChronoDBCommitException Thrown if a commit failed due to consistency violations. */ public long commit(Object commitMetadata) throws ChronoDBCommitException; /** * Performs an incremental commit on this transaction. * <p> * <p> * Incremental commits can be used to insert large batches of data into a {@link ChronoDB} instance. Their advantage * over normal transactions is that they do not require the entire data to be contained in main memory before * writing it to the storage backend. * <p> * <p> * Recommended usage of this method: * <p> * <pre> * ChronoDBTransaction tx = db.tx(); * try { * // ... do some heavy work * tx.commitIncremental(); * // ... more work... * tx.commitIncremental(); * // ... more work... * // ... and finally, accept the changes and make them visible to others * tx.commit(); * } finally { * // make absolutely sure that the incremental process is terminated in case of error * tx.rollback(); * } * </pre> * <p> * <p> * Using an incremental commit implies all of the following facts: * <ul> * <li>Only one incremental commit process may be active on any given {@link ChronoDB} instance at any point in * time. Attempting to have multiple incremental commit processes on the same {@link ChronoDB} instance will result * in a {@link ChronoDBCommitException} on all processes, except for the first process. * <li>While an incremental commit process is active, no regular commits on other transactions can be accepted. * <li>Other transactions may continue to read data while an incremental commit process is active, but they cannot * see the changes made by incremental commits. * <li>An incremental commit process consists of several calls to {@link #commitIncremental()}, and is terminated * either by a full-fledged {@link #commit()}, or by a {@link #rollback()}. * <li>It is the responsibility of the caller to ensure that either {@link #commit()} or {@link #rollback()} are * called after the initial {@link #commitIncremental()} was called. Failure to do so will result in this * {@link ChronoDB} instance no longer accepting any commits. * <li>After the terminating {@link #commit()}, the changes will be visible to other transactions, provided that * they use an appropriate timestamp. * <li>The timestamp of all changes in an incremental commit process is the timestamp of the first * {@link #commitIncremental()} invocation. * <li>In contrast to regular transactions, several calls to {@link #commitIncremental()} may modify the same data. * Overwrites within the same incremental commit process are <b>not</b> tracked by the versioning system, and follow * the "last writer wins" principle. * <li>In the history of any given key, an incremental commit process appears as a single, large commit. In * particular, it is not possible to select a point in time where only parts of the incremental commit process were * applied. * <li>A call to {@link #commitIncremental()} does not update the {@link TemporalKeyValueStore#getNow()} timestamp. * Only the terminating call to {@link #commit()} updates this timestamp. * <li>The timestamp of the transaction executing the incremental commit will be increased after each call to * {@link #commitIncremental()} in order to allow the transaction to read the data it has written in the incremental * update. If the incremental commit process fails at any point, this timestamp will be reverted to the original * timestamp of the transaction before the incremental commit process started. * <li>Durability of the changes made by {@link #commitIncremental()} can only be guaranteed by {@link ChronoDB} if * the terminating call to {@link #commit()} is successful. Any other changes may be lost in case of errors. * <li>If the JVM process is terminated during an incremental commit process, and the terminating call to * {@link #commit()} has not yet been completed successfully, any data stored by that process will be lost and * rolled back on the next startup. * </ul> * * @throws ChronoDBCommitException Thrown if the commit fails. If this exception is thrown, the entire incremental commit process is * aborted, and any changes to the data made by that process will be rolled back. */ public void commitIncremental() throws ChronoDBCommitException; /** * Checks if this transaction is in incremental commit mode, i.e. {@link #commitIncremental()} has been called at least once. * * @return <code>true</code> if the transaction is in incremental commit mode, otherwise <code>false</code>. */ public boolean isInIncrementalCommitMode(); /** * Performs a rollback on this transaction, clearing all changes made to it. * <p> * <p> * This transaction may be used after calling rollback, in contrast to when calling {@link #commit()}. */ public void rollback(); // ===================================================================================================================== // INTERNALS // ===================================================================================================================== /** * Returns the change set that contains the pending changes which will be stored upon calling {@link #commit()}. * * @return An unmodifiable view on the change set. May be empty, but never <code>null</code>. */ public Collection<ChangeSetEntry> getChangeSet(); /** * Returns the configuration of this transaction. * * @return The transaction configuration. Never <code>null</code>. */ public Configuration getConfiguration(); /** * This interface represents the configuration of a single transaction. * <p> * <p> * Clients must not implement this interface, and must not attempt to instantiate implementing classes. Instances of * this class are forwarded to the client via {@link ChronoDBTransaction#getConfiguration()} for read-only purposes. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface Configuration { /** * Checks if this transaction is thread-safe, i.e. may be shared among multiple threads. * * @return <code>true</code> if the transaction is thread-safe, otherwise <code>false</code>. */ public boolean isThreadSafe(); /** * Returns the conflict resolution strategy to apply in case of commit conflicts. * * @return The conflict resolution strategy. Never <code>null</code>. */ public ConflictResolutionStrategy getConflictResolutionStrategy(); /** * Returns the {@link DuplicateVersionEliminationMode} associated with this transaction. * * @return The duplicate version elimination mode. Never <code>null</code>. */ public DuplicateVersionEliminationMode getDuplicateVersionEliminationMode(); /** * Checks if this transaction is read-only. * <p> * <p> * Read-only transactions throw a {@link TransactionIsReadOnlyException} if a modifying method, such as * {@link ChronoDBTransaction#put(String, Object)}, is called. * * @return <code>true</code> if this transaction is read-only, otherwise <code>false</code>. */ public boolean isReadOnly(); } }
77,042
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
BranchHeadStatistics.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/BranchHeadStatistics.java
package org.chronos.chronodb.api; import org.chronos.chronodb.internal.impl.BranchHeadStatisticsImpl; import static com.google.common.base.Preconditions.*; public interface BranchHeadStatistics { public long getTotalNumberOfEntries(); public long getNumberOfEntriesInHead(); public long getNumberOfEntriesInHistory(); public double getHeadHistoryRatio(); }
381
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
BranchManager.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/BranchManager.java
package org.chronos.chronodb.api; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Set; import static com.google.common.base.Preconditions.*; /** * The {@link BranchManager} is responsible for managing the branching functionality inside a {@link ChronoDB}. * * <p> * By default, every ChronoDB instance contains at least one branch, the master branch. Any other branches are children of the master branch. * * <p> * <b>All operations on the branch manager are considered to be management operations, and therefore are by default neither versioned nor ACID protected.</b> * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public interface BranchManager { /** * Creates a new child of the master branch with the given name. * * <p> * This will use the head revision as the base revision for the new branch. * * @param branchName The name of the new branch. Must not be <code>null</code>. Must not refer to an already existing branch. Branch names must be unique. * @return The newly created branch. Never <code>null</code>. * @see #createBranch(String, long) * @see #createBranch(String, String) * @see #createBranch(String, String, long) */ public Branch createBranch(String branchName); /** * Creates a new child of the master branch with the given name. * * @param branchName The name of the new branch. Must not be <code>null</code>. Must not refer to an already existing branch. Branch names must be unique. * @param branchingTimestamp The timestamp at which to branch away from the master branch. Must not be negative. Must be less than or equal to the timestamp of the latest commit on the master branch. * @return The newly created branch. Never <code>null</code>. * @see #createBranch(String) * @see #createBranch(String, String) * @see #createBranch(String, String, long) */ public Branch createBranch(String branchName, long branchingTimestamp); /** * Creates a new child of the given parent branch with the given name. * * <p> * This will use the head revision of the given parent branch as the base revision for the new branch. * * @param parentName The name of the parent branch. Must not be <code>null</code>. Must refer to an existing branch. * @param newBranchName The name of the new child branch. Must not be <code>null</code>. Must not refere to an already existing branch. Branch names must be unique. * @return The newly created branch. Never <code>null</code>. * @see #createBranch(String) * @see #createBranch(String, long) * @see #createBranch(String, String, long) */ public Branch createBranch(String parentName, String newBranchName); /** * Creates a new child of the given parent branch with the given name. * * @param parentName The name of the parent branch. Must not be <code>null</code>. Must refer to an existing branch. * @param newBranchName The name of the new child branch. Must not be <code>null</code>. Must not refere to an already existing branch. Branch names must be unique. * @param branchingTimestamp The timestamp at which to branch away from the parent branch. Must not be negative. Must be less than or equal to the timestamp of the latest commit on the parent branch. * @return The newly created branch. Never <code>null</code>. * @see #createBranch(String) * @see #createBranch(String, long) * @see #createBranch(String, String, long) */ public Branch createBranch(String parentName, String newBranchName, long branchingTimestamp); /** * Checks if a branch with the given name exists or not. * * @param branchName The branch name to check. Must not be <code>null</code>. * @return <code>true</code> if there is an existing branch with the given name, otherwise <code>false</code>. */ public boolean existsBranch(String branchName); /** * Returns the branch with the given name. * * @param branchName The name of the branch to retrieve. Must not be <code>null</code>. Must refer to an existing branch. * @return The branch with the given name, or <code>null</code> if there is no branch with that name. */ public Branch getBranch(String branchName); /** * Returns the master branch. * * @return The master branch. Never <code>null</code>. */ public default Branch getMasterBranch() { return this.getBranch(ChronoDBConstants.MASTER_BRANCH_IDENTIFIER); } /** * Returns the name of all existing branches. * * @return An unmodifiable view on the names of all branches. May be empty, but never <code>null</code>. */ public Set<String> getBranchNames(); /** * Returns the set of all existing branches. * * @return An unmodifiable view on the set of all branches. May be empty, but never <code>null</code>. */ public Set<Branch> getBranches(); public List<Branch> getChildBranches(Branch branch, boolean recursive); /** * Deletes the branch with the given name, and its child branches (recursively). * * <p> * <b>/!\ WARNING /!\</b><br> * This is a <i>management operation</i> which <b>should not be used</b> while the database is under * active use! The behaviour for all current and future transactions on the given branch is <b>undefined</b>! * This operation is <b>not atomic</b>: if a child branch is deleted and an error occurs, the parent branch may still continue to exist. * Child branches are deleted before parent branches. * </p> * * @param branchName The name of the branch to delete. Must not be <code>null</code>. The {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch cannot be deleted! * @return The list of branch names which have been deleted by this operation. May be empty, but never <code>null</code>. */ public List<String> deleteBranchRecursively(String branchName); /** * Gets the actual branch which is referred to by the given coordinates. * * <p> * If a query is executed on a (non-master) branch, and the query timestamp is * before the branching timestamp, the actual branch that is being queried is * the parent branch (maybe recursively). * </p> * * @param branchName The name of the target branch. Must refer to an existing branch. Must not be <code>null</code>. * @param timestamp The timestamp to resolve. Must not be negative. * @return The actual branch which will be affected by the query. This branch may either be the same as, * or a direct or indirect parent of the given branch */ public Branch getActualBranchForQuerying(@NotNull final String branchName, final long timestamp); /** * Gets the actual branch which is referred to by the given coordinates. * * <p> * If a query is executed on a (non-master) branch, and the query timestamp is * before the branching timestamp, the actual branch that is being queried is * the parent branch (maybe recursively). * </p> * * @param branch The target branch. Must not be <code>null</code>. * @param timestamp The timestamp to resolve. Must not be negative. * @return The actual branch which will be affected by the query. This branch may either be the same as, * or a direct or indirect parent of the given branch */ public default Branch getActualBranchForQuerying(@NotNull final Branch branch, final long timestamp) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); return this.getActualBranchForQuerying(branch.getName(), timestamp); } }
7,990
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
Order.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/Order.java
package org.chronos.chronodb.api; /** * A general multi-purpose enumeration for any kind of ordering. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public enum Order { /** Represents ascending order, i.e. when iterating, every entry will be larger than the previous one. */ ASCENDING, /** Represents descending order, i.e. when iterating, every entry will be smaller than the previous one. */ DESCENDING }
446
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
Branch.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/Branch.java
package org.chronos.chronodb.api; import java.util.List; import org.chronos.chronodb.internal.impl.IBranchMetadata; /** * A {@link Branch} represents a single stream of changes in the versioning system. * * <p> * Branches work much like in document versioning systems, such as GIT or SVN. Every branch has an "{@linkplain #getOrigin() origin}" (or "parent") branch from which it was created, as well as a "{@linkplain #getBranchingTimestamp() branching timestamp}" that reflects the point in time from which this branch was created. There is one special branch, which is the {@linkplain ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master branch}. It is the transitive origin of all other branches. It always has the same name, an origin of <code>null</code>, and a branching timestamp of zero. Unlike other branches, the master branch is created by default and always exists. * * <p> * All branches are uniquely identified by their name. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface Branch { /** * Returns the name of this branch, which also acts as its unique identifier. * * @return The branch name. Never <code>null</code>. Branch names are unique. */ public String getName(); /** * Returns the branch from which this branch originates. * * @return The origin (parent) branch. May be <code>null</code> if this branch is the master branch. */ public Branch getOrigin(); /** * Returns the timestamp at which this branch was created from the origin (parent) branch. * * @return The branching timestamp. Never negative. */ public long getBranchingTimestamp(); /** * Returns the list of direct and transitive origin branches. * * <p> * The first entry in the list will always be the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. The remaining entries are the descendants of the previous branch in the list which are also direct or transitive origins of the current branch. * * <p> * For example, if there were the following branching actions: * <ol> * <li>master is forked into new branch A * <li>A is forked into new branch B * <li>B is forked into new branch C * </ol> * * ... and <code>C.getOriginsRecursive()</code> is invoked, then the returned list will consist of <code>[master, A, B]</code> (in exactly this order). * * @return The list of origin branches. Will be empty for the master branch, and will start with the master branch for all other branches. Never <code>null</code>. The returned list is a calculated object which may freely be modified without changing any internal state. */ public List<Branch> getOriginsRecursive(); /** * Returns the "now" timestamp on this branch, i.e. the timestamp at which the last full commit was successfully executed. * * @return The "now" timestamp. The minimum is the branching timestamp (or zero for the master branch). Never negative. */ public long getNow(); /** * Returns the name of the directory where this branch is stored. * * <p> * For backends that are not file based, this value may be <code>null</code>. * * @return The name of the directory where this branch is located. May be <code>null</code> if this ChronoDB instance is using a backend that is not file-based. */ public String getDirectoryName(); /** * Returns the immutable metadata of this branch. * * @return The metadata object. Never <code>null</code> * * @since 0.6.0 */ public IBranchMetadata getMetadata(); /** * Checks if this branch is the master branch. * * @return <code>true</code> if this is the master branch, otherwise <code>false</code>. */ public default boolean isMaster(){ return ChronoDBConstants.MASTER_BRANCH_IDENTIFIER.equals(this.getName()); } }
3,797
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBStatistics.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/ChronoDBStatistics.java
package org.chronos.chronodb.api; import java.util.Set; public interface ChronoDBStatistics { // ================================================================================================================= // BRANCHING DATA // ================================================================================================================= /** * Returns an immutable set, containing all branch names. * * @return The immutable set of all branch names. Never <code>null</code>. Will always at least contain the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. */ public Set<String> getBranchNames(); /** * Returns the immutable set of known keyspace names in the given branch. * * @param branchName * The name of the branch to retrieve the keyspaces for. Must not be <code>null</code>. * @return The immutable set of known keyspace names in the given branch. May be empty, but never <code>null</code>. Is guaranteed to be empty for non-existing branches. */ public Set<String> getKeyspacesInBranch(String branchName); /** * Returns the number of branches. * * @return The number of branches. Guaranteed to be greater than or equal to one (the master branch). */ public int getNumberOfBranches(); /** * Returns the maximum branching depth in the database. * * <p> * A branch B1 that has {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} as origin has branching depth 1. A branch B2 that has B1 as origin has branching depth 2, etc. The master branch has branching depth zero by definition. * * @return The maximum branching depth. Always greater than or equal to zero. * * @see #getAverageBranchingDepth() */ public int getMaximumBranchingDepth(); /** * Returns the average branching depth. * * For a definition of "branching depth", please see {@link #getMaximumBranchingDepth()}. * * @return The average branching depth over all non-master branches. Will be zero if there are no branches other than the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master}, or a value greater than or equal to one if there is at least one branch. */ public double getAverageBranchingDepth(); // ================================================================================================================= // CHUNK DATA // ================================================================================================================= /** * Returns the number of chunks in the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. * * <p> * For all backends that do not support chunks, this method will return 1. * * @return the number of chunks in the {@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch. Guaranteed to be greater than or equal to 1. */ public int getMasterBranchChunks(); /** * Returns the number of chunks in the given branch. * * <p> * For all backends that do not support chunks, this method will return 1 for all existing branches. * * @param branchName * the name of the branch to fetch the chunk count for. Must not be <code>null</code>. * @return A value greater than or equal to 1 representing the number of chunks, if the given branch exists; otherwise zero. */ public int getNumberOfChunksInBranch(String branchName); /** * Returns the average number of chunks in all branches ({@link ChronoDBConstants#MASTER_BRANCH_IDENTIFIER master} branch). * * @return The average number of chunks. Will be zero for backends that do not support chunks, or if there are no other branches. Will be a value greater than or equal to 1 in all other cases. */ public double getAverageNumberOfChunksPerNonMasterBranch(); // ================================================================================================================= // ACCESS PATTERNS // ================================================================================================================= /** * Returns the number of {@link ChronoDBTransaction#get(String)} operations executed on this database so far. * * @return The number of <code>get</code> operations. Never negative. */ public long getTotalNumberOfGetOperations(); /** * Returns the number of {@link ChronoDBTransaction#put(String, Object)} operations executed on this database so far. * * @return The number of <code>put</code> operations. Never negative. */ public long getTotalNumberOfPutOperations(); /** * Returns the number of {@link ChronoDBTransaction#remove(String)} operations executed on this database so far. * * @return The number of <code>remove</code> operations. Never negative. */ public long getTotalNumberOfRemoveOperations(); /** * Returns the number of {@link ChronoDBTransaction#get(String)} operations executed on this database within the given time range since the head revision. * * <p> * Examples include: * * <pre> * statistics.getNumberOfOperationsWithin(HeadMinus.TEN_SECONDS); // #1 * statistics.getNumberOfOperationsWithin(HeadMinus.ONE_HOUR); // #2 * </pre> * * <p> * It is important to note that a <code>get</code> operation that belongs to the {@link HeadMinus#ONE_MINUTE} group will not be counted for the {@link HeadMinus#FIVE_MINUTES} group. Each <code>get</code> belongs to at most one time group. * * @param headMinus * The time distance between the <code>get</code> call timestamp and the head revision timestamp. * * @return The number of <code>get</code> operations within the given time delta since the head revision. Never negative. * * @see #getNumberOfGetOperationsInOlderHistory() */ public long getNumberOfGetOperationsWithin(HeadMinus headMinus); /** * Returns the number of {@link ChronoDBTransaction#get(String)} operations executed on timestamps not retrievable via {@link #getNumberOfGetOperationsWithin(HeadMinus)}. * * @return The number of <code>get</code> operations executed on older history. Never negative. */ public long getNumberOfGetOperationsInOlderHistory(); /** * Returns the number of {@link ChronoDBTransaction#get(String)} operations executed on the given branch. * * @param branchName * The branch to retrieve the number of executed <code>get</code> operations for. Must not be <code>null</code>. * * @return The number of <code>get</code> operations on the given branch. May be zero. Will be zero for any non-existing branch. */ public long getNumberOfGetOperationsOnBranch(String branchName); /** * Returns the number of {@link ChronoDBTransaction#put(String, Object)} operations executed on the given branch. * * @param branchName * The branch to retrieve the number of executed <code>put</code> operations for. Must not be <code>null</code>. * * @return The number of <code>put</code> operations on the given branch. May be zero. Will be zero for any non-existing branch. */ public long getNumberOfPutOperationsOnBranch(String branchName); /** * Returns the number of {@link ChronoDBTransaction#remove(String)} operations executed on the given branch. * * @param branchName * The branch to retrieve the number of executed <code>remove</code> operations for. Must not be <code>null</code>. * * @return The number of <code>remove</code> operations on the given branch. May be zero. Will be zero for any non-existing branch. */ public long getNumberOfRemoveOperationsOnBranch(String branchName); // ================================================================================================================= // CACHING // ================================================================================================================= /** * Returns the total number of entry cache misses, i.e. {@link ChronoDBTransaction#get(String)} calls that were not answered by the cache. * * @return The number of entry cache misses. Will be fixed at -1 if entry caching is disabled. * * @see #getNumberOfEntryCacheHits() * @see #getNumberOfQueryCacheHits() * @see #getNumberOfQueryCacheMisses() */ public long getNumberOfEntryCacheHits(); /** * Returns the total number entry cache hits, i.e. {@link ChronoDBTransaction#get(String)} calls that were answered by the cache. * * @return The number of entry cache hits. Will be fixed at -1 if entry caching is disabled. * * @see #getNumberOfEntryCacheMisses() * @see #getNumberOfQueryCacheHits() * @see #getNumberOfQueryCacheMisses() */ public long getNumberOfEntryCacheMisses(); /** * Returns the total number of query cache hits. * * @return The number of query cache hits. Will be fixed at -1 if query caching is disabled. */ public long getNumberOfQueryCacheHits(); /** * Returns the total number of query cache misses. * * @return The number of query cache misses. Will be fixed at -1 if query caching is disabled. */ public long getNumberOfQueryCacheMisses(); // ================================================================================================================= // INDEXING // ================================================================================================================= /** * Returns the immutable set of active secondary index names. * * @return The immutable set of secondary index names. Never <code>null</code>, may be empty. */ public Set<String> getActiveSecondaryIndices(); /** * Returns the total number of index documents that constitute the secondary index. * * @return The total number of index documents. Always greater than or equal to zero. */ public long getNumberOfIndexDocuments(); // ================================================================================================================= // RESOURCE USAGE // ================================================================================================================= /** * Estimates the footprint of this database instance on disk (in bytes). * * @return The estimated footprint of this database on disk, in bytes. */ public long getDiskFootprintInBytes(); // ================================================================================================================= // INNER CLASSES // ================================================================================================================= public static enum HeadMinus { ONE_SECOND, FIVE_SECONDS, TEN_SECONDS, THIRTY_SECONDS, ONE_MINUTE, FIVE_MINUTES, TEN_MINUTES, THIRTY_MINUTES, ONE_HOUR, TWO_HOURS, THREE_HOURS } }
10,580
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
PutOption.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/PutOption.java
package org.chronos.chronodb.api; /** * Put options are advanced options that can be set per {@link ChronoDBTransaction#put(String, Object, PutOption...)} command. * * <p> * Normal users should not have to concern themselves with these options. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public enum PutOption { /** * [ADVANCED USERS ONLY] This option tells {@link ChronoDB} to skip the secondary indexing step for this value. * * <p> * This can potentially break your secondary index and make it inconsistent! Use this option only as a performance optimization when you are <b>sure</b> that this put operation <b>would not have altered</b> the state of the secondary indexer. */ NO_INDEX; /** The default option to use. */ public static final PutOption[] NONE = {}; }
827
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DumpOption.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/DumpOption.java
package org.chronos.chronodb.api; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.api.dump.ChronoConverter; import org.chronos.chronodb.api.dump.ChronoDBDumpFormat.Alias; import org.chronos.chronodb.api.dump.annotations.ChronosExternalizable; /** * This class acts as a factory for options for {@link ChronoDB#writeDump(java.io.File, DumpOption...)}. * * <p> * Some options (that don't need parameters) can be accessed via constants, others are produced via static factory methods. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public abstract class DumpOption { // ===================================================================================================================== // USER OPTIONS // ===================================================================================================================== /** Enforces binary encoding for DB entry content. Does not apply to metadata. */ public static final DumpOption FORCE_BINARY_ENCODING = new FlagOption("forceBinaryEncoding"); /** * Enables G-Zipping of the output file to preserve space on disk. * * <p> * Unzipping the file will yield the internal plain text. */ public static final DumpOption ENABLE_GZIP = new FlagOption("enableGZip"); /** * Creates an alias for the given class in the output format. * * <p> * Please note that this is a <b>HINT</b> for the output writer and input reader. It may or may not affect all occurrences. * * <p> * <b>/!\ WARNING /!\</b><br> * You <b>must</b> use the <b>same set of aliases</b> when reading a dump as you used when writing it, otherwise the dump will not be readable! Also, alias names <b>must not clash</b> and <b>must be unique</b>! * * <p> * This has several uses: * <ul> * <li>It reduces the overall length of the dump by using shorter class names * <li>It improves the human-readability of the dump * <li>It makes the dump more resilient against package name changes (or classes moving to other packages) * </ul> * * @param clazz * The class to create the alias for. Must not be <code>null</code>. * @param alias * The alias to give to the class. must not be <code>null</code>. * @return The alias option. Never <code>null</code>. */ public static DumpOption aliasHint(final Class<?> clazz, final String alias) { checkNotNull(clazz, "Precondition violation - argument 'clazz' must not be NULL!"); checkNotNull(alias, "Precondition violation - argument 'alias' must not be NULL!"); return new AliasOption(clazz, alias); } /** * Registers a default converter for a given class. * * <p> * Please note that which class to use as the first argument depends on the use case: * <ul> * <li>When writing a dump, <code>type</code> must be the internal class (i.e. the parameter type of the {@link ChronoConverter#writeToOutput(Object) writeToOutput} method). * <li>When reading a dump, <code>type</code> must be the serialized class (i.e. the parameter type of the {@link ChronoConverter#readFromInput(Object) readFromInput} method). * </ul> * * <p> * Example: * * <pre> * * // we have a converter class like this (converts Person <-> PersonExt): * public class PersonConverter implements ChronoConverter&lt;Person, PersonExt&gt; {...} * * // we write a dump using: * DumpOption.defaultConverter(Person.class, new PersonConverter()); * // this will create a dump that contains no Person instances, but PersonExt instances. * * // ... if we want to read that dump, we use: * DumpOption.defaultConverter(PersonExt.class, new PersonConverter()); * // this will find all PersonExt instances in the dump, and convert them to Person instances again. * * </pre> * * <p> * As a general rule, a {@link ChronosExternalizable} annotation on a value class will override the default converter if specified, unless they are equal, in which case the default converter takes precedence. When writing a dump using default converters, the used converters will <b>not</b> be part of the output. * * <p> * <b>/!\ WARNING /!\</b><br> * You <b>must</b> use the <b>same set of default converters</b> when reading a dump as you used when writing it, otherwise the dump will not be readable! * * @param type * The class to associate the converter with. Must not be <code>null</code>. * @param converter * The converter to use for instances of the model class. Must not be <code>null</code>. * @return The option that adds the given default converter. Never <code>null</code>. */ public static DumpOption defaultConverter(final Class<?> type, final ChronoConverter<?, ?> converter) { checkNotNull(type, "Precondition violation - argument 'type' must not be NULL!"); checkNotNull(converter, "Precondition violation - argument 'converter' must not be NULL!"); return new DefaultConverterOption(type, converter); } /** * Sets the batch size to use when reading elements from a dump. * * <p> * Higher batch sizes consume more RAM, but are in general faster. Sensible values usually range from 1000 to 10000. * * @param batchSize * The batch size to use. Must be greater than or equal to 1. * @return The option that sets the batch size. Never <code>null</code>. */ public static DumpOption batchSize(final int batchSize) { checkArgument(batchSize > 0, "Precondition violation - argument 'batchSize' must be strictly greater than zero!"); return new IntOption("batchSize", batchSize); } // ===================================================================================================================== // INNER CLASSES // ===================================================================================================================== /** * A {@link FlagOption} is the simplest kind of option. It has a name, and is either present or absent. * * <p> * Flag options are uniquely identified by their name. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ private static class FlagOption extends DumpOption { /** The name of the flag. */ private String name; /** * Constructs a new flag option. * * @param name * The name for the flag. Must not be <code>null</code>. */ private FlagOption(final String name) { checkNotNull(name, "Precondition violation - argument 'name' must not be NULL!"); this.name = name; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (this.name == null ? 0 : this.name.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } FlagOption other = (FlagOption) obj; if (this.name == null) { if (other.name != null) { return false; } } else if (!this.name.equals(other.name)) { return false; } return true; } @Override public String toString() { return "FlagOption [name=" + this.name + "]"; } } /** * An {@link AliasOption} allows to register alternative (usually shorter) names for classes that appear in a dump. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public static class AliasOption extends DumpOption { /** The alias that is added by this option. */ private Alias alias; /** * Creates a new alias option. * * @param clazz * The Java {@link Class} to define the alias for. Must not be <code>null</code>. * @param name * The alias name to use for the class. Must not be <code>null</code>. */ public AliasOption(final Class<?> clazz, final String name) { this.alias = new Alias(clazz, name); } /** * Returns the alias that is provided by this option. * * @return The alias. Never <code>null</code>. */ public Alias getAlias() { return this.alias; } @Override public String toString() { return "AliasOption [alias=" + this.alias + "]"; } } /** * This option allows to add default {@link ChronoConverter}s to a dump process. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public static class DefaultConverterOption extends DumpOption { /** The type to be converted. */ private final Class<?> type; /** The converter to be applied to the {@link #type}. */ private final ChronoConverter<?, ?> converter; /** * Creates a new Default Converter Option. * * @param type * The Java {@link Class} that should be converted. Must not be <code>null</code>. * @param converter * The converter to apply to instances of the given class. Must not be <code>null</code>. */ public DefaultConverterOption(final Class<?> type, final ChronoConverter<?, ?> converter) { checkNotNull(type, "Precondition violation - argument 'type' must not be NULL!"); checkNotNull(converter, "Precondition violation - argument 'converter' must not be NULL!"); this.type = type; this.converter = converter; } /** * Returns the Java {@link Class} that should be converted. * * @return The class. Never <code>null</code>. */ public Class<?> getType() { return this.type; } /** * Returns the converter to be applied to instances of the {@link #getType() class}. * * @return The converter. Never <code>null</code>. */ public ChronoConverter<?, ?> getConverter() { return this.converter; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (this.converter == null ? 0 : this.converter.hashCode()); result = prime * result + (this.type == null ? 0 : this.type.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } DefaultConverterOption other = (DefaultConverterOption) obj; if (this.converter == null) { if (other.converter != null) { return false; } } else if (!this.converter.equals(other.converter)) { return false; } if (this.type == null) { if (other.type != null) { return false; } } else if (!this.type.equals(other.type)) { return false; } return true; } } /** * An {@link IntOption} is a named container for an integer value. * * <p> * IntOptions are uniquely identified by their name. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public static class IntOption extends DumpOption { /** The name of this option. */ private final String name; /** The integer value associated with this option. */ private final int value; /** * Constructs a new IntOption. * * @param name * The name to use for the option. Must not be <code>null</code>. * @param value * The value to use for the option. Must not be <code>null</code>. */ public IntOption(final String name, final int value) { checkNotNull(name, "Precondition violation - argument 'name' must not be NULL!"); this.name = name; this.value = value; } /** * Returns the name of this option. * * @return The name. Never <code>null</code>. */ public String getName() { return this.name; } /** * Returns the integer value associated with this option. * * @return The integer value. */ public int getValue() { return this.value; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (this.name == null ? 0 : this.name.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } IntOption other = (IntOption) obj; if (this.name == null) { if (other.name != null) { return false; } } else if (!this.name.equals(other.name)) { return false; } return true; } } }
12,357
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
InvalidTransactionBranchException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/InvalidTransactionBranchException.java
package org.chronos.chronodb.api.exceptions; public class InvalidTransactionBranchException extends ChronoDBTransactionException { public InvalidTransactionBranchException() { super(); } public InvalidTransactionBranchException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public InvalidTransactionBranchException(final String message, final Throwable cause) { super(message, cause); } public InvalidTransactionBranchException(final String message) { super(message); } public InvalidTransactionBranchException(final Throwable cause) { super(cause); } }
716
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
CacheGetResultNotPresentException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/CacheGetResultNotPresentException.java
package org.chronos.chronodb.api.exceptions; public class CacheGetResultNotPresentException extends ChronoDBException { public CacheGetResultNotPresentException() { super(); } protected CacheGetResultNotPresentException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public CacheGetResultNotPresentException(final String message, final Throwable cause) { super(message, cause); } public CacheGetResultNotPresentException(final String message) { super(message); } public CacheGetResultNotPresentException(final Throwable cause) { super(cause); } }
708
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
InvalidTransactionTimestampException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/InvalidTransactionTimestampException.java
package org.chronos.chronodb.api.exceptions; public class InvalidTransactionTimestampException extends ChronoDBTransactionException { public InvalidTransactionTimestampException() { super(); } public InvalidTransactionTimestampException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public InvalidTransactionTimestampException(final String message, final Throwable cause) { super(message, cause); } public InvalidTransactionTimestampException(final String message) { super(message); } public InvalidTransactionTimestampException(final Throwable cause) { super(cause); } }
734
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBStorageBackendException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBStorageBackendException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBStorageBackendException extends ChronoDBException { public ChronoDBStorageBackendException() { super(); } public ChronoDBStorageBackendException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBStorageBackendException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBStorageBackendException(final String message) { super(message); } public ChronoDBStorageBackendException(final Throwable cause) { super(cause); } }
693
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IndexerConflictException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/IndexerConflictException.java
package org.chronos.chronodb.api.exceptions; public class IndexerConflictException extends ChronoDBIndexingException { public IndexerConflictException() { super(); } protected IndexerConflictException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public IndexerConflictException(final String message, final Throwable cause) { super(message, cause); } public IndexerConflictException(final String message) { super(message); } public IndexerConflictException(final Throwable cause) { super(cause); } }
662
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
JdbcTableException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/JdbcTableException.java
package org.chronos.chronodb.api.exceptions; public class JdbcTableException extends RuntimeException { public JdbcTableException() { super(); } public JdbcTableException(final String message) { super(message); } public JdbcTableException(final Throwable cause) { super(cause); } public JdbcTableException(final String message, final Throwable cause) { super(message, cause); } protected JdbcTableException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } }
617
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBCommitConflictException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBCommitConflictException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBCommitConflictException extends ChronoDBCommitException { public ChronoDBCommitConflictException() { super(); } protected ChronoDBCommitConflictException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBCommitConflictException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBCommitConflictException(final String message) { super(message); } public ChronoDBCommitConflictException(final Throwable cause) { super(cause); } }
702
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBSerializationException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBSerializationException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBSerializationException extends ChronoDBException { public ChronoDBSerializationException() { super(); } public ChronoDBSerializationException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBSerializationException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBSerializationException(final String message) { super(message); } public ChronoDBSerializationException(final Throwable cause) { super(cause); } }
687
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBTransactionException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBTransactionException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBTransactionException extends ChronoDBException { public ChronoDBTransactionException() { super(); } public ChronoDBTransactionException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBTransactionException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBTransactionException(final String message) { super(message); } public ChronoDBTransactionException(final Throwable cause) { super(cause); } }
675
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBQuerySyntaxException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBQuerySyntaxException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBQuerySyntaxException extends ChronoDBException { public ChronoDBQuerySyntaxException() { super(); } protected ChronoDBQuerySyntaxException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBQuerySyntaxException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBQuerySyntaxException(final String message) { super(message); } public ChronoDBQuerySyntaxException(final Throwable cause) { super(cause); } }
678
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBException.java
package org.chronos.chronodb.api.exceptions; import org.chronos.common.exceptions.ChronosException; public class ChronoDBException extends ChronosException { public ChronoDBException() { super(); } protected ChronoDBException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBException(final String message) { super(message); } public ChronoDBException(final Throwable cause) { super(cause); } }
667
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
InvalidIndexAccessException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/InvalidIndexAccessException.java
package org.chronos.chronodb.api.exceptions; public class InvalidIndexAccessException extends ChronoDBIndexingException { public InvalidIndexAccessException() { super(); } protected InvalidIndexAccessException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public InvalidIndexAccessException(final String message, final Throwable cause) { super(message, cause); } public InvalidIndexAccessException(final String message) { super(message); } public InvalidIndexAccessException(final Throwable cause) { super(cause); } }
677
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBBranchingException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBBranchingException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBBranchingException extends ChronoDBException { public ChronoDBBranchingException() { super(); } public ChronoDBBranchingException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBBranchingException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBBranchingException(final String message) { super(message); } public ChronoDBBranchingException(final Throwable cause) { super(cause); } }
663
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBCommitException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBCommitException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBCommitException extends ChronoDBTransactionException { public ChronoDBCommitException() { super(); } public ChronoDBCommitException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBCommitException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBCommitException(final String message) { super(message); } public ChronoDBCommitException(final Throwable cause) { super(cause); } }
656
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronosBuildVersionConflictException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronosBuildVersionConflictException.java
package org.chronos.chronodb.api.exceptions; import org.chronos.common.exceptions.ChronosException; public class ChronosBuildVersionConflictException extends ChronosException { public ChronosBuildVersionConflictException() { super(); } protected ChronosBuildVersionConflictException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronosBuildVersionConflictException(final String message, final Throwable cause) { super(message, cause); } public ChronosBuildVersionConflictException(final String message) { super(message); } public ChronosBuildVersionConflictException(final Throwable cause) { super(cause); } }
781
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
UnknownIndexException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/UnknownIndexException.java
package org.chronos.chronodb.api.exceptions; public class UnknownIndexException extends ChronoDBIndexingException { public UnknownIndexException() { super(); } protected UnknownIndexException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public UnknownIndexException(final String message, final Throwable cause) { super(message, cause); } public UnknownIndexException(final String message) { super(message); } public UnknownIndexException(final Throwable cause) { super(cause); } }
644
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
UnknownKeyspaceException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/UnknownKeyspaceException.java
package org.chronos.chronodb.api.exceptions; public class UnknownKeyspaceException extends ChronoDBException { public UnknownKeyspaceException() { super(); } public UnknownKeyspaceException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public UnknownKeyspaceException(final String message, final Throwable cause) { super(message, cause); } public UnknownKeyspaceException(final String message) { super(message); } public UnknownKeyspaceException(final Throwable cause) { super(cause); } }
651
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBIndexingException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBIndexingException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBIndexingException extends ChronoDBException { public ChronoDBIndexingException() { super(); } protected ChronoDBIndexingException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBIndexingException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBIndexingException(final String message) { super(message); } public ChronoDBIndexingException(final Throwable cause) { super(cause); } }
660
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBBackupException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBBackupException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBBackupException extends ChronoDBException { public ChronoDBBackupException() { } protected ChronoDBBackupException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBBackupException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBBackupException(final String message) { super(message); } public ChronoDBBackupException(final Throwable cause) { super(cause); } }
686
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
TransactionIsReadOnlyException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/TransactionIsReadOnlyException.java
package org.chronos.chronodb.api.exceptions; public class TransactionIsReadOnlyException extends ChronoDBTransactionException { public TransactionIsReadOnlyException() { super(); } protected TransactionIsReadOnlyException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public TransactionIsReadOnlyException(final String message, final Throwable cause) { super(message, cause); } public TransactionIsReadOnlyException(final String message) { super(message); } public TransactionIsReadOnlyException(final Throwable cause) { super(cause); } }
701
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ValueTypeMismatchException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ValueTypeMismatchException.java
package org.chronos.chronodb.api.exceptions; public class ValueTypeMismatchException extends ChronoDBSerializationException { public ValueTypeMismatchException() { super(); } public ValueTypeMismatchException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ValueTypeMismatchException(final String message, final Throwable cause) { super(message, cause); } public ValueTypeMismatchException(final String message) { super(message); } public ValueTypeMismatchException(final Throwable cause) { super(cause); } }
676
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
DatebackException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/DatebackException.java
package org.chronos.chronodb.api.exceptions; public class DatebackException extends ChronoDBException { public DatebackException() { super(); } protected DatebackException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public DatebackException(final String message, final Throwable cause) { super(message, cause); } public DatebackException(final String message) { super(message); } public DatebackException(final Throwable cause) { super(cause); } }
612
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoTransactionClosedException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoTransactionClosedException.java
package org.chronos.chronodb.api.exceptions; public class ChronoTransactionClosedException extends ChronoDBTransactionException { public ChronoTransactionClosedException() { super(); } public ChronoTransactionClosedException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoTransactionClosedException(final String message, final Throwable cause) { super(message, cause); } public ChronoTransactionClosedException(final String message) { super(message); } public ChronoTransactionClosedException(final Throwable cause) { super(cause); } }
710
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBCommitMetadataRejectedException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBCommitMetadataRejectedException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBCommitMetadataRejectedException extends ChronoDBCommitException { public ChronoDBCommitMetadataRejectedException() { } protected ChronoDBCommitMetadataRejectedException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBCommitMetadataRejectedException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBCommitMetadataRejectedException(final String message) { super(message); } public ChronoDBCommitMetadataRejectedException(final Throwable cause) { super(cause); } }
790
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBConfigurationException.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/exceptions/ChronoDBConfigurationException.java
package org.chronos.chronodb.api.exceptions; public class ChronoDBConfigurationException extends ChronoDBException { public ChronoDBConfigurationException() { super(); } public ChronoDBConfigurationException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } public ChronoDBConfigurationException(final String message, final Throwable cause) { super(message, cause); } public ChronoDBConfigurationException(final String message) { super(message); } public ChronoDBConfigurationException(final Throwable cause) { super(cause); } }
687
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IncrementalBackupResult.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/dump/IncrementalBackupResult.java
package org.chronos.chronodb.api.dump; import java.io.File; import static com.google.common.base.Preconditions.*; public class IncrementalBackupResult { private File cibFile; private IncrementalBackupInfo metadata; public IncrementalBackupResult(File cibFile, IncrementalBackupInfo metadata){ checkNotNull(cibFile, "Precondition violation - argument 'cibFile' must not be NULL!"); checkNotNull(metadata, "Precondition violation - argument 'metadata' must not be NULL!"); this.cibFile = cibFile; this.metadata = metadata; } public File getCibFile() { return cibFile; } public IncrementalBackupInfo getMetadata() { return metadata; } }
721
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
IncrementalBackupInfo.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/dump/IncrementalBackupInfo.java
package org.chronos.chronodb.api.dump; import org.chronos.common.version.ChronosVersion; import static com.google.common.base.Preconditions.*; public class IncrementalBackupInfo { private ChronosVersion chronosVersion; private long dumpFormatVersion; private long requestStartTimestamp; private long previousRequestWallClockTime; private long now; private long wallClockTime; public IncrementalBackupInfo(final ChronosVersion chronosVersion, final int dumpFormatVersion, final long requestStartTimestamp, final long previousRequestWallClockTime, final long now, final long wallClockTime) { checkNotNull(chronosVersion, "Precondition violation - argument 'chronosVersion' must not be NULL!"); checkArgument(requestStartTimestamp <= now, "Precondition violation - argument 'requestStartTimestamp' must be less than 'now'!"); checkArgument(previousRequestWallClockTime <= wallClockTime, "Precondition violation - argument 'previousRequestWallClockTime' must be less than 'wallClockTime'!"); this.chronosVersion = chronosVersion; this.dumpFormatVersion = dumpFormatVersion; this.requestStartTimestamp = requestStartTimestamp; this.previousRequestWallClockTime = previousRequestWallClockTime; this.now = now; this.wallClockTime = wallClockTime; } public ChronosVersion getChronosVersion() { return chronosVersion; } public long getDumpFormatVersion() { return dumpFormatVersion; } public long getRequestStartTimestamp() { return requestStartTimestamp; } public long getPreviousRequestWallClockTime() { return previousRequestWallClockTime; } public long getNow() { return now; } public long getWallClockTime() { return wallClockTime; } }
1,843
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoDBDumpFormat.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/dump/ChronoDBDumpFormat.java
package org.chronos.chronodb.api.dump; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider; import com.thoughtworks.xstream.security.AnyTypePermission; import org.apache.commons.io.IOUtils; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.api.DumpOption; import org.chronos.chronodb.api.exceptions.ChronoDBStorageBackendException; import org.chronos.chronodb.api.key.ChronoIdentifier; import org.chronos.chronodb.internal.api.stream.ObjectInput; import org.chronos.chronodb.internal.api.stream.ObjectOutput; import org.chronos.chronodb.internal.impl.dump.DumpOptions; import org.chronos.chronodb.internal.impl.dump.entry.ChronoDBDumpBinaryEntry; import org.chronos.chronodb.internal.impl.dump.entry.ChronoDBDumpPlainEntry; import org.chronos.chronodb.internal.impl.dump.meta.BranchDumpMetadata; import org.chronos.chronodb.internal.impl.dump.meta.ChronoDBDumpMetadata; import org.chronos.chronodb.internal.impl.dump.meta.IndexerDumpMetadata; import org.chronos.chronodb.internal.impl.temporal.ChronoIdentifierImpl; import org.chronos.chronodb.internal.util.ChronosFileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.nio.file.Files; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import static com.google.common.base.Preconditions.*; /** * This class describes the file format for {@link ChronoDB#writeDump(File, DumpOption...) DB dumps}. * * <p> * This class serves two major purposes: * <ul> * <li>Offering constants and a default configuration for the file format * <li>Creating {@link ObjectInput input} and {@link ObjectOutput output} streams * </ul> * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public class ChronoDBDumpFormat { private static final Logger log = LoggerFactory.getLogger(ChronoDBDumpFormat.class); /** * The default alias name for the {@link ChronoDBDumpMetadata} class. */ public static final String ALIAS_NAME__CHRONODB_METADATA = "dbmetadata"; /** * The default alias name for the {@link ChronoDBDumpPlainEntry} class. */ public static final String ALIAS_NAME__CHRONODB_PLAIN_ENTRY = "dbentryPlain"; /** * The default alias name for the {@link ChronoDBDumpBinaryEntry} class. */ public static final String ALIAS_NAME__CHRONODB_BINARY_ENTRY = "dbentryBinary"; /** * The default alias name for the {@link ChronoIdentifier} class. */ public static final String ALIAS_NAME__CHRONO_IDENTIFIER = "chronoIdentifier"; /** * The default alias name for the {@link BranchDumpMetadata} class. */ public static final String ALIAS_NAME__BRANCH_DUMP_METADATA = "branch"; /** * The default alias name for the {@link IndexerDumpMetadata} class. */ public static final String ALIAS_NAME__INDEXER_DUMP_METADATA = "indexer"; /** * The default alias definition for the {@link ChronoDBDumpMetadata} class. */ public static final Alias ALIAS__CHRONODB_METADATA = new Alias(ChronoDBDumpMetadata.class, ALIAS_NAME__CHRONODB_METADATA); /** * The default alias definition for the {@link ChronoDBDumpPlainEntry} class. */ public static final Alias ALIAS__CHRONODB_PLAIN_ENTRY = new Alias(ChronoDBDumpPlainEntry.class, ALIAS_NAME__CHRONODB_PLAIN_ENTRY); /** * The default alias definition for the {@link ChronoDBDumpBinaryEntry} class. */ public static final Alias ALIAS__CHRONODB_BINARY_ENTRY = new Alias(ChronoDBDumpBinaryEntry.class, ALIAS_NAME__CHRONODB_BINARY_ENTRY); /** * The default alias definition for the {@link ChronoIdentifierImpl} class. */ public static final Alias ALIAS__CHRONO_IDENTIFIER = new Alias(ChronoIdentifierImpl.class, ALIAS_NAME__CHRONO_IDENTIFIER); /** * The default alias definition for the {@link BranchDumpMetadata} class. */ public static final Alias ALIAS__CHRONO_DUMP_METADATA = new Alias(BranchDumpMetadata.class, ALIAS_NAME__BRANCH_DUMP_METADATA); /** * The default alias definition for the {@link IndexerDumpMetadata} class. */ public static final Alias ALIAS__INDEXER_DUMP = new Alias(IndexerDumpMetadata.class, ALIAS_NAME__INDEXER_DUMP_METADATA); // ===================================================================================================================== // PUBLIC API METHODS // ===================================================================================================================== /** * Returns the set of default aliases for DB dumps. * * @return the set of default aliases. May be empty, but never <code>null</code>. */ public static Set<Alias> getAliases() { Set<Alias> aliases = Sets.newHashSet(); Field[] fields = ChronoDBDumpFormat.class.getDeclaredFields(); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers()) == false) { continue; } if (field.getType().equals(Alias.class) == false) { continue; } try { Alias value = (Alias) field.get(null); aliases.add(value); } catch (IllegalArgumentException | IllegalAccessException e) { log.error("Failed to collect aliases", e); } } return aliases; } /** * Returns the set of default aliases, as a map from alias name to "aliased" class. * * @return The mapping of default aliases (alias name to class). May be empty, but never <code>null</code>. */ public static Map<String, Class<?>> getAliasesAsMap() { Set<Alias> aliases = getAliases(); Map<String, Class<?>> resultMap = Maps.newHashMap(); for (Alias alias : aliases) { Class<?> previousValue = resultMap.put(alias.getAliasName(), alias.getType()); if (previousValue != null) { throw new IllegalStateException("Multiple classes share the alias '" + alias.getAliasName() + "': " + previousValue.getName() + ", " + alias.getType().getName()); } } return resultMap; } /** * Creates a default {@link ObjectOutput} for {@linkplain ChronoDB#writeDump(File, DumpOption...) DB dumping} . * * <p> * It is <b>strongly</b> recommended (and in some cases required) to use the same options for writing and reading a * dump file! * * @param outputFile The file to store the dump data. Must not be <code>null</code>, must refer to a file. Will be created * if it does not exist. Will be overwritten without further notice. * @param options The options to use when writing the dump. Must not be <code>null</code>, may be empty. * @return The object output. Must be closed explicitly by the caller. Never <code>null</code>. * @throws ChronoDBStorageBackendException When an I/O related error occurs. */ public static ObjectOutput createOutput(final File outputFile, final DumpOptions options) { checkNotNull(outputFile, "Precondition violation - argument 'outputFile' must not be NULL!"); checkNotNull(options, "Precondition violation - argument 'options' must not be NULL!"); if (outputFile.exists()) { checkArgument(outputFile.isFile(), "Precondition violation - argument 'outputFile' must be a file (not a directory)!"); } else { try { outputFile.getParentFile().mkdirs(); Files.deleteIfExists(outputFile.toPath()); Files.createFile(outputFile.toPath()); } catch (IOException e) { throw new ChronoDBStorageBackendException( "Failed to create dump file in '" + outputFile.getAbsolutePath() + "'!", e); } } // initialize the stream XStream xStream = createXStream(options); try { OutputStream outputStream = null; ObjectOutputStream oos = null; try { outputStream = new FileOutputStream(outputFile); if (options.isGZipEnabled()) { // wrap the output stream in a GZIP output stream outputStream = new GZIPOutputStream(outputStream); } // create the raw object output stream oos = xStream.createObjectOutputStream(outputStream, "chronodump"); // wrap it into an object output ObjectOutputStreamWrapper wrapper = new ObjectOutputStreamWrapper(oos); return wrapper; } catch (Exception e) { // an error has occurred, we can't create the desired output. Close // the output streams in case they were opened. if (oos != null) { IOUtils.closeQuietly(oos); } if (outputStream != null) { IOUtils.closeQuietly(outputStream); } throw new IOException("An error has occurred while constructing the object output.", e); } } catch (IOException e) { throw new ChronoDBStorageBackendException("Failed to open output stream for writing!", e); } } /** * Creates a default {@link ObjectInput} for {@linkplain ChronoDB#readDump(File, DumpOption...) reading DB dump * files}. * * <p> * It is <b>strongly</b> recommended (and in some cases required) to use the same options for writing and reading a * dump file! * * @param inputFile The dump file to read. Must not be <code>null</code>. Must point to a file (not a directory). Must * point to an existing file. * @param options The options to use when reading the dump data. Must not be <code>null</code>. * @return The object input. Must be closed explicitly by the caller. Never <code>null</code>. * @throws ChronoDBStorageBackendException When an I/O related error occurs. */ public static ObjectInput createInput(final File inputFile, final DumpOptions options) { checkNotNull(inputFile, "Precondition violation - argument 'inputFile' must not be NULL!"); checkArgument(inputFile.exists(), "Precondition violation - argument 'inputFile' does not exist! Location: " + inputFile.getAbsolutePath()); checkArgument(inputFile.isFile(), "Precondition violation - argument 'inputFile' must be a File (is a Directory)!"); checkNotNull(options, "Precondition violation - argument 'options' must not be NULL!"); // initialize the xstream XStream xStream = createXStream(options); try { InputStream inputStream = null; ObjectInputStream ois = null; try { inputStream = new FileInputStream(inputFile); if (ChronosFileUtils.isGZipped(inputFile)) { // unzip the stream inputStream = new GZIPInputStream(inputStream); } // create the raw object input stream ois = xStream.createObjectInputStream(inputStream); // wrap it into an object input ObjectInputStreamWrapper wrapper = new ObjectInputStreamWrapper(ois); return wrapper; } catch (Exception e) { // an error has occurred, we can't create the desired output. Close // the output streams in case they were opened. if (ois != null) { IOUtils.closeQuietly(ois); } if (inputStream != null) { IOUtils.closeQuietly(inputStream); } throw new IOException("An error has occurred while constructing the object input.", e); } } catch (IOException e) { throw new ChronoDBStorageBackendException("Failed to open XStream for reading!", e); } } // ===================================================================================================================== // INTERNAL HELPER METHODS // ===================================================================================================================== /** * Creates a new instance of {@link XStream} for reading or writing dump data. * * <p> * It will be equipped with all {@linkplain #getAliases() default aliases}. * * @param options The options to use for the stream. Must not be <code>null</code>. * @return The new, pre-configured XStream instance. Never <code>null</code>. */ private static XStream createXStream(final DumpOptions options) { XStream xStream = new XStream(new PureJavaReflectionProvider()); // since we are serializing/deserializing user objects, we cannot // impose any kind of restriction on the objects to be serialized // and/or deserialized. xStream.addPermission(new AnyTypePermission()); for (Alias alias : ChronoDBDumpFormat.getAliases()) { xStream.alias(alias.getAliasName(), alias.getType()); } for (DumpOption.AliasOption aliasOption : options.getAliasOptions()) { Alias alias = aliasOption.getAlias(); xStream.alias(alias.getAliasName(), alias.getType()); } return xStream; } // ===================================================================================================================== // PUBLIC INNER CLASSES // ===================================================================================================================== /** * An {@link Alias} is simply an alternative name for a {@link java.lang.Class} in the output file. * * <p> * Aliases serve multiple purposes: * <ul> * <li>As an alias is typically shorter than a fully qualified class name, they make the output more compact. * <li>Aliases typically have names that are easier to read for humans than class names. * <li>As aliases prevent the qualified class name from leaking into a persistent file, classes can be moved to * other Java packages without breaking existing dump files. * </ul> * * <p> * Please note that any class may have at most one alias! Aliases are immutable once created. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ public static class Alias { /** * The {@link java.lang.Class} to provide an alias for. */ private final Class<?> type; /** * The alias name given to the class. */ private final String aliasName; /** * Creates a new alias. * * @param type The class to give the alias name to. Must not be <code>null</code>. * @param name The alias name to assign to the class. Must not be <code>null</code>. */ public Alias(final Class<?> type, final String name) { checkNotNull(type, "Precondition violation - argument 'type' must not be NULL!"); checkNotNull(name, "Precondition violation - argument 'name' must not be NULL!"); this.type = type; this.aliasName = name; } /** * Returns the alias name for the class. * * @return The alias name. Never <code>null</code>. */ public String getAliasName() { return this.aliasName; } /** * Returns the class which receives an alias name by this instance. * * @return The class to be aliased. Never <code>null</code>. */ public Class<?> getType() { return this.type; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (this.aliasName == null ? 0 : this.aliasName.hashCode()); result = prime * result + (this.type == null ? 0 : this.type.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (this.getClass() != obj.getClass()) { return false; } Alias other = (Alias) obj; if (this.aliasName == null) { if (other.aliasName != null) { return false; } } else if (!this.aliasName.equals(other.aliasName)) { return false; } if (this.type == null) { if (other.type != null) { return false; } } else if (!this.type.equals(other.type)) { return false; } return true; } @Override public String toString() { return "Alias [type=" + this.type + ", aliasName=" + this.aliasName + "]"; } } // ===================================================================================================================== // PRIVATE INNER CLASSES // ===================================================================================================================== /** * A simple wrapper for an {@link ObjectOutputStream} that implements the reduced {@link ObjectOutput} interface. * * <p> * All calls to the {@link ObjectOutput} interface will be forwarded to the appropriate {@link ObjectOutputStream} * methods. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ private static class ObjectOutputStreamWrapper implements ObjectOutput { /** * The object output stream that is wrapped. */ private final ObjectOutputStream oos; /** * Creates a new instance that wraps the given stream. * * @param stream The stream to wrap. Must not be <code>null</code>. */ public ObjectOutputStreamWrapper(final ObjectOutputStream stream) { checkNotNull(stream, "Precondition violation - argument 'stream' must not be NULL!"); this.oos = stream; } @Override public void write(final Object object) { try { this.oos.writeObject(object); } catch (IOException e) { String clazz = "NULL"; if (object != null) { clazz = object.getClass().getName(); } throw new ChronoDBStorageBackendException("Failed to write object of type '" + clazz + "' to output!", e); } } @Override public void close() { try { this.oos.close(); } catch (IOException e) { throw new ChronoDBStorageBackendException("Failed to close object output!", e); } } } /** * A simple wrapper for an {@link ObjectInputStream} that implements the reduced {@link ObjectInput} interface. * * <p> * All calls to the {@link ObjectInput} interface will be forwarded to the appropriate {@link ObjectInputStream} * methods. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API */ private static class ObjectInputStreamWrapper implements ObjectInput { /** * The object input stream that is being wrapped. */ private final ObjectInputStream ois; /** * As {@link ObjectInputStream} does not provide a {@link #hasNext()} method, we buffer one element here. */ private Object next; /** * Boolean flag that indicates if {@link #close()} has already been called (<code>true</codE>) or not ( * <code>false</code>). */ private boolean closed = false; /** * Creates a new object input, wrapping the given {@link ObjectInputStream}. * * @param ois The object input stream to wrap. Must not be <code>null</code>. */ public ObjectInputStreamWrapper(final ObjectInputStream ois) { checkNotNull(ois, "Precondition violation - argument 'ois' must not be NULL!"); this.ois = ois; this.tryReadNext(); } /** * Fills the internal {@link #next} buffer field to answer the {@link #hasNext()} method. * * <p> * If {@link #next} is <code>null</code> after calling this method, the end of the wrapped input stream has been * reached. */ private void tryReadNext() { try { this.next = this.ois.readObject(); } catch (EOFException ex) { // end of stream was reached this.next = null; } catch (ClassNotFoundException | IOException e) { throw new ChronoDBStorageBackendException("Failed to read object from input!", e); } } @Override public Object next() { if (!this.hasNext()) { throw new NoSuchElementException(); } Object next = this.next; this.tryReadNext(); return next; } @Override public boolean hasNext() { if (this.isClosed()) { return false; } return this.next != null; } @Override public void close() { try { this.ois.close(); } catch (IOException e) { throw new ChronoDBStorageBackendException("Failed to close object input stream!", e); } finally { this.closed = true; } } @Override public boolean isClosed() { return this.closed; } } }
22,571
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoConverter.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/dump/ChronoConverter.java
package org.chronos.chronodb.api.dump; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.api.dump.annotations.ChronosExternalizable; /** * A basic converter interface. * * <p> * The intended use of this interface is to work as a converter between an internal (in-memory) and an external * (persistent) data format. It is mainly used in combination with the * {@linkplain ChronoDB#writeDump(java.io.File, org.chronos.chronodb.api.DumpOption...) dump API} and the * {@link ChronosExternalizable} annotation. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * * @param <I> * The internal data format that can be converted to the external format by this converter. * @param <E> * The external data format that can be converted to the internal format by this converter. */ public interface ChronoConverter<I, E> { /** * Converts the given internal object into its external representation. * * @param value * The internal object to convert. May be <code>null</code>. * @return The external representation of the object. May be <code>null</code>. */ public E writeToOutput(I value); /** * Converts the given external object into its internal representation. * * @param value * The external object to convert. May be <code>null</code>. * @return The internal representation of the object. May be <code>null</code>. */ public I readFromInput(E value); }
1,479
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronosExternalizable.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/dump/annotations/ChronosExternalizable.java
package org.chronos.chronodb.api.dump.annotations; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.api.dump.ChronoConverter; /** * A marker annotation that associates a class with a {@link ChronoConverter}. * * <p> * This annotation is primarily used in conjunction with the * {@linkplain ChronoDB#writeDump(java.io.File, org.chronos.chronodb.api.DumpOption...) dump API}. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ @Documented @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface ChronosExternalizable { /** The converter class to use for the annotated class. */ public Class<? extends ChronoConverter<?, ?>> converterClass(); }
929
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
QualifiedKey.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/key/QualifiedKey.java
package org.chronos.chronodb.api.key; import static com.google.common.base.Preconditions.*; import java.io.Serializable; import org.chronos.chronodb.api.ChronoDBConstants; import org.chronos.chronodb.internal.impl.temporal.QualifiedKeyImpl; /** * A qualified key is a combination of a keyspace name and a key name. * * <p> * Implementations of this interface <b>must</b> implement {@link #hashCode()} and {@link #equals(Object)} based upon * the key and the keyspace name. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface QualifiedKey extends Serializable { // ===================================================================================================================== // FACTORY METHODS // ===================================================================================================================== /** * Creates a new {@link QualifiedKey} in the {@link ChronoDBConstants#DEFAULT_KEYSPACE_NAME default keyspace}. * * @param key * The key to use for the new qualified key. Must not be <code>null</code>. * * @return The newly created qualified key. Never <code>null</code>. */ public static QualifiedKey createInDefaultKeyspace(final String key) { checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new QualifiedKeyImpl(ChronoDBConstants.DEFAULT_KEYSPACE_NAME, key); } /** * Creates a new {@link QualifiedKey}. * * @param key * The key to use for the new qualified key. Must not be <code>null</code>. * @param keyspace * The keyspace to use for the new qualified key. Must not be <code>null</code>. * * @return The newly created qualified key. Never <code>null</code>. */ public static QualifiedKey create(final String keyspace, final String key) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new QualifiedKeyImpl(keyspace, key); } // ===================================================================================================================== // GETTERS // ===================================================================================================================== /** * Returns the "key" part of this qualified key. * * @return The key. Never <code>null</code>. */ public String getKey(); /** * Returns the "keyspace" part of this qualified key. * * @return The keyspace name. Never <code>null</code>. */ public String getKeyspace(); }
2,616
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
TemporalKey.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/key/TemporalKey.java
package org.chronos.chronodb.api.key; import static com.google.common.base.Preconditions.*; import java.util.Comparator; import org.chronos.chronodb.internal.impl.temporal.TemporalKeyImpl; /** * A {@link TemporalKey} is a {@link QualifiedKey} with additional temporal information. * * <p> * This class does <b>not</b> extend {@link QualifiedKey} due to problems with collection containment checks and the * {@link #equals(Object)} method. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface TemporalKey /* NOT extends QualifiedKey, */ { // ===================================================================================================================== // STATIC FACTORY METHODS // ===================================================================================================================== /** * Creates a new {@link TemporalKey}. * * @param timestamp * The timestamp to use in the new temporal key. Must not be negative. * @param keyspace * The keyspace to use in the new temporal key. Must not be <code>null</code>. * @param key * The key to use in the new temporal key. Must not be <code>null</code>. * * @return The newly created temporal key. Never <code>null</code>. */ public static TemporalKey create(final long timestamp, final String keyspace, final String key) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new TemporalKeyImpl(timestamp, keyspace, key); } /** * Creates a new {@link TemporalKey}. * * @param timestamp * The timestamp to use in the new temporal key. Must not be negative. * @param qualifiedKey * The qualified key to read data from for the new temporal key. Data will be copied, the qualified key * will not be modified. Must not be <code>null</code>. * * @return The newly created temporal key. Never <code>null</code>. */ public static TemporalKey create(final long timestamp, final QualifiedKey qualifiedKey) { checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); return create(timestamp, qualifiedKey.getKeyspace(), qualifiedKey.getKey()); } /** * Creates a new {@link TemporalKey}, with the minimum timestamp (zero). * * @param keyspace * The keyspace to use in the new temporal key. Must not be <code>null</code>. * @param key * The key to use in the new temporal key. Must not be <code>null</code>. * * @return The newly created temporal key. Never <code>null</code>. */ public static TemporalKey createMinTime(final String keyspace, final String key) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new TemporalKeyImpl(0L, keyspace, key); } /** * Creates a new {@link TemporalKey}, with the maximum timestamp ({@link Long#MAX_VALUE}). * * @param keyspace * The keyspace to use in the new temporal key. Must not be <code>null</code>. * @param key * The key to use in the new temporal key. Must not be <code>null</code>. * * @return The newly created temporal key. Never <code>null</code>. */ public static TemporalKey createMaxTime(final String keyspace, final String key) { checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new TemporalKeyImpl(Long.MAX_VALUE, keyspace, key); } // ================================================================================================================= // COMPARATORS // ================================================================================================================= public static interface Comparators { //@formatter:off public static final Comparator<TemporalKey> BY_TIME_KEYSPACE_KEY = Comparator.comparing(TemporalKey::getTimestamp) .thenComparing(TemporalKey::getKeyspace) .thenComparing(TemporalKey::getKey); //@formatter:on } // ===================================================================================================================== // GETTERS // ===================================================================================================================== /** * Returns the timestamp associated with this temporal key. * * @return The timestamp */ public long getTimestamp(); /** * Returns the "key" part of this temporal key. * * @return The key. Never <code>null</code>. */ public String getKey(); /** * Returns the "keyspace" part of this temporal key. * * @return The keyspace name. Never <code>null</code>. */ public String getKeyspace(); // ===================================================================================================================== // CONVERSION METHODS // ===================================================================================================================== /** * Returns a representation of this {@link TemporalKey} as a {@link QualifiedKey}. * * <p> * Note that a {@link QualifiedKey} contains less data than a {@link TemporalKey}. Two different temporal keys may * therefore produce two equal qualified keys. * * @return The qualified key representation of this temporal key. Never <code>null</code>. */ public QualifiedKey toQualifiedKey(); }
5,752
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
ChronoIdentifier.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/key/ChronoIdentifier.java
package org.chronos.chronodb.api.key; import static com.google.common.base.Preconditions.*; import org.chronos.chronodb.api.Branch; import org.chronos.chronodb.api.ChronoDB; import org.chronos.chronodb.internal.impl.temporal.ChronoIdentifierImpl; /** * A {@link ChronoIdentifier} is a {@link TemporalKey} with additional metadata. * * <p> * Every entry in the entire {@link ChronoDB} can be uniquely identified by a ChronoIdentifier. * * <p> * This class does <b>not</b> extend {@link TemporalKey} or {@link QualifiedKey} due to problems with collection * containment checks and the {@link #equals(Object)} method. * * @author martin.haeusler@uibk.ac.at -- Initial Contribution and API * */ public interface ChronoIdentifier /* NOT implements TemporalKey, QualifiedKey */ { // ===================================================================================================================== // FACTORY METHODS // ===================================================================================================================== /** * Creates a new {@link ChronoIdentifier} instance. * * @param branch * The branch to use in the new identifier. Must not be <code>null</code>. * @param timestamp * The timestamp to use in the new identifier. Must not be negative. * @param keyspace * The keyspace to use in the new identifier. Must not be <code>null</code>. * @param key * The key to use in the new identifier. Must not be <code>null</code>. * * @return The newly created {@link ChronoIdentifier} instance, filled with the data from the parameters. Never * <code>null</code>. */ public static ChronoIdentifier create(final Branch branch, final long timestamp, final String keyspace, final String key) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new ChronoIdentifierImpl(branch.getName(), keyspace, key, timestamp); } /** * Creates a new {@link ChronoIdentifier} instance. * * @param branchName * The branch name to use in the new identifier. Must not be <code>null</code>. * @param timestamp * The timestamp to use in the new identifier. Must not be negative. * @param keyspace * The keyspace to use in the new identifier. Must not be <code>null</code>. * @param key * The key to use in the new identifier. Must not be <code>null</code>. * * @return The newly created {@link ChronoIdentifier} instance, filled with the data from the parameters. Never * <code>null</code>. */ public static ChronoIdentifier create(final String branchName, final long timestamp, final String keyspace, final String key) { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(keyspace, "Precondition violation - argument 'keyspace' must not be NULL!"); checkNotNull(key, "Precondition violation - argument 'key' must not be NULL!"); return new ChronoIdentifierImpl(branchName, keyspace, key, timestamp); } /** * Creates a new {@link ChronoIdentifier} instance. * * @param branchName * The branch name to use in the new identifier. Must not be <code>null</code>. * @param temporalKey * The temporal key that contains the data to use in the new identifier. Data will be copied, the * temporal key remains unmodified. Must not be <code>null</code>. * * @return The newly created {@link ChronoIdentifier} instance, filled with the data from the parameters. Never * <code>null</code>. */ public static ChronoIdentifier create(final String branchName, final TemporalKey temporalKey) { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); checkNotNull(temporalKey, "Precondition violation - argument 'temporalKey' must not be NULL!"); return create(branchName, temporalKey.getTimestamp(), temporalKey.getKeyspace(), temporalKey.getKey()); } /** * Creates a new {@link ChronoIdentifier} instance. * * @param branch * The branch to use in the new identifier. Must not be <code>null</code>. * @param temporalKey * The temporal key that contains the data to use in the new identifier. Data will be copied, the * temporal key remains unmodified. Must not be <code>null</code>. * * @return The newly created {@link ChronoIdentifier} instance, filled with the data from the parameters. Never * <code>null</code>. */ public static ChronoIdentifier create(final Branch branch, final TemporalKey temporalKey) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkNotNull(temporalKey, "Precondition violation - argument 'temporalKey' must not be NULL!"); return create(branch, temporalKey.getTimestamp(), temporalKey.getKeyspace(), temporalKey.getKey()); } /** * Creates a new {@link ChronoIdentifier} instance. * * @param branchName * The branch name to use in the new identifier. Must not be <code>null</code>. * @param timestamp * The timestamp to use in the new identifier. Must not be negative. * @param qualifiedKey * The qualified key that contains the data to use in the new identifier. Data will be copied, the * qualified key remains unmodified. Must not be <code>null</code>. * * @return The newly created {@link ChronoIdentifier} instance, filled with the data from the parameters. Never * <code>null</code>. */ public static ChronoIdentifier create(final String branchName, final long timestamp, final QualifiedKey qualifiedKey) { checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(qualifiedKey, "Precondition violation - argument 'qualifiedKey' must not be NULL!"); return create(branchName, timestamp, qualifiedKey.getKeyspace(), qualifiedKey.getKey()); } /** * Creates a new {@link ChronoIdentifier} instance. * * @param branch * The branch to use in the new identifier. Must not be <code>null</code>. * @param timestamp * The timestamp to use in the new identifier. Must not be negative. * @param qualifiedKey * The qualified key that contains the data to use in the new identifier. Data will be copied, the * qualified key remains unmodified. Must not be <code>null</code>. * * @return The newly created {@link ChronoIdentifier} instance, filled with the data from the parameters. Never * <code>null</code>. */ public static ChronoIdentifier create(final Branch branch, final long timestamp, final QualifiedKey qualifiedKey) { checkNotNull(branch, "Precondition violation - argument 'branch' must not be NULL!"); checkArgument(timestamp >= 0, "Precondition violation - argument 'timestamp' must not be negative!"); checkNotNull(qualifiedKey, "Precondition violation - argument 'qualifiedKey' must not be NULL!"); return create(branch, timestamp, qualifiedKey.getKeyspace(), qualifiedKey.getKey()); } // ===================================================================================================================== // GETTERS // ===================================================================================================================== /** * Returns the "key" part of this chrono identifer. * * @return The key. Never <code>null</code>. */ public String getKey(); /** * Returns the "keyspace" part of this chrono identifier. * * @return The keyspace name. Never <code>null</code>. */ public String getKeyspace(); /** * Returns the branch identifier for the branch in which this identifier resides. * * @return The branch identifier. Never <code>null</code>. */ public String getBranchName(); /** * Returns the timestamp associated with this chrono identifer. * * @return The timestamp */ public long getTimestamp(); // ===================================================================================================================== // CONVERSION METHODS // ===================================================================================================================== /** * Returns a representation of this {@link ChronoIdentifier} as a {@link TemporalKey}. * * <p> * Note that a {@link TemporalKey} contains less data than a {@link ChronoIdentifier}. Two different identifiers may * therefore produce two equal temporal keys. * * @return The temporal key representation of this identifier. Never <code>null</code>. */ public TemporalKey toTemporalKey(); /** * Returns a representation of this {@link ChronoIdentifier} as a {@link QualifiedKey}. * * <p> * Note that a {@link QualifiedKey} contains less data than a {@link ChronoIdentifier}. Two different identifiers * may therefore produce two equal qualified keys. * * @return The qualified key representation of this identifier. Never <code>null</code>. */ public QualifiedKey toQualifiedKey(); }
9,613
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z
LongContainmentCondition.java
/FileExtraction/Java_unseen/Txture_chronos/org.chronos.chronodb.api/src/main/java/org/chronos/chronodb/api/query/LongContainmentCondition.java
package org.chronos.chronodb.api.query; import org.chronos.chronodb.internal.impl.query.condition.containment.LongWithinSetCondition; import org.chronos.chronodb.internal.impl.query.condition.containment.SetWithoutLongCondition; import java.util.Set; public interface LongContainmentCondition extends ContainmentCondition { public static LongContainmentCondition WITHIN = LongWithinSetCondition.INSTANCE; public static LongContainmentCondition WITHOUT = SetWithoutLongCondition.INSTANCE; /** * Negates this condition. * * @return The negated condition. */ public LongContainmentCondition negate(); /** * Applies this condition. * * @param elementToTest The element to check. May be <code>null</code>. * @param collectionToTestAgainst The collection to check against. <code>null</code> will be treated as empty collection. * @return <code>true</code> if this condition applies, otherwise <code>false</code>. */ public boolean applies(long elementToTest, Set<Long> collectionToTestAgainst); }
1,073
Java
.java
Txture/chronos
26
3
0
2020-05-19T17:35:13Z
2023-03-10T16:19:01Z