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 booleancheckExistingprivate ExpressioncheckExpressionprivate java.lang.Stringcommentprivate java.lang.StringconstraintNameprivate java.util.ArrayList<Index>createdIndexesprivate ConstraintUniquecreatedUniqueConstraintprivate ConstraintActionTypedeleteActionprivate booleanifNotExistsprivate Indexindexprivate IndexColumn[]indexColumnsprivate booleanprimaryKeyHashprivate IndexrefIndexprivate IndexColumn[]refIndexColumnsprivate SchemarefSchemaprivate java.lang.StringrefTableNameprivate inttypeprivate ConstraintActionTypeupdateAction-
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 voidaddConstraintToTable(Database db, Table table, Constraint constraint)private static booleancanUseIndex(Index index, Table table, IndexColumn[] cols, boolean unique)private IndexcreateIndex(Table t, IndexColumn[] cols, boolean unique)private ConstraintUniquecreateUniqueConstraint(Table table, Index index, IndexColumn[] indexColumns, boolean forForeignKey)private java.lang.StringgenerateConstraintName(Table table)java.lang.StringgetConstraintName()private static IndexgetIndex(Table t, IndexColumn[] cols, boolean unique)IndexColumn[]getIndexColumns()intgetType()Get the command type as defined in CommandInterfaceprivate static ConstraintUniquegetUniqueConstraint(Table t, IndexColumn[] cols)voidsetCheckExisting(boolean b)voidsetCheckExpression(Expression expression)voidsetComment(java.lang.String comment)voidsetConstraintName(java.lang.String constraintName)voidsetDeleteAction(ConstraintActionType action)voidsetIndex(Index index)voidsetIndexColumns(IndexColumn[] indexColumns)voidsetPrimaryKeyHash(boolean b)voidsetRefIndex(Index refIndex)voidsetRefIndexColumns(IndexColumn[] indexColumns)voidsetRefTableName(Schema refSchema, java.lang.String ref)Set the referenced table.voidsetUpdateAction(ConstraintActionType action)private inttryUpdate(Table table)Try to execute the statement.longupdate(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:
updatein 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:PreparedGet 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)
-
-