Class OChainedIndexProxy<T>
java.lang.Object
com.orientechnologies.orient.core.sql.OChainedIndexProxy<T>
- All Implemented Interfaces:
OIndex,OIndexInternal,Comparable<OIndex>
There are some cases when we need to create index for some class by traversed property.
Unfortunately, such functionality is not supported yet. But we can do that by creating index for
each element of
OSQLFilterItemField.FieldChain (which define "way" to our property), and
then process operations consequently using previously created indexes.
This class provides possibility to find optimal chain of indexes and then use it just like it was index for traversed property.
IMPORTANT: this class is only for internal usage!
- Author:
- Artem Orobets
-
Field Summary
Fields inherited from interface com.orientechnologies.orient.core.index.OIndexInternal
ALGORITHM, CONFIG_AUTOMATIC, CONFIG_KEYTYPE, CONFIG_NAME, CONFIG_TYPE, INDEX_DEFINITION, INDEX_DEFINITION_CLASS, INDEX_VERSION, MERGE_KEYS, METADATA, VALUE_CONTAINER_ALGORITHM -
Method Summary
Modifier and TypeMethodDescriptionbooleanAcquires exclusive lock in the active atomic operation running on the current thread for this index.addCluster(String iClusterName) Add given cluster to the list of clusters that should be automatically indexed.booleanIndicates whether given index can be used to calculate result ofOQueryOperatorEqualityoperators.clear()Deprecated.Manual indexes are deprecated and will be removedvoidclose()intlongCounts the entries for the key.create(OIndexMetadata indexMetadat, boolean rebuild, OProgressListener progressListener) static <T> Collection<OChainedIndexProxy<T>>createProxies(OClass iSchemaClass, OSQLFilterItemField.FieldChain longChain) Create proxies that support maximum number of different operations.cursor()delete()Delete the index.voiddoPut(OAbstractPaginatedStorage storage, Object key, ORID rid) booleandoRemove(OAbstractPaginatedStorage storage, Object key) booleandoRemove(OAbstractPaginatedStorage storage, Object key, ORID rid) protected static OIndexfindBestIndex(Iterable<OIndex> indexes) Finds the index that fits better as a base index in chain.voidflush()Flushes in-memory changes to disk.Deprecated.Returns the engine of the index as string.Returns Names of clusters that will be indexed.getCollatingValue(Object key) Returns the index configuration.intgetIndexNameByKey(Object key) Returns the index name for a key.Returns internal index of last chain index, because proxy applicable to all operations that last index applicable.longOType[]Types of the keys that index can accept, if index contains composite key, list of types of elements from which this index consist will be returned, otherwise single element (key type obviously) will be returned.getName()Returns the index name.longgetRidsIgnoreTx(Object key) longgetSize()getType()Returns the type of the index as string.intReturns binary format version for this index.booleanstatic booleanisAppropriateAsBase(OIndex index) Checks if index can be used as base index.booleanTells if the index is automatic.booleanbooleanbooleanisUnique()iterateEntries(Collection<?> keys, boolean ascSortOrder) Returns cursor which presents data associated with passed in keys.iterateEntriesBetween(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive, boolean ascOrder) Returns cursor which presents subset of index data between passed in keys.iterateEntriesMajor(Object fromKey, boolean fromInclusive, boolean ascOrder) Returns cursor which presents subset of data which associated with key which is greater than passed in key.iterateEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder) Returns cursor which presents subset of data which associated with key which is less than passed in key.iterator()booleanloadFromConfiguration(ODocument iConfig) Loads the index giving the configuration.loadMetadata(ODocument iConfig) put(Object key, OIdentifiable value) Inserts a new entry in the index.longrebuild()Rebuilds an automatic index.longrebuild(OProgressListener iProgressListener) Populate the index with all the existent records.booleanRemoves an entry by its key.booleanremove(Object key, OIdentifiable rid) Removes an entry by its key and value.removeCluster(String iClusterName) Remove given cluster from the list of clusters that should be automatically indexed.longsize()stream()streamEntries(Collection<?> keys, boolean ascSortOrder) Returns stream which presents data associated with passed in keys.streamEntriesBetween(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive, boolean ascOrder) Returns stream which presents subset of index data between passed in keys.streamEntriesMajor(Object fromKey, boolean fromInclusive, boolean ascOrder) Returns stream which presents subset of data which associated with key which is greater than passed in key.streamEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder) Returns stream which presents subset of data which associated with key which is less than passed in key.booleanSaves the index configuration to disk.
-
Method Details
-
createProxies
public static <T> Collection<OChainedIndexProxy<T>> createProxies(OClass iSchemaClass, OSQLFilterItemField.FieldChain longChain) Create proxies that support maximum number of different operations. In case when several different indexes which support different operations (e.g. indexes ofUNIQUEandFULLTEXTtypes) are possible, the creates the only one index of each type.- Parameters:
longChain- - property chain from the query, which should be evaluated- Returns:
- proxies needed to process query.
-
findBestIndex
Finds the index that fits better as a base index in chain. Requirements to the base index:- Should be unique or not unique. Other types cannot be used to get all documents with required links.
- Should not be composite hash index. As soon as hash index does not support partial match search.
- Composite index that ignores null values should not be used.
- Hash index is better than tree based indexes.
- Non composite indexes is better that composite.
- Parameters:
indexes- where search- Returns:
- the index that fits better as a base index in chain
-
isAppropriateAsBase
Checks if index can be used as base index. Requirements to the base index:- Should be unique or not unique. Other types cannot be used to get all documents with required links.
- Should not be composite hash index. As soon as hash index does not support partial match search.
- Composite index that ignores null values should not be used.
- Parameters:
index- to check- Returns:
- true if index usage is allowed as base index.
-
getDatabaseName
- Specified by:
getDatabaseNamein interfaceOIndex
-
getIndexNames
-
getName
Description copied from interface:OIndexReturns the index name. -
get
Deprecated.Gets the set of records associated with the passed key. -
getRidsIgnoreTx
- Specified by:
getRidsIgnoreTxin interfaceOIndexInternal
-
getRids
- Specified by:
getRidsin interfaceOIndexInternal
-
getInternal
Returns internal index of last chain index, because proxy applicable to all operations that last index applicable.- Specified by:
getInternalin interfaceOIndex
-
getDefinition
- Specified by:
getDefinitionin interfaceOIndex
-
create
public OIndex create(OIndexMetadata indexMetadat, boolean rebuild, OProgressListener progressListener) - Specified by:
createin interfaceOIndexInternal
-
getKeyTypes
Description copied from interface:OIndexTypes of the keys that index can accept, if index contains composite key, list of types of elements from which this index consist will be returned, otherwise single element (key type obviously) will be returned.- Specified by:
getKeyTypesin interfaceOIndex
-
iterator
-
put
Description copied from interface:OIndexInserts a new entry in the index. The behaviour depends by the index implementation. -
remove
Description copied from interface:OIndexRemoves an entry by its key. -
remove
Description copied from interface:OIndexRemoves an entry by its key and value. -
clear
Deprecated.Manual indexes are deprecated and will be removedClears the index removing all the entries in one shot. -
getSize
public long getSize() -
count
Description copied from interface:OIndexCounts the entries for the key. -
getKeySize
public long getKeySize()- Specified by:
getKeySizein interfaceOIndex- Returns:
- Number of keys in index
-
flush
public void flush()Description copied from interface:OIndexFlushes in-memory changes to disk. -
getRebuildVersion
public long getRebuildVersion()- Specified by:
getRebuildVersionin interfaceOIndex
-
isRebuilding
public boolean isRebuilding()- Specified by:
isRebuildingin interfaceOIndex- Returns:
- Indicates whether index is rebuilding at the moment.
- See Also:
-
getFirstKey
- Specified by:
getFirstKeyin interfaceOIndex
-
getLastKey
- Specified by:
getLastKeyin interfaceOIndex
-
cursor
-
descCursor
- Specified by:
descCursorin interfaceOIndex
-
keyCursor
-
getCollatingValue
- Specified by:
getCollatingValuein interfaceOIndexInternal
-
loadFromConfiguration
Description copied from interface:OIndexInternalLoads the index giving the configuration.- Specified by:
loadFromConfigurationin interfaceOIndexInternal- Parameters:
iConfig- ODocument instance containing the configuration
-
updateConfiguration
Description copied from interface:OIndexInternalSaves the index configuration to disk.- Specified by:
updateConfigurationin interfaceOIndexInternal- Returns:
- The configuration as ODocument instance
- See Also:
-
addCluster
Description copied from interface:OIndexInternalAdd given cluster to the list of clusters that should be automatically indexed.- Specified by:
addClusterin interfaceOIndexInternal- Parameters:
iClusterName- Cluster to add.- Returns:
- Current index instance.
-
removeCluster
Description copied from interface:OIndexInternalRemove given cluster from the list of clusters that should be automatically indexed.- Specified by:
removeClusterin interfaceOIndexInternal- Parameters:
iClusterName- Cluster to remove.- Returns:
- Current index instance.
-
canBeUsedInEqualityOperators
public boolean canBeUsedInEqualityOperators()Description copied from interface:OIndexInternalIndicates whether given index can be used to calculate result ofOQueryOperatorEqualityoperators.- Specified by:
canBeUsedInEqualityOperatorsin interfaceOIndexInternal- Returns:
trueif given index can be used to calculate result ofOQueryOperatorEqualityoperators.
-
hasRangeQuerySupport
public boolean hasRangeQuerySupport()- Specified by:
hasRangeQuerySupportin interfaceOIndexInternal
-
loadMetadata
- Specified by:
loadMetadatain interfaceOIndexInternal
-
close
public void close()- Specified by:
closein interfaceOIndexInternal
-
getIndexNameByKey
Description copied from interface:OIndexInternalReturns the index name for a key. The name is always the current index name, but in cases where the index supports key-based sharding.- Specified by:
getIndexNameByKeyin interfaceOIndexInternal- Parameters:
key- the index key.- Returns:
- The index name involved
-
acquireAtomicExclusiveLock
Description copied from interface:OIndexInternalAcquires exclusive lock in the active atomic operation running on the current thread for this index.If this index supports a more narrow locking, for example key-based sharding, it may use the provided
keyto infer a more narrow lock scope, but that is not a requirement.- Specified by:
acquireAtomicExclusiveLockin interfaceOIndexInternal- Parameters:
key- the index key to lock.- Returns:
trueif this index was locked entirely,falseif this index locking is sensitive to the providedkeyand only some subset of this index was locked.
-
size
public long size()- Specified by:
sizein interfaceOIndexInternal- Returns:
- number of entries in the index.
-
delete
Description copied from interface:OIndexDelete the index. -
getType
Description copied from interface:OIndexReturns the type of the index as string. -
getAlgorithm
Description copied from interface:OIndexReturns the engine of the index as string.- Specified by:
getAlgorithmin interfaceOIndex
-
isAutomatic
public boolean isAutomatic()Description copied from interface:OIndexTells if the index is automatic. Automatic means it's maintained automatically by OrientDB. This is the case of indexes created against schema properties. Automatic indexes can always been rebuilt.- Specified by:
isAutomaticin interfaceOIndex- Returns:
- True if the index is automatic, otherwise false
-
rebuild
public long rebuild()Description copied from interface:OIndexRebuilds an automatic index. -
rebuild
Description copied from interface:OIndexPopulate the index with all the existent records. -
getConfiguration
Description copied from interface:OIndexReturns the index configuration.- Specified by:
getConfigurationin interfaceOIndex- Returns:
- An ODocument object containing all the index properties
-
getMetadata
- Specified by:
getMetadatain interfaceOIndex
-
getClusters
Description copied from interface:OIndexReturns Names of clusters that will be indexed.- Specified by:
getClustersin interfaceOIndex- Returns:
- Names of clusters that will be indexed.
-
iterateEntries
Description copied from interface:OIndexReturns cursor which presents data associated with passed in keys.- Specified by:
iterateEntriesin interfaceOIndex- Parameters:
keys- Keys data of which should be returned.ascSortOrder- Flag which determines whether data iterated by cursor should be in ascending or descending order.- Returns:
- cursor which presents data associated with passed in keys.
-
iterateEntriesBetween
public OIndexCursor iterateEntriesBetween(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive, boolean ascOrder) Description copied from interface:OIndexReturns cursor which presents subset of index data between passed in keys.- Specified by:
iterateEntriesBetweenin interfaceOIndex- Parameters:
fromKey- Lower border of index data.fromInclusive- Indicates whether lower border should be inclusive or exclusive.toKey- Upper border of index data.toInclusive- Indicates whether upper border should be inclusive or exclusive.ascOrder- Flag which determines whether data iterated by cursor should be in ascending or descending order.- Returns:
- Cursor which presents subset of index data between passed in keys.
-
iterateEntriesMajor
Description copied from interface:OIndexReturns cursor which presents subset of data which associated with key which is greater than passed in key.- Specified by:
iterateEntriesMajorin interfaceOIndex- Parameters:
fromKey- Lower border of index data.fromInclusive- Indicates whether lower border should be inclusive or exclusive.ascOrder- Flag which determines whether data iterated by cursor should be in ascending or descending order.- Returns:
- cursor which presents subset of data which associated with key which is greater than passed in key.
-
iterateEntriesMinor
Description copied from interface:OIndexReturns cursor which presents subset of data which associated with key which is less than passed in key.- Specified by:
iterateEntriesMinorin interfaceOIndex- Parameters:
toKey- Upper border of index data.toInclusive- Indicates Indicates whether upper border should be inclusive or exclusive.ascOrder- Flag which determines whether data iterated by cursor should be in ascending or descending order.- Returns:
- cursor which presents subset of data which associated with key which is less than passed in key.
-
getIndexId
public int getIndexId()- Specified by:
getIndexIdin interfaceOIndexInternal
-
isUnique
public boolean isUnique() -
stream
- Specified by:
streamin interfaceOIndexInternal
-
descStream
- Specified by:
descStreamin interfaceOIndexInternal
-
keyStream
- Specified by:
keyStreamin interfaceOIndexInternal
-
getVersion
public int getVersion()Description copied from interface:OIndexReturns binary format version for this index. Index format changes during system development but old formats are supported for binary compatibility. This method may be used to detect version of binary format which is used by current index and upgrade index to new one.- Specified by:
getVersionin interfaceOIndex- Returns:
- Returns binary format version for this index if possible, otherwise -1.
-
supportsOrderedIterations
public boolean supportsOrderedIterations()- Specified by:
supportsOrderedIterationsin interfaceOIndex
-
streamEntries
Description copied from interface:OIndexInternalReturns stream which presents data associated with passed in keys.- Specified by:
streamEntriesin interfaceOIndexInternal- Parameters:
keys- Keys data of which should be returned.ascSortOrder- Flag which determines whether data iterated by stream should be in ascending or descending order.- Returns:
- stream which presents data associated with passed in keys.
-
streamEntriesBetween
public Stream<ORawPair<Object,ORID>> streamEntriesBetween(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive, boolean ascOrder) Description copied from interface:OIndexInternalReturns stream which presents subset of index data between passed in keys.- Specified by:
streamEntriesBetweenin interfaceOIndexInternal- Parameters:
fromKey- Lower border of index data.fromInclusive- Indicates whether lower border should be inclusive or exclusive.toKey- Upper border of index data.toInclusive- Indicates whether upper border should be inclusive or exclusive.ascOrder- Flag which determines whether data iterated by stream should be in ascending or descending order.- Returns:
- Cursor which presents subset of index data between passed in keys.
-
streamEntriesMajor
public Stream<ORawPair<Object,ORID>> streamEntriesMajor(Object fromKey, boolean fromInclusive, boolean ascOrder) Description copied from interface:OIndexInternalReturns stream which presents subset of data which associated with key which is greater than passed in key.- Specified by:
streamEntriesMajorin interfaceOIndexInternal- Parameters:
fromKey- Lower border of index data.fromInclusive- Indicates whether lower border should be inclusive or exclusive.ascOrder- Flag which determines whether data iterated by stream should be in ascending or descending order.- Returns:
- stream which presents subset of data which associated with key which is greater than passed in key.
-
streamEntriesMinor
public Stream<ORawPair<Object,ORID>> streamEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder) Description copied from interface:OIndexInternalReturns stream which presents subset of data which associated with key which is less than passed in key.- Specified by:
streamEntriesMinorin interfaceOIndexInternal- Parameters:
toKey- Upper border of index data.toInclusive- Indicates Indicates whether upper border should be inclusive or exclusive.ascOrder- Flag which determines whether data iterated by stream should be in ascending or descending order.- Returns:
- stream which presents subset of data which associated with key which is less than passed in key.
-
isNativeTxSupported
public boolean isNativeTxSupported()- Specified by:
isNativeTxSupportedin interfaceOIndexInternal
-
interpretTxKeyChanges
public Iterable<OTransactionIndexChangesPerKey.OTransactionIndexEntry> interpretTxKeyChanges(OTransactionIndexChangesPerKey changes) - Specified by:
interpretTxKeyChangesin interfaceOIndexInternal
-
doPut
- Specified by:
doPutin interfaceOIndexInternal
-
doRemove
- Specified by:
doRemovein interfaceOIndexInternal
-
doRemove
- Specified by:
doRemovein interfaceOIndexInternal
-
compareTo
- Specified by:
compareToin interfaceComparable<T>
-