Class Constraint

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

@Immutable public class Constraint extends Object implements DbObject, TableNameAware, ConstraintNameAware
A representation of constraint in a database.
Since:
0.11.0
See Also:
  • Constructor Details

    • Constraint

      protected Constraint(@Nonnull String tableName, @Nonnull String constraintName, @Nonnull 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.
  • Method Details

    • getName

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

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

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

      @Nonnull 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

      @Nonnull public ConstraintType getConstraintType()
      Retrieves type of constraint.
      Returns:
      type of constraint
      See Also:
    • equals

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

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

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

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

      @Nonnull public static Constraint ofType(@Nonnull String tableName, @Nonnull String constraintName, @Nonnull 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

      @Nonnull public static Constraint ofType(@Nonnull PgContext pgContext, @Nonnull String tableName, @Nonnull String constraintName, @Nonnull 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