Package org.pgcodekeeper.core.schema.pg
Class PgConstraintPk
java.lang.Object
org.pgcodekeeper.core.schema.PgStatement
org.pgcodekeeper.core.schema.AbstractConstraint
org.pgcodekeeper.core.schema.pg.PgConstraint
org.pgcodekeeper.core.schema.pg.PgConstraintPk
- All Implemented Interfaces:
IHashable,IConstraint,IConstraintPk,ISearchPath,IStatement,PgIndexParamContainer
public final class PgConstraintPk
extends PgConstraint
implements IConstraintPk, PgIndexParamContainer
PostgreSQL PRIMARY KEY and UNIQUE constraint implementation.
Primary key constraints uniquely identify each row and cannot contain NULL values.
Unique constraints ensure no duplicate values but can contain NULLs.
-
Field Summary
Fields inherited from class org.pgcodekeeper.core.schema.PgStatement
GO -
Constructor Summary
ConstructorsConstructorDescriptionPgConstraintPk(String name, boolean isPrimaryKey) Creates a new PostgreSQL PRIMARY KEY or UNIQUE constraint. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a column to this constraint.voidaddInclude(String include) Adds a column to the INCLUDE clause of the index.voidAdds an index parameter (WITH clause option).booleancompare(PgStatement obj) This method does not account for nested child PgStatements.voidcomputeHash(Hasher hasher) Computes the hash of the implementing object using the provided hasher.Gets the columns involved in this constraint.Gets the SQL definition of this constraint.booleanChecks if this primary key constraint is clustered.booleanChecks if this constraint is a primary key constraint.voidsetClustered(boolean isClustered) voidsetDistinct(boolean isDistinct) voidsetTablespace(String tablespace) Sets the tablespace for this index.Methods inherited from class org.pgcodekeeper.core.schema.pg.PgConstraint
appendAlterSQL, getCreationSQL, getDropSQL, setDeferrable, setInitially, shallowCopyMethods inherited from class org.pgcodekeeper.core.schema.AbstractConstraint
containsColumn, getContainingSchema, getLocation, getStatementType, getTableName, isNotValid, isSubElement, setNotValidMethods inherited from class org.pgcodekeeper.core.schema.PgStatement
addAllDeps, addDep, addPrivilege, appendAlterComments, appendComments, appendOwnerSQL, canDrop, canDropBeforeCreate, checkComments, clearPrivileges, compareChildren, deepCopy, equals, getAuthor, getBareName, getChildren, getComment, getDbType, getDeps, getDescendants, getDropSQL, getLibName, getName, getObjectState, getObjectState, getOwner, getParent, getPrivileges, getQualifiedName, getSQL, getTwin, getTypeName, hasChildren, hashCode, isLib, isOwned, setAuthor, setComment, setLibName, setLocation, setOwner, setParent, toStringMethods inherited from interface org.pgcodekeeper.core.schema.IConstraint
containsColumn, getTableNameMethods inherited from interface org.pgcodekeeper.core.schema.ISearchPath
getContainingSchema, getDatabase, getSchemaNameMethods inherited from interface org.pgcodekeeper.core.schema.IStatement
getBareName, getComment, getName, getParent, getQualifiedName, getStatementType
-
Constructor Details
-
PgConstraintPk
Creates a new PostgreSQL PRIMARY KEY or UNIQUE constraint.- Parameters:
name- constraint nameisPrimaryKey- true for PRIMARY KEY, false for UNIQUE
-
-
Method Details
-
setDistinct
public void setDistinct(boolean isDistinct) -
addInclude
Description copied from interface:PgIndexParamContainerAdds a column to the INCLUDE clause of the index.- Specified by:
addIncludein interfacePgIndexParamContainer- Parameters:
include- column name to include
-
addParam
Description copied from interface:PgIndexParamContainerAdds an index parameter (WITH clause option).- Specified by:
addParamin interfacePgIndexParamContainer- Parameters:
key- parameter namevalue- parameter value
-
setTablespace
Description copied from interface:PgIndexParamContainerSets the tablespace for this index.- Specified by:
setTablespacein interfacePgIndexParamContainer- Parameters:
tablespace- tablespace name
-
isPrimaryKey
public boolean isPrimaryKey()Description copied from interface:IConstraintChecks if this constraint is a primary key constraint.- Specified by:
isPrimaryKeyin interfaceIConstraint- Returns:
- true if this is a primary key constraint
-
isClustered
public boolean isClustered()Description copied from interface:IConstraintPkChecks if this primary key constraint is clustered.- Specified by:
isClusteredin interfaceIConstraintPk- Returns:
- true if the primary key is clustered
-
setClustered
public void setClustered(boolean isClustered) -
getColumns
Description copied from interface:IConstraintGets the columns involved in this constraint.- Specified by:
getColumnsin interfaceIConstraint- Overrides:
getColumnsin classAbstractConstraint- Returns:
- a collection of column names
-
addColumn
Adds a column to this constraint.- Parameters:
column- column name
-
getErrorCode
-
getDefinition
Description copied from interface:IConstraintGets the SQL definition of this constraint.- Specified by:
getDefinitionin interfaceIConstraint- Returns:
- the constraint definition
-
compare
Description copied from class:PgStatementThis method does not account for nested child PgStatements. Shallow version ofPgStatement.equals(Object)- Overrides:
comparein classPgConstraint
-
computeHash
Description copied from interface:IHashableComputes the hash of the implementing object using the provided hasher. The implementation should call appropriateputmethods on the hasher for all fields that should contribute to the hash value.- Specified by:
computeHashin interfaceIHashable- Overrides:
computeHashin classPgConstraint- Parameters:
hasher- the hasher instance to use for hash computation
-