com.hazelcast.query.impl.Index Maven / Gradle / Ivy
Show all versions of hazelcast-all Show documentation
/*
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.query.impl;
import com.hazelcast.core.TypeConverter;
import com.hazelcast.nio.serialization.Data;
import com.hazelcast.query.QueryException;
import com.hazelcast.query.impl.predicates.PredicateUtils;
import java.util.Set;
/**
* Represents an index built on top of the attribute of the map entries.
*/
public interface Index {
/**
* @return the canonical name of this index: for single-attribute
* non-composite indexes, it's the attribute name itself stripping an
* unnecessary "this." qualifier, if any; for composite indexes, it's a
* comma-separated list of index components with a single space character
* going after every comma, any unnecessary "this." qualifiers are stripped.
* @see PredicateUtils#canonicalizeAttribute
* @see PredicateUtils#constructCanonicalCompositeIndexName
*/
String getName();
/**
* @return the components of this index for composite indexes, {@code null}
* for single-attribute non-composite indexes.
*/
String[] getComponents();
/**
* Tells whether this index is ordered or not.
*
* Ordered indexes support the fast evaluation of range queries. Unordered
* indexes are still capable to execute range queries, but the performance
* would be about the same as the full scan performance.
*
* @return {@code true} if this index is ordered, {@code false} otherwise.
* @see #getRecords(Comparison, Comparable)
* @see #getRecords(Comparable, boolean, Comparable, boolean)
*/
boolean isOrdered();
/**
* @return the converter associated with this index; or {@code null} if the
* converter is not known because there were no saves to this index and
* the attribute type is not inferred yet.
*/
TypeConverter getConverter();
/**
* Saves the given entry into this index.
*
* @param entry the entry to save.
* @param oldValue the previous old value associated with the entry or
* {@code null} if the entry is new.
* @param operationSource the operation source.
* @throws QueryException if there were errors while extracting the
* attribute value from the entry.
*/
void putEntry(QueryableEntry entry, Object oldValue, OperationSource operationSource);
/**
* Removes the entry having the given key and the value from this index.
*
* @param key the key of the entry to remove.
* @param value the value of the entry to remove.
* @param operationSource the operation source.
* @throws QueryException if there were errors while extracting the
* attribute value from the entry.
*/
void removeEntry(Data key, Object value, OperationSource operationSource);
/**
* Produces a result set containing entries whose attribute values are equal
* to the given value.
*
* @param value the value to compare against.
* @return the produced result set.
*/
Set getRecords(Comparable value);
/**
* Produces a result set containing entries whose attribute values are equal
* to at least one of the given values.
*
* @param values the values to compare against.
* @return the produced result set.
*/
Set getRecords(Comparable[] values);
/**
* Produces a result set by performing a range query on this index with the
* range defined by the passed arguments.
*
* @param from the beginning of the range.
* @param fromInclusive {@code true} if the beginning of the range is
* inclusive, {@code false} otherwise.
* @param to the end of the range.
* @param toInclusive {@code true} if the end of the range is inclusive,
* {@code false} otherwise.
* @return the produced result set.
*/
Set getRecords(Comparable from, boolean fromInclusive, Comparable to, boolean toInclusive);
/**
* Produces a result set containing entries whose attribute values are
* satisfy the comparison of the given type with the given value.
*
* @param comparison the type of the comparison to perform.
* @param value the value to compare against.
* @return the produced result set.
*/
Set getRecords(Comparison comparison, Comparable value);
/**
* Clears out all entries from this index.
*/
void clear();
/**
* Releases all resources hold by this index, e.g. the allocated native
* memory for the HD index.
*/
void destroy();
/**
* Identifies an original source of an index operation.
*
* Required for the index stats tracking to ignore index operations
* initiated internally by Hazelcast. We can't achieve the same behaviour
* on the pure stats level, e.g. by turning stats off during a partition
* migration, since global indexes and their stats are shared across
* partitions.
*/
enum OperationSource {
/**
* Indicates that an index operation was initiated by a user; for
* instance, as a result of a new map entry insertion.
*/
USER,
/**
* Indicates that an index operation was initiated internally by
* Hazelcast; for instance, as a result of a partition migration.
*/
SYSTEM
}
}