public class CreateForeignKey extends H2SqlPart
Generates an ALTER TABLE...ADD CONSTRAINT statement to add a foreign key constraint in H2.
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
| Constructor and Description |
|---|
CreateForeignKey() |
CreateForeignKey(String constraintName,
String primaryTableName,
String foreignTableName)
Constructs a CreateForeignKey with the specified constraint, primary table, and foreign table names.
|
| Modifier and Type | Method and Description |
|---|---|
void |
collectSqlFragment(CodeWriter writer) |
String |
getConstraintName()
Returns the constraint name.
|
List<String> |
getForeignKeyColumnNames()
Returns the foreign key column names.
|
String |
getForeignTableName()
Returns the foreign table name.
|
ForeignKeyAction |
getOnDeleteAction()
Returns the ON DELETE action.
|
ForeignKeyAction |
getOnUpdateAction()
Returns the ON UPDATE action.
|
List<String> |
getPrimaryKeyColumnNames()
Returns the primary key column names.
|
String |
getPrimaryTableName()
Returns the primary table name.
|
CreateForeignKey |
setConstraintName(String constraintName)
Sets the constraint name.
|
CreateForeignKey |
setForeignKeyColumnNames(List<String> foreignKeyColumnNames)
Sets the foreign key column names.
|
CreateForeignKey |
setForeignKeyColumnNames(String... foreignKeyColumnNames)
Sets the foreign key column names.
|
CreateForeignKey |
setForeignTableName(String foreignTableName)
Sets the foreign table name.
|
CreateForeignKey |
setOnDeleteAction(ForeignKeyAction onDeleteAction)
Sets the ON DELETE action.
|
CreateForeignKey |
setOnUpdateAction(ForeignKeyAction onUpdateAction)
Sets the ON UPDATE action.
|
CreateForeignKey |
setPretty(boolean pretty)
Indicates if line breaks and indentations should be added to output DDL (default false).
Example output (pretty = true):
ALTER TABLE products
Example output (pretty = false): ALTER TABLE products ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id) REFERENCES product_groups ON DELETE CASCADE ON UPDATE CASCADE |
CreateForeignKey |
setPrimaryKeyColumnNames(List<String> primaryKeyColumnNames)
Sets the primary key column names.
|
CreateForeignKey |
setPrimaryKeyColumnNames(String... primaryKeyColumnNames)
Sets the primary key column names.
|
CreateForeignKey |
setPrimaryTableName(String primaryTableName)
Sets the primary table name.
|
escapeKeyword, placeBackTickscollectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toStringpublic CreateForeignKey()
public CreateForeignKey(String constraintName, String primaryTableName, String foreignTableName)
constraintName - the constraint nameprimaryTableName - the primary table nameforeignTableName - the foreign table namepublic CreateForeignKey setPretty(boolean pretty)
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
ALTER TABLE products ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id) REFERENCES product_groups ON DELETE CASCADE ON UPDATE CASCADEpublic void collectSqlFragment(CodeWriter writer)
collectSqlFragment in class SqlPartpublic String getForeignTableName()
public CreateForeignKey setForeignTableName(String foreignTableName)
foreignTableName - the foreign table namepublic String getPrimaryTableName()
public CreateForeignKey setPrimaryTableName(String primaryTableName)
primaryTableName - the primary table namepublic String getConstraintName()
public CreateForeignKey setConstraintName(String constraintName)
constraintName - the constraint namepublic List<String> getForeignKeyColumnNames()
public CreateForeignKey setForeignKeyColumnNames(List<String> foreignKeyColumnNames)
foreignKeyColumnNames - the foreign key column namespublic CreateForeignKey setForeignKeyColumnNames(String... foreignKeyColumnNames)
foreignKeyColumnNames - the foreign key column namespublic List<String> getPrimaryKeyColumnNames()
public CreateForeignKey setPrimaryKeyColumnNames(List<String> primaryKeyColumnNames)
primaryKeyColumnNames - the primary key column namespublic CreateForeignKey setPrimaryKeyColumnNames(String... primaryKeyColumnNames)
primaryKeyColumnNames - the primary key column namespublic ForeignKeyAction getOnUpdateAction()
public CreateForeignKey setOnUpdateAction(ForeignKeyAction onUpdateAction)
onUpdateAction - the ON UPDATE actionpublic ForeignKeyAction getOnDeleteAction()
public CreateForeignKey setOnDeleteAction(ForeignKeyAction onDeleteAction)
onDeleteAction - the ON DELETE actionCopyright (c) 2006-2026 North Concepts Inc. All Rights Reserved.