Class MsConstraintPk

All Implemented Interfaces:
IConstraint, IConstraintPk, IOptionContainer, ISearchPath, ISimpleColumnContainer, IStatement, ISubElement, IHashable

public class MsConstraintPk extends MsConstraint implements IConstraintPk, IOptionContainer, ISimpleColumnContainer
Represents a Microsoft SQL PRIMARY KEY or UNIQUE constraint. Supports both clustered and non-clustered indexes with various options.
  • Constructor Details

    • MsConstraintPk

      public MsConstraintPk(String name, boolean isPrimaryKey)
      Creates a new Microsoft SQL PRIMARY KEY or UNIQUE constraint.
      Parameters:
      name - the constraint name
      isPrimaryKey - true for PRIMARY KEY, false for UNIQUE
  • Method Details

    • getDefinition

      public String getDefinition()
      Description copied from interface: IConstraint
      Gets the SQL definition of this constraint.
      Specified by:
      getDefinition in interface IConstraint
      Returns:
      the constraint definition
    • compareOptions

      public void compareOptions(IOptionContainer newContainer, SQLScript script)
      Description copied from interface: IOptionContainer
      Compares options between this container and a new container, generating SQL to update differences.
      Specified by:
      compareOptions in interface IOptionContainer
      Parameters:
      newContainer - the new container to compare against
      script - the script to append changes to
    • isPrimaryKey

      public boolean isPrimaryKey()
      Description copied from interface: IConstraint
      Checks if this constraint is a primary key constraint.
      Specified by:
      isPrimaryKey in interface IConstraint
      Returns:
      true if this is a primary key constraint
    • isClustered

      public boolean isClustered()
      Description copied from interface: IConstraintPk
      Checks if this primary key constraint is clustered.
      Specified by:
      isClustered in interface IConstraintPk
      Returns:
      true if the primary key is clustered
    • setClustered

      public void setClustered(boolean isClustered)
    • setDataSpace

      public void setDataSpace(String dataSpace)
    • getColumns

      public List<String> getColumns()
      Description copied from interface: IConstraint
      Gets the columns involved in this constraint.
      Specified by:
      getColumns in interface IConstraint
      Overrides:
      getColumns in class MsConstraint
      Returns:
      a collection of column names
    • containsColumn

      public boolean containsColumn(String name)
      Description copied from interface: IConstraint
      Checks if this constraint involves the specified column.
      Specified by:
      containsColumn in interface IConstraint
      Overrides:
      containsColumn in class MsConstraint
      Parameters:
      name - the column name to check
      Returns:
      true if the column is part of this constraint
    • addColumn

      public void addColumn(SimpleColumn column)
      Description copied from interface: ISimpleColumnContainer
      Adds a column reference to this container.
      Specified by:
      addColumn in interface ISimpleColumnContainer
      Parameters:
      column - the simple column to add
    • addInclude

      public void addInclude(String column)
      Throws an exception as include columns are not supported for primary key/unique constraints.
      Specified by:
      addInclude in interface ISimpleColumnContainer
      Parameters:
      column - the column name (not used)
      Throws:
      IllegalStateException - always, as this operation is unsupported
    • getOptions

      public Map<String,String> getOptions()
      Description copied from interface: IOptionContainer
      Gets all options for this container.
      Specified by:
      getOptions in interface IOptionContainer
      Returns:
      a map of option keys to values
    • addOption

      public void addOption(String key, String value)
      Description copied from interface: IOptionContainer
      Adds an option to this container.
      Specified by:
      addOption in interface IOptionContainer
      Parameters:
      key - the option key
      value - the option value
    • computeHash

      public void computeHash(Hasher hasher)
      Description copied from interface: IHashable
      Computes the hash of the implementing object using the provided hasher. The implementation should call appropriate put methods on the hasher for all fields that should contribute to the hash value.
      Specified by:
      computeHash in interface IHashable
      Overrides:
      computeHash in class MsConstraint
      Parameters:
      hasher - the hasher instance to use for hash computation
    • compare

      public boolean compare(IStatement obj)
      Description copied from class: AbstractStatement
      This method does not account for nested child PgStatements. Shallow version of AbstractStatement.equals(Object)
      Specified by:
      compare in interface IStatement
      Overrides:
      compare in class MsConstraint