Class Index

Direct Known Subclasses:
CompositeIndex, SimpleIndex

public abstract class Index extends SchemaItem
A simple or composite index on some field(s) an ObjType.
  • Method Details

    • getObjType

      public ObjType getObjType()
      Get the object type that contains the field(s) in this index.
      Returns:
      indexed fields' object type
    • getFields

      public List<SimpleField<?>> getFields()
      Get the indexed field(s).
      Returns:
      list of indexed fields
    • getEncodings

      public List<Encoding<?>> getEncodings()
      Get the field encoding(s).

      Note that the core API treats reference fields with the same name as the same field, regardless of their object type restrictions. Therefore, the encodings in an index corresponding to reference fields do not have type restrictions and therefore can be different from the encodings associated with the fields themselves.

      Returns:
      list of indexed fields
    • isComposite

      public boolean isComposite()
      Determine whether this is a composite index, i.e., and index on two or more fields.
      Returns:
      true if composite
    • getIndex

      public abstract AbstractCoreIndex<ObjId> getIndex(Transaction tx)
      Get this index's view of the given transaction.
      Parameters:
      tx - transaction
      Returns:
      view of this index in tx
      Throws:
      IllegalArgumentException - if tx is null
    • getKey

      public byte[] getKey(Object... values)
      Get the byte[] key in the underlying key/value store corresponding to the given value tuple in this index.

      The returned key will be the prefix of all index entries with the given value tuple over all objects.

      Parameters:
      values - indexed values
      Returns:
      the corresponding KVDatabase key
      Throws:
      IllegalArgumentException - if values is null
      IllegalArgumentException - if values has the wrong length for this index
      IllegalArgumentException - if any value in values has the wrong type
      See Also:
    • getKey

      public byte[] getKey(ObjId id, Object... values)
      Get the byte[] key in the underlying key/value store corresponding to the given value tuple and target object in this index.
      Parameters:
      id - target object ID
      values - indexed values
      Returns:
      the corresponding KVDatabase key
      Throws:
      IllegalArgumentException - if values is null
      IllegalArgumentException - if values has the wrong length for this index
      IllegalArgumentException - if any value in values has the wrong type
      See Also:
    • visit

      public abstract <R> R visit(IndexSwitch<R> target)
      Apply visitor pattern.
      Type Parameters:
      R - visitor return type
      Parameters:
      target - target to invoke
      Returns:
      return value from the method of target corresponding to this instance's type
      Throws:
      NullPointerException - if target is null
    • toString

      public String toString()
      Specified by:
      toString in class SchemaItem
    • genericize

      public static <T> Encoding<T> genericize(Encoding<T> encoding)
      Genericize the given encoding for use in a index.

      For encodings other than ReferenceEncoding, this just returns the given encoding unchanged. For ReferenceEncoding, this returns the encoding with all type restrictions removed. This is required because the type restrictions associated with reference fields are allowed to vary across schemas without changing the identity of the field. When querying indexes, reference fields are instead restricted according to the types specified in the query.

      Parameters:
      encoding - simple field encoding
      Returns:
      encoding genericized for use in an index, or encoding itself if no change is needed