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 Summary
ConstructorsModifierConstructorDescriptionprotectedConstraint(String tableName, String constraintName, ConstraintType constraintType) Constructs aConstraintobject with givenConstraintType. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanRetrieves the name of the database constraint associated with this entity.Retrieves type of constraint.final StringgetName()Retrieves database object name.final PgObjectTypeRetrieves database object type.Retrieves table name.Builds and returns sql query to validate current constraint.final inthashCode()static ConstraintofType(String tableName, String constraintName, ConstraintType constraintType) Constructs aConstraintobject with givenConstraintType.toString()
-
Constructor Details
-
Constraint
protected Constraint(@Nonnull String tableName, @Nonnull String constraintName, @Nonnull ConstraintType constraintType) Constructs aConstraintobject with givenConstraintType.- 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
Retrieves database object name. -
getObjectType
Retrieves database object type.- Specified by:
getObjectTypein interfaceDbObject- Returns:
- database object type
-
getTableName
Retrieves table name.- Specified by:
getTableNamein interfaceTableNameAware- Returns:
- table name
-
getConstraintName
Retrieves the name of the database constraint associated with this entity.- Specified by:
getConstraintNamein interfaceConstraintNameAware- Returns:
- the name of the constraint as a non-null
String.
-
getConstraintType
Retrieves type of constraint.- Returns:
- type of constraint
- See Also:
-
equals
-
hashCode
public final int hashCode() -
toString
-
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 aConstraintobject with givenConstraintType.- Parameters:
tableName- table name; should be non-blank.constraintName- constraint name; should be non-blank.constraintType- constraint type; should be non-null.- Returns:
Constraint
-