Class Constraint

java.lang.Object
io.github.mfvanek.pg.model.constraint.Constraint
All Implemented Interfaces:
ConstraintNameAware, DbObject, TableNameAware

public final class Constraint extends Object implements DbObject, ConstraintNameAware
An immutable representation of constraint in a database.
Since:
0.11.0
See Also:
  • Method Details

    • getName

      public String getName()
      Retrieves database object name.
      Specified by:
      getName in interface DbObject
      Returns:
      database object name
    • getObjectType

      public PgObjectType getObjectType()
      Retrieves database object type.
      Specified by:
      getObjectType in interface DbObject
      Returns:
      database object type
    • getTableName

      public String getTableName()
      Retrieves table name.
      Specified by:
      getTableName in interface TableNameAware
      Returns:
      table name
    • getConstraintName

      public String getConstraintName()
      Retrieves the name of the database constraint associated with this entity.
      Specified by:
      getConstraintName in interface ConstraintNameAware
      Returns:
      the name of the constraint as a non-null String.
    • getConstraintType

      public ConstraintType getConstraintType()
      Retrieves type of constraint.
      Specified by:
      getConstraintType in interface ConstraintNameAware
      Returns:
      type of constraint
      See Also:
    • equals

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

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

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

      public String getValidateSql()
      Builds and returns sql query to validate current constraint.
      Returns:
      sql query to validate current constraint
      See Also:
    • ofType

      public static Constraint ofType(String tableName, String constraintName, ConstraintType constraintType)
      Constructs a Constraint object with given ConstraintType.
      Parameters:
      tableName - table name; should be non-blank.
      constraintName - constraint name; should be non-blank.
      constraintType - constraint type; should be non-null.
      Returns:
      Constraint
    • ofType

      public static Constraint ofType(PgContext pgContext, String tableName, String constraintName, ConstraintType constraintType)
      Constructs a Constraint object with given ConstraintType and context.
      Parameters:
      pgContext - the schema context to enrich table name; must be non-null.
      tableName - table name; should be non-blank.
      constraintName - constraint name; should be non-blank.
      constraintType - constraint type; should be non-null.
      Returns:
      Constraint
      Since:
      0.14.3