Package org.h2.command.ddl
Class AlterTableAddConstraint
- java.lang.Object
-
- org.h2.command.Prepared
-
- org.h2.command.ddl.DefineCommand
-
- org.h2.command.ddl.SchemaCommand
-
- org.h2.command.ddl.AlterTable
-
- org.h2.command.ddl.AlterTableAddConstraint
-
public class AlterTableAddConstraint extends AlterTable
This class represents the statement ALTER TABLE ADD CONSTRAINT
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
checkExisting
private Expression
checkExpression
private java.lang.String
comment
private java.lang.String
constraintName
private java.util.ArrayList<Index>
createdIndexes
private ConstraintUnique
createdUniqueConstraint
private ConstraintActionType
deleteAction
private boolean
ifNotExists
private Index
index
private IndexColumn[]
indexColumns
private boolean
primaryKeyHash
private Index
refIndex
private IndexColumn[]
refIndexColumns
private Schema
refSchema
private java.lang.String
refTableName
private int
type
private ConstraintActionType
updateAction
-
Fields inherited from class org.h2.command.ddl.AlterTable
ifTableExists, tableName
-
Fields inherited from class org.h2.command.ddl.DefineCommand
transactional
-
Fields inherited from class org.h2.command.Prepared
create, parameters, prepareAlways, session, sqlStatement, sqlTokens
-
-
Constructor Summary
Constructors Constructor Description AlterTableAddConstraint(SessionLocal session, Schema schema, int type, boolean ifNotExists)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addConstraintToTable(Database db, Table table, Constraint constraint)
private static boolean
canUseIndex(Index index, Table table, IndexColumn[] cols, boolean unique)
private Index
createIndex(Table t, IndexColumn[] cols, boolean unique)
private ConstraintUnique
createUniqueConstraint(Table table, Index index, IndexColumn[] indexColumns, boolean forForeignKey)
private java.lang.String
generateConstraintName(Table table)
java.lang.String
getConstraintName()
private static Index
getIndex(Table t, IndexColumn[] cols, boolean unique)
IndexColumn[]
getIndexColumns()
int
getType()
Get the command type as defined in CommandInterfaceprivate static ConstraintUnique
getUniqueConstraint(Table t, IndexColumn[] cols)
void
setCheckExisting(boolean b)
void
setCheckExpression(Expression expression)
void
setComment(java.lang.String comment)
void
setConstraintName(java.lang.String constraintName)
void
setDeleteAction(ConstraintActionType action)
void
setIndex(Index index)
void
setIndexColumns(IndexColumn[] indexColumns)
void
setPrimaryKeyHash(boolean b)
void
setRefIndex(Index refIndex)
void
setRefIndexColumns(IndexColumn[] indexColumns)
void
setRefTableName(Schema refSchema, java.lang.String ref)
Set the referenced table.void
setUpdateAction(ConstraintActionType action)
private int
tryUpdate(Table table)
Try to execute the statement.long
update(Table table)
-
Methods inherited from class org.h2.command.ddl.AlterTable
setIfTableExists, setTableName, update
-
Methods inherited from class org.h2.command.ddl.SchemaCommand
getSchema
-
Methods inherited from class org.h2.command.ddl.DefineCommand
isReadOnly, isTransactional, queryMeta, setTransactional
-
Methods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, collectDependencies, getCteCleanups, getCurrentRowNumber, getObjectId, getParameters, getPersistedObjectId, getPlanSQL, getSession, getSimpleSQL, getSQL, getSQLTokens, isCacheable, isQuery, needRecompile, prepare, query, setCommand, setCteCleanups, setCurrentRowNumber, setParameterList, setPersistedObjectId, setPrepareAlways, setRow, setSession, setSQL, toString
-
-
-
-
Field Detail
-
type
private final int type
-
constraintName
private java.lang.String constraintName
-
indexColumns
private IndexColumn[] indexColumns
-
deleteAction
private ConstraintActionType deleteAction
-
updateAction
private ConstraintActionType updateAction
-
refSchema
private Schema refSchema
-
refTableName
private java.lang.String refTableName
-
refIndexColumns
private IndexColumn[] refIndexColumns
-
checkExpression
private Expression checkExpression
-
index
private Index index
-
refIndex
private Index refIndex
-
comment
private java.lang.String comment
-
checkExisting
private boolean checkExisting
-
primaryKeyHash
private boolean primaryKeyHash
-
ifNotExists
private final boolean ifNotExists
-
createdIndexes
private final java.util.ArrayList<Index> createdIndexes
-
createdUniqueConstraint
private ConstraintUnique createdUniqueConstraint
-
-
Constructor Detail
-
AlterTableAddConstraint
public AlterTableAddConstraint(SessionLocal session, Schema schema, int type, boolean ifNotExists)
-
-
Method Detail
-
generateConstraintName
private java.lang.String generateConstraintName(Table table)
-
update
public long update(Table table)
- Specified by:
update
in classAlterTable
-
tryUpdate
private int tryUpdate(Table table)
Try to execute the statement.- Returns:
- the update count
-
createUniqueConstraint
private ConstraintUnique createUniqueConstraint(Table table, Index index, IndexColumn[] indexColumns, boolean forForeignKey)
-
addConstraintToTable
private void addConstraintToTable(Database db, Table table, Constraint constraint)
-
createIndex
private Index createIndex(Table t, IndexColumn[] cols, boolean unique)
-
setDeleteAction
public void setDeleteAction(ConstraintActionType action)
-
setUpdateAction
public void setUpdateAction(ConstraintActionType action)
-
getUniqueConstraint
private static ConstraintUnique getUniqueConstraint(Table t, IndexColumn[] cols)
-
getIndex
private static Index getIndex(Table t, IndexColumn[] cols, boolean unique)
-
canUseIndex
private static boolean canUseIndex(Index index, Table table, IndexColumn[] cols, boolean unique)
-
setConstraintName
public void setConstraintName(java.lang.String constraintName)
-
getConstraintName
public java.lang.String getConstraintName()
-
getType
public int getType()
Description copied from class:Prepared
Get the command type as defined in CommandInterface
-
setCheckExpression
public void setCheckExpression(Expression expression)
-
setIndexColumns
public void setIndexColumns(IndexColumn[] indexColumns)
-
getIndexColumns
public IndexColumn[] getIndexColumns()
-
setRefTableName
public void setRefTableName(Schema refSchema, java.lang.String ref)
Set the referenced table.- Parameters:
refSchema
- the schemaref
- the table name
-
setRefIndexColumns
public void setRefIndexColumns(IndexColumn[] indexColumns)
-
setIndex
public void setIndex(Index index)
-
setRefIndex
public void setRefIndex(Index refIndex)
-
setComment
public void setComment(java.lang.String comment)
-
setCheckExisting
public void setCheckExisting(boolean b)
-
setPrimaryKeyHash
public void setPrimaryKeyHash(boolean b)
-
-