All Implemented Interfaces:
DataExceptionContributor, JsonSerializable, RecordSerializable, XmlSerializable, SchemaProblemsSupplier, JavaCodeGenerator, Serializable, Cloneable

public class IndexDef extends SchemaPart implements Cloneable, SchemaProblemsSupplier, JavaCodeGenerator
The metadata model for an entity's index.
See Also:
  • Constructor Details

    • IndexDef

      public IndexDef()
    • IndexDef

      public IndexDef(String name, String... indexFieldNames)
      Creates an index on the named entity fields, each in ascending order.
  • Method Details

    • getSchemaProblems

      public void getSchemaProblems(List<SchemaProblem> problems, boolean includeChildren)
      Description copied from interface: SchemaProblemsSupplier
      Adds this element's problems to the list, plus those of its children when includeChildren is true; the default adds none.
      Specified by:
      getSchemaProblems in interface SchemaProblemsSupplier
    • clone

      public IndexDef clone()
      Overrides:
      clone in class FoundationObject
    • generateJavaCode

      public void generateJavaCode(JavaCodeBuilder code)
      Description copied from interface: JavaCodeGenerator
      Appends Java source code representing this object to the given builder.
      Specified by:
      generateJavaCode in interface JavaCodeGenerator
    • getSchemaDef

      public SchemaDef getSchemaDef(boolean throwException)
      Returns the schema of the entity containing this index; if either is missing, throws a DataException when throwException is true and returns null otherwise.
    • getSchemaDef

      public SchemaDef getSchemaDef()
      The schema of the parent entity containing this field.
      Specified by:
      getSchemaDef in class SchemaPart
    • getSchemaPartContainer

      public SchemaPart getSchemaPartContainer()
      Description copied from class: SchemaPart
      Returns the schema part containing this one or null if there is none.
      Specified by:
      getSchemaPartContainer in class SchemaPart
    • getSchemaPartType

      public SchemaPartType getSchemaPartType()
      Description copied from class: SchemaPart
      Returns the kind of part this is, such as SchemaPartType.ENTITY.
      Specified by:
      getSchemaPartType in class SchemaPart
    • getSchemaPartName

      public String getSchemaPartName()
      Description copied from class: SchemaPart
      Returns the name identifying this part, such as an entity's name or an index field's field name.
      Specified by:
      getSchemaPartName in class SchemaPart
    • getEntityDef

      public EntityDef getEntityDef()
      Returns the entity containing this index or null if it has not been added to one.
    • setEntityDef

      protected IndexDef setEntityDef(EntityDef entityDef)
      Sets the parent entity; called by EntityDef when this index is added to it.
    • getName

      public String getName()
    • setName

      public IndexDef setName(String name)
    • getQualifiedName

      public String getQualifiedName()
      Returns the fully qualified name that includes the name of this index and all names in its hierarchy separated by period.
    • getEntityQualifiedName

      public String getEntityQualifiedName()
      Returns the qualified name that includes the name of this index and the EntityDef above it separated by period.
    • getDescription

      public String getDescription()
    • setDescription

      public IndexDef setDescription(String description)
    • isUnique

      public boolean isUnique()
    • setUnique

      public IndexDef setUnique(boolean unique)
    • isPrimaryKeyIndex

      public boolean isPrimaryKeyIndex()
      Returns true if this index has exactly the entity's primary key fields, in key order and all ascending.
    • containsField

      public boolean containsField(String name)
      Returns true if this index contains an IndexFieldDef with the specified name.
    • getIndexFieldCount

      public int getIndexFieldCount()
      Returns the number of index fields in this index.
    • getIndexFieldNames

      public List<String> getIndexFieldNames()
      Returns the names of all index fields in this index.
    • getIndexFields

      public List<IndexFieldDef> getIndexFields(boolean create)
      Returns the index fields, creating the list if it is null and create is true.
    • getIndexField

      public IndexFieldDef getIndexField(String name)
      Returns the IndexFieldDef that matches the specified name.
    • getIndexFields

      public List<IndexFieldDef> getIndexFields()
      Returns the index fields or null if none were added.
    • setIndexFields

      public IndexDef setIndexFields(List<IndexFieldDef> indexFields)
      Replaces the index fields with the given list (not copied) and makes this index their parent.
    • addIndexField

      public IndexDef addIndexField(IndexFieldDef indexField)
      Appends the index field and makes this index its parent.
    • addIndexFields

      public IndexDef addIndexFields(String... indexFieldNames)
      Appends an ascending index field for each of the named entity fields; a null or empty array is ignored.
    • toXmlElement

      public Element toXmlElement(Document document)
      Description copied from interface: XmlSerializable
      Returns an element, created with document, describing this object; the default implementation throws a DataException.
      Specified by:
      toXmlElement in interface XmlSerializable
    • fromXmlElement

      public IndexDef fromXmlElement(Element indexDefElement)
      Specified by:
      fromXmlElement in interface XmlSerializable
    • toJson

      public String toJson()
      Specified by:
      toJson in interface JsonSerializable
      Specified by:
      toJson in interface RecordSerializable
    • toRecord

      public Record toRecord()
      Description copied from interface: RecordSerializable
      Converts this object's state to a record that RecordSerializable.fromRecord(Record) can load.
      Specified by:
      toRecord in interface RecordSerializable
      Overrides:
      toRecord in class Bean
    • fromRecord

      public IndexDef fromRecord(Record source)
      Description copied from interface: RecordSerializable
      Loads this instance's state from a record and returns this (for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.
      Specified by:
      fromRecord in interface RecordSerializable
      Overrides:
      fromRecord in class Bean
      Parameters:
      source -
      Returns:
      this instance.
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • indexOfField

      public int indexOfField(String indexFieldName)
      Returns the zero-based position of the IndexDef with the specified name or -1 if it is not found.
    • indexOfField

      public int indexOfField(String indexFieldName, boolean throwExceptionOnFailure)
      Returns the zero-based position of the IndexFieldDef with the specified name or -1 if it is not found and throwExceptionOnFailure is false, otherwise a DataException is thrown.
    • moveField

      public void moveField(int oldIndex, int newIndex)
      Moves the index field at the oldIndex to the newIndex, shifting any existing elements at or after newIndex to the right.
    • moveField

      public void moveField(String fieldName, int newIndex)
      Moves the index field with the given name to the newIndex, shifting any existing elements at or after newIndex to the right.
    • moveFieldBefore

      public void moveFieldBefore(String fieldName, String beforeFieldName)
      Moves the index field with the given fieldName before to the index field with the specified beforeFieldName, shifting elements at or after beforeFieldName to the right.
    • moveFieldAfter

      public void moveFieldAfter(String fieldName, String afterFieldName)
      Moves the index field with the given fieldName after to the index field with the specified afterFieldName, shifting any existing elements after afterFieldName to the right.