Class OChainedIndexProxy<T>

java.lang.Object
com.orientechnologies.orient.core.sql.OChainedIndexProxy<T>
All Implemented Interfaces:
OIndex, OIndexInternal, Comparable<OIndex>

public class OChainedIndexProxy<T> extends Object implements OIndexInternal
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
  • 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 of UNIQUE and FULLTEXT types) 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

      protected static OIndex findBestIndex(Iterable<OIndex> indexes)
      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

      public static boolean isAppropriateAsBase(OIndex index)
      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

      public String getDatabaseName()
      Specified by:
      getDatabaseName in interface OIndex
    • getIndexNames

      public List<String> getIndexNames()
    • getName

      public String getName()
      Description copied from interface: OIndex
      Returns the index name.
      Specified by:
      getName in interface OIndex
      Returns:
      The name of the index
    • get

      @Deprecated public T get(Object key)
      Deprecated.
      Gets the set of records associated with the passed key.
      Specified by:
      get in interface OIndex
      Parameters:
      key - The key to search
      Returns:
      The Record set if found, otherwise an empty Set
    • getRidsIgnoreTx

      public Stream<ORID> getRidsIgnoreTx(Object key)
      Specified by:
      getRidsIgnoreTx in interface OIndexInternal
    • getRids

      public Stream<ORID> getRids(Object key)
      Specified by:
      getRids in interface OIndexInternal
    • getInternal

      public OIndexInternal getInternal()
      Returns internal index of last chain index, because proxy applicable to all operations that last index applicable.
      Specified by:
      getInternal in interface OIndex
    • getDefinition

      public OIndexDefinition getDefinition()
      Specified by:
      getDefinition in interface OIndex
    • create

      public OIndex create(OIndexMetadata indexMetadat, boolean rebuild, OProgressListener progressListener)
      Specified by:
      create in interface OIndexInternal
    • getKeyTypes

      public OType[] getKeyTypes()
      Description copied from interface: OIndex
      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.
      Specified by:
      getKeyTypes in interface OIndex
    • iterator

      public Iterator<Map.Entry<Object,T>> iterator()
    • put

      public OIndex put(Object key, OIdentifiable value)
      Description copied from interface: OIndex
      Inserts a new entry in the index. The behaviour depends by the index implementation.
      Specified by:
      put in interface OIndex
      Parameters:
      key - Entry's key
      value - Entry's value as OIdentifiable instance
      Returns:
      The index instance itself to allow in chain calls
    • remove

      public boolean remove(Object key)
      Description copied from interface: OIndex
      Removes an entry by its key.
      Specified by:
      remove in interface OIndex
      Parameters:
      key - The entry's key to remove
      Returns:
      True if the entry has been found and removed, otherwise false
    • remove

      public boolean remove(Object key, OIdentifiable rid)
      Description copied from interface: OIndex
      Removes an entry by its key and value.
      Specified by:
      remove in interface OIndex
      Parameters:
      key - The entry's key to remove
      Returns:
      True if the entry has been found and removed, otherwise false
    • clear

      @Deprecated public OIndex clear()
      Deprecated.
      Manual indexes are deprecated and will be removed
      Clears the index removing all the entries in one shot.
      Specified by:
      clear in interface OIndex
      Returns:
      The index instance itself to allow in chain calls
    • getSize

      public long getSize()
      Specified by:
      getSize in interface OIndex
      Returns:
      number of entries in the index.
    • count

      public long count(Object iKey)
      Description copied from interface: OIndex
      Counts the entries for the key.
      Specified by:
      count in interface OIndex
    • getKeySize

      public long getKeySize()
      Specified by:
      getKeySize in interface OIndex
      Returns:
      Number of keys in index
    • flush

      public void flush()
      Description copied from interface: OIndex
      Flushes in-memory changes to disk.
      Specified by:
      flush in interface OIndex
    • getRebuildVersion

      public long getRebuildVersion()
      Specified by:
      getRebuildVersion in interface OIndex
    • isRebuilding

      public boolean isRebuilding()
      Specified by:
      isRebuilding in interface OIndex
      Returns:
      Indicates whether index is rebuilding at the moment.
      See Also:
    • getFirstKey

      public Object getFirstKey()
      Specified by:
      getFirstKey in interface OIndex
    • getLastKey

      public Object getLastKey()
      Specified by:
      getLastKey in interface OIndex
    • cursor

      public OIndexCursor cursor()
      Specified by:
      cursor in interface OIndex
    • descCursor

      public OIndexCursor descCursor()
      Specified by:
      descCursor in interface OIndex
    • keyCursor

      public OIndexKeyCursor keyCursor()
      Specified by:
      keyCursor in interface OIndex
    • getCollatingValue

      public Object getCollatingValue(Object key)
      Specified by:
      getCollatingValue in interface OIndexInternal
    • loadFromConfiguration

      public boolean loadFromConfiguration(ODocument iConfig)
      Description copied from interface: OIndexInternal
      Loads the index giving the configuration.
      Specified by:
      loadFromConfiguration in interface OIndexInternal
      Parameters:
      iConfig - ODocument instance containing the configuration
    • updateConfiguration

      public ODocument updateConfiguration()
      Description copied from interface: OIndexInternal
      Saves the index configuration to disk.
      Specified by:
      updateConfiguration in interface OIndexInternal
      Returns:
      The configuration as ODocument instance
      See Also:
    • addCluster

      public OIndex addCluster(String iClusterName)
      Description copied from interface: OIndexInternal
      Add given cluster to the list of clusters that should be automatically indexed.
      Specified by:
      addCluster in interface OIndexInternal
      Parameters:
      iClusterName - Cluster to add.
      Returns:
      Current index instance.
    • removeCluster

      public OIndex removeCluster(String iClusterName)
      Description copied from interface: OIndexInternal
      Remove given cluster from the list of clusters that should be automatically indexed.
      Specified by:
      removeCluster in interface OIndexInternal
      Parameters:
      iClusterName - Cluster to remove.
      Returns:
      Current index instance.
    • canBeUsedInEqualityOperators

      public boolean canBeUsedInEqualityOperators()
      Description copied from interface: OIndexInternal
      Indicates whether given index can be used to calculate result of OQueryOperatorEquality operators.
      Specified by:
      canBeUsedInEqualityOperators in interface OIndexInternal
      Returns:
      true if given index can be used to calculate result of OQueryOperatorEquality operators.
    • hasRangeQuerySupport

      public boolean hasRangeQuerySupport()
      Specified by:
      hasRangeQuerySupport in interface OIndexInternal
    • loadMetadata

      public OIndexMetadata loadMetadata(ODocument iConfig)
      Specified by:
      loadMetadata in interface OIndexInternal
    • close

      public void close()
      Specified by:
      close in interface OIndexInternal
    • getIndexNameByKey

      public String getIndexNameByKey(Object key)
      Description copied from interface: OIndexInternal
      Returns 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:
      getIndexNameByKey in interface OIndexInternal
      Parameters:
      key - the index key.
      Returns:
      The index name involved
    • acquireAtomicExclusiveLock

      public boolean acquireAtomicExclusiveLock(Object key)
      Description copied from interface: OIndexInternal
      Acquires 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 key to infer a more narrow lock scope, but that is not a requirement.

      Specified by:
      acquireAtomicExclusiveLock in interface OIndexInternal
      Parameters:
      key - the index key to lock.
      Returns:
      true if this index was locked entirely, false if this index locking is sensitive to the provided key and only some subset of this index was locked.
    • size

      public long size()
      Specified by:
      size in interface OIndexInternal
      Returns:
      number of entries in the index.
    • delete

      public OIndex delete()
      Description copied from interface: OIndex
      Delete the index.
      Specified by:
      delete in interface OIndex
      Returns:
      The index instance itself to allow in chain calls
    • getType

      public String getType()
      Description copied from interface: OIndex
      Returns the type of the index as string.
      Specified by:
      getType in interface OIndex
    • getAlgorithm

      public String getAlgorithm()
      Description copied from interface: OIndex
      Returns the engine of the index as string.
      Specified by:
      getAlgorithm in interface OIndex
    • isAutomatic

      public boolean isAutomatic()
      Description copied from interface: OIndex
      Tells 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:
      isAutomatic in interface OIndex
      Returns:
      True if the index is automatic, otherwise false
    • rebuild

      public long rebuild()
      Description copied from interface: OIndex
      Rebuilds an automatic index.
      Specified by:
      rebuild in interface OIndex
      Returns:
      The number of entries rebuilt
    • rebuild

      public long rebuild(OProgressListener iProgressListener)
      Description copied from interface: OIndex
      Populate the index with all the existent records.
      Specified by:
      rebuild in interface OIndex
    • getConfiguration

      public ODocument getConfiguration()
      Description copied from interface: OIndex
      Returns the index configuration.
      Specified by:
      getConfiguration in interface OIndex
      Returns:
      An ODocument object containing all the index properties
    • getMetadata

      public ODocument getMetadata()
      Specified by:
      getMetadata in interface OIndex
    • getClusters

      public Set<String> getClusters()
      Description copied from interface: OIndex
      Returns Names of clusters that will be indexed.
      Specified by:
      getClusters in interface OIndex
      Returns:
      Names of clusters that will be indexed.
    • iterateEntries

      public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder)
      Description copied from interface: OIndex
      Returns cursor which presents data associated with passed in keys.
      Specified by:
      iterateEntries in interface OIndex
      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: OIndex
      Returns cursor which presents subset of index data between passed in keys.
      Specified by:
      iterateEntriesBetween in interface OIndex
      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

      public OIndexCursor iterateEntriesMajor(Object fromKey, boolean fromInclusive, boolean ascOrder)
      Description copied from interface: OIndex
      Returns cursor which presents subset of data which associated with key which is greater than passed in key.
      Specified by:
      iterateEntriesMajor in interface OIndex
      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

      public OIndexCursor iterateEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder)
      Description copied from interface: OIndex
      Returns cursor which presents subset of data which associated with key which is less than passed in key.
      Specified by:
      iterateEntriesMinor in interface OIndex
      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:
      getIndexId in interface OIndexInternal
    • isUnique

      public boolean isUnique()
      Specified by:
      isUnique in interface OIndex
    • stream

      public Stream<ORawPair<Object,ORID>> stream()
      Specified by:
      stream in interface OIndexInternal
    • descStream

      public Stream<ORawPair<Object,ORID>> descStream()
      Specified by:
      descStream in interface OIndexInternal
    • keyStream

      public Stream<Object> keyStream()
      Specified by:
      keyStream in interface OIndexInternal
    • getVersion

      public int getVersion()
      Description copied from interface: OIndex
      Returns 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:
      getVersion in interface OIndex
      Returns:
      Returns binary format version for this index if possible, otherwise -1.
    • supportsOrderedIterations

      public boolean supportsOrderedIterations()
      Specified by:
      supportsOrderedIterations in interface OIndex
    • streamEntries

      public Stream<ORawPair<Object,ORID>> streamEntries(Collection<?> keys, boolean ascSortOrder)
      Description copied from interface: OIndexInternal
      Returns stream which presents data associated with passed in keys.
      Specified by:
      streamEntries in interface OIndexInternal
      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: OIndexInternal
      Returns stream which presents subset of index data between passed in keys.
      Specified by:
      streamEntriesBetween in interface OIndexInternal
      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: OIndexInternal
      Returns stream which presents subset of data which associated with key which is greater than passed in key.
      Specified by:
      streamEntriesMajor in interface OIndexInternal
      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: OIndexInternal
      Returns stream which presents subset of data which associated with key which is less than passed in key.
      Specified by:
      streamEntriesMinor in interface OIndexInternal
      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:
      isNativeTxSupported in interface OIndexInternal
    • interpretTxKeyChanges

      Specified by:
      interpretTxKeyChanges in interface OIndexInternal
    • doPut

      public void doPut(OAbstractPaginatedStorage storage, Object key, ORID rid)
      Specified by:
      doPut in interface OIndexInternal
    • doRemove

      public boolean doRemove(OAbstractPaginatedStorage storage, Object key, ORID rid)
      Specified by:
      doRemove in interface OIndexInternal
    • doRemove

      public boolean doRemove(OAbstractPaginatedStorage storage, Object key)
      Specified by:
      doRemove in interface OIndexInternal
    • compareTo

      public int compareTo(OIndex o)
      Specified by:
      compareTo in interface Comparable<T>