Class CreateForeignKey
java.lang.Object
com.northconcepts.datapipeline.jdbc.sql.SqlPart
com.northconcepts.datapipeline.sql.h2.H2SqlPart
com.northconcepts.datapipeline.sql.h2.CreateForeignKey
Generates an ALTER TABLE...ADD CONSTRAINT statement to add a foreign key constraint in H2.
Sample Generated SQL:
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
-
Constructor Summary
ConstructorsConstructorDescriptionCreateForeignKey(String constraintName, String primaryTableName, String foreignTableName) Constructs a CreateForeignKey with the specified constraint, primary table, and foreign table names. -
Method Summary
Modifier and TypeMethodDescriptionvoidcollectSqlFragment(CodeWriter writer) Writes this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.Returns the constraint name.Returns the foreign key column names.Returns the foreign table name.Returns the ON DELETE action.Returns the ON UPDATE action.Returns the primary key column names.Returns the primary table name.setConstraintName(String constraintName) Sets the constraint name.setForeignKeyColumnNames(String... foreignKeyColumnNames) Sets the foreign key column names.setForeignKeyColumnNames(List<String> foreignKeyColumnNames) Sets the foreign key column names.setForeignTableName(String foreignTableName) Sets the foreign table name.setOnDeleteAction(ForeignKeyAction onDeleteAction) Sets the ON DELETE action.setOnUpdateAction(ForeignKeyAction onUpdateAction) Sets the ON UPDATE action.setPretty(boolean pretty) Indicates if line breaks and indentations should be added to output DDL (default false).
Example output (pretty = true):
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
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 CASCADEsetPrimaryKeyColumnNames(String... primaryKeyColumnNames) Sets the primary key column names.setPrimaryKeyColumnNames(List<String> primaryKeyColumnNames) Sets the primary key column names.setPrimaryTableName(String primaryTableName) Sets the primary table name.Methods inherited from class com.northconcepts.datapipeline.sql.h2.H2SqlPart
escapeKeyword, placeBackTicksMethods inherited from class com.northconcepts.datapipeline.jdbc.sql.SqlPart
collectParameterValues, getParameterValues, getSqlFragment, isPretty, printSqlParts, toString
-
Constructor Details
-
CreateForeignKey
public CreateForeignKey() -
CreateForeignKey
Constructs a CreateForeignKey with the specified constraint, primary table, and foreign table names.- Parameters:
constraintName- the constraint nameprimaryTableName- the primary table nameforeignTableName- the foreign table name
-
-
Method Details
-
setPretty
Indicates if line breaks and indentations should be added to output DDL (default false).
Example output (pretty = true):
ALTER TABLE products
ADD CONSTRAINT fk_products_product_groups FOREIGN KEY (product_group_id)
REFERENCES product_groups
ON DELETE CASCADE
ON UPDATE CASCADE
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 -
collectSqlFragment
Description copied from class:SqlPartWrites this part's SQL to the writer; used bySqlPart.getSqlFragment()and by enclosing parts.- Specified by:
collectSqlFragmentin classSqlPart
-
getForeignTableName
Returns the foreign table name.- Returns:
- the foreign table name
-
setForeignTableName
Sets the foreign table name.- Parameters:
foreignTableName- the foreign table name- Returns:
- this instance
-
getPrimaryTableName
Returns the primary table name.- Returns:
- the primary table name
-
setPrimaryTableName
Sets the primary table name.- Parameters:
primaryTableName- the primary table name- Returns:
- this instance
-
getConstraintName
Returns the constraint name.- Returns:
- the constraint name
-
setConstraintName
Sets the constraint name.- Parameters:
constraintName- the constraint name- Returns:
- this instance
-
getForeignKeyColumnNames
Returns the foreign key column names.- Returns:
- the foreign key column names
-
setForeignKeyColumnNames
Sets the foreign key column names.- Parameters:
foreignKeyColumnNames- the foreign key column names- Returns:
- this instance
-
setForeignKeyColumnNames
Sets the foreign key column names.- Parameters:
foreignKeyColumnNames- the foreign key column names- Returns:
- this instance
-
getPrimaryKeyColumnNames
Returns the primary key column names.- Returns:
- the primary key column names
-
setPrimaryKeyColumnNames
Sets the primary key column names.- Parameters:
primaryKeyColumnNames- the primary key column names- Returns:
- this instance
-
setPrimaryKeyColumnNames
Sets the primary key column names.- Parameters:
primaryKeyColumnNames- the primary key column names- Returns:
- this instance
-
getOnUpdateAction
Returns the ON UPDATE action.- Returns:
- the ON UPDATE action
-
setOnUpdateAction
Sets the ON UPDATE action.- Parameters:
onUpdateAction- the ON UPDATE action- Returns:
- this instance
-
getOnDeleteAction
Returns the ON DELETE action.- Returns:
- the ON DELETE action
-
setOnDeleteAction
Sets the ON DELETE action.- Parameters:
onDeleteAction- the ON DELETE action- Returns:
- this instance
-