Class OIndexAbstract

java.lang.Object
com.orientechnologies.orient.core.index.OIndexAbstract
All Implemented Interfaces:
OIndex, OIndexInternal, Comparable<OIndex>
Direct Known Subclasses:
OIndexMultiValues, OIndexOneValue, OLuceneIndexNotUnique

public abstract class OIndexAbstract extends Object implements OIndexInternal
Handles indexing when records change. The underlying lock manager for keys can be the OPartitionedLockManager, the default one, or the OOneEntryPerKeyLockManager in case of distributed. This is to avoid deadlock situation between nodes where keys have the same hash code.
Author:
Luca Garulli (l.garulli--(at)--orientdb.com)
  • Field Details

    • CONFIG_MAP_RID

      protected static final String CONFIG_MAP_RID
      See Also:
    • storage

      protected final OStorage storage
    • indexId

      protected volatile int indexId
    • apiVersion

      protected volatile int apiVersion
    • im

      protected OIndexMetadata im
  • Constructor Details

  • Method Details

    • loadMetadataFromDoc

      public static OIndexMetadata loadMetadataFromDoc(ODocument config)
    • loadMetadataInternal

      public static OIndexMetadata loadMetadataInternal(ODocument config, String type, String algorithm, String valueContainerAlgorithm)
    • hasRangeQuerySupport

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

      public OIndexInternal create(OIndexMetadata indexMetadata, boolean rebuild, OProgressListener progressListener)
      Creates the index.
      Specified by:
      create in interface OIndexInternal
    • doReloadIndexEngine

      protected void doReloadIndexEngine()
    • loadFromConfiguration

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

      public OIndexMetadata loadMetadata(ODocument config)
      Specified by:
      loadMetadata in interface OIndexInternal
    • rebuild

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

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

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

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

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

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

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

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

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

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

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

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

      @Deprecated public OIndexKeyCursor keyCursor()
      Deprecated.
      Specified by:
      keyCursor in interface OIndex
    • iterateEntries

      @Deprecated public OIndexCursor iterateEntries(Collection<?> keys, boolean ascSortOrder)
      Deprecated.
      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

      @Deprecated public OIndexCursor iterateEntriesBetween(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive, boolean ascOrder)
      Deprecated.
      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

      @Deprecated public OIndexCursor iterateEntriesMajor(Object fromKey, boolean fromInclusive, boolean ascOrder)
      Deprecated.
      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

      @Deprecated public OIndexCursor iterateEntriesMinor(Object toKey, boolean toInclusive, boolean ascOrder)
      Deprecated.
      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.
    • rebuild

      public long rebuild(OProgressListener iProgressListener)
      Populate the index with all the existent records.
      Specified by:
      rebuild in interface OIndex
    • 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
    • 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
    • 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
    • delete

      public OIndexInternal 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
    • doDelete

      protected void doDelete()
    • 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
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getInternal

      public OIndexInternal getInternal()
      Description copied from interface: OIndex
      Returns the internal index used.
      Specified by:
      getInternal 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.
    • addCluster

      public OIndexAbstract addCluster(String clusterName)
      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:
      clusterName - Cluster to add.
      Returns:
      Current index instance.
    • removeCluster

      public OIndexAbstract 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.
    • 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.
    • 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:
    • interpretTxKeyChanges

      Interprets transaction index changes for a certain key. Override it to customize index behaviour on interpreting index changes. This may be viewed as an optimization, but in some cases this is a requirement. For example, if you put multiple values under the same key during the transaction for single-valued/unique index, but remove all of them except one before commit, there is no point in throwing ORecordDuplicatedException while applying index changes.
      Specified by:
      interpretTxKeyChanges in interface OIndexInternal
      Parameters:
      changes - the changes to interpret.
      Returns:
      the interpreted index key changes.
    • 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
    • isUnique

      public boolean isUnique()
      Specified by:
      isUnique 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
    • 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
    • keyStream

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

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getIndexId

      public int getIndexId()
      Specified by:
      getIndexId in interface OIndexInternal
    • getDatabaseName

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

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

      public int compareTo(OIndex index)
      Specified by:
      compareTo in interface Comparable<OIndex>
    • 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.
    • getDatabase

      protected static ODatabaseDocumentInternal getDatabase()
    • releaseExclusiveLock

      protected void releaseExclusiveLock()
    • acquireExclusiveLock

      protected void acquireExclusiveLock()
    • releaseSharedLock

      protected void releaseSharedLock()
    • acquireSharedLock

      protected void acquireSharedLock()
    • manualIndexesWarning

      public static void manualIndexesWarning()
    • enhanceToCompositeKeyBetweenAsc

      public Object enhanceToCompositeKeyBetweenAsc(Object keyTo, boolean toInclusive)
    • enhanceFromCompositeKeyBetweenAsc

      public Object enhanceFromCompositeKeyBetweenAsc(Object keyFrom, boolean fromInclusive)
    • enhanceToCompositeKeyBetweenDesc

      public Object enhanceToCompositeKeyBetweenDesc(Object keyTo, boolean toInclusive)
    • enhanceFromCompositeKeyBetweenDesc

      public Object enhanceFromCompositeKeyBetweenDesc(Object keyFrom, boolean fromInclusive)