Package org.hibernate.dialect.unique
Class CreateTableUniqueDelegate
- java.lang.Object
-
- org.hibernate.dialect.unique.AlterTableUniqueDelegate
-
- org.hibernate.dialect.unique.CreateTableUniqueDelegate
-
- All Implemented Interfaces:
UniqueDelegate
- Direct Known Subclasses:
SkipNullableUniqueDelegate
public class CreateTableUniqueDelegate extends AlterTableUniqueDelegate
AUniqueDelegate
which includes the unique constraint in thecreate table
statement, except when called during schema migration.- For columns marked unique, this results
in a
unique
column definition. - For named unique keys, it results
in
constraint abc unique(a,b,c)
after the column list increate table
. - For unique keys with no explicit name, it results in
unique(x, y)
after the column list.
Counterintuitively, this class extends
AlterTableUniqueDelegate
, since it falls back to usingalter table
for schema migration.
-
-
Field Summary
-
Fields inherited from class org.hibernate.dialect.unique.AlterTableUniqueDelegate
dialect
-
-
Constructor Summary
Constructors Constructor Description CreateTableUniqueDelegate(Dialect dialect)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendUniqueConstraint(StringBuilder fragment, UniqueKey uniqueKey)
String
getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context)
Get thealter table
command used to create the given unique key constraint, or return the empty string if the constraint was already included in thecreate table
statement byUniqueDelegate.getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table, org.hibernate.boot.model.relational.SqlStringGenerationContext)
.String
getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context)
Get thealter table
command used to drop the given unique key which was previously created byUniqueDelegate.getAlterTableToAddUniqueKeyCommand(org.hibernate.mapping.UniqueKey, org.hibernate.boot.Metadata, org.hibernate.boot.model.relational.SqlStringGenerationContext)
.String
getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context)
Get the SQL fragment used to make the given column unique as part of its column definition, usually just" unique"
, or return an empty string if uniqueness does not belong in the column definition.String
getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context)
Get the SQL fragment used to specify the unique constraints on the given table as part of thecreate table
command, with a leading comma, usually something like:-
Methods inherited from class org.hibernate.dialect.unique.AlterTableUniqueDelegate
uniqueConstraintSql
-
-
-
-
Constructor Detail
-
CreateTableUniqueDelegate
public CreateTableUniqueDelegate(Dialect dialect)
-
-
Method Detail
-
getColumnDefinitionUniquenessFragment
public String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context)
Description copied from interface:UniqueDelegate
Get the SQL fragment used to make the given column unique as part of its column definition, usually just" unique"
, or return an empty string if uniqueness does not belong in the column definition.This is for handling single columns explicitly marked unique, not for dealing with unique keys.
- Specified by:
getColumnDefinitionUniquenessFragment
in interfaceUniqueDelegate
- Overrides:
getColumnDefinitionUniquenessFragment
in classAlterTableUniqueDelegate
- Parameters:
column
- The column to which to apply the uniquecontext
- A context for SQL string generation- Returns:
- The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a different approach
-
getTableCreationUniqueConstraintsFragment
public String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context)
Description copied from interface:UniqueDelegate
Get the SQL fragment used to specify the unique constraints on the given table as part of thecreate table
command, with a leading comma, usually something like:, unique(x,y), constraint abc unique(a,b,c)
or return an empty string if there are no unique constraints or if the unique constraints do not belong in the table definition.
The implementation should iterate over the unique keys of the given table by calling
Table.getUniqueKeys()
and generate a fragment which includes all the unique key declarations.- Specified by:
getTableCreationUniqueConstraintsFragment
in interfaceUniqueDelegate
- Overrides:
getTableCreationUniqueConstraintsFragment
in classAlterTableUniqueDelegate
- Parameters:
table
- The table for which to generate the unique constraints fragmentcontext
- A context for SQL string generation- Returns:
- The fragment, typically in the form
", unique(col1, col2), unique(col20)"
. The leading comma is important!
-
appendUniqueConstraint
protected void appendUniqueConstraint(StringBuilder fragment, UniqueKey uniqueKey)
-
getAlterTableToAddUniqueKeyCommand
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context)
Description copied from interface:UniqueDelegate
Get thealter table
command used to create the given unique key constraint, or return the empty string if the constraint was already included in thecreate table
statement byUniqueDelegate.getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table, org.hibernate.boot.model.relational.SqlStringGenerationContext)
.- Specified by:
getAlterTableToAddUniqueKeyCommand
in interfaceUniqueDelegate
- Overrides:
getAlterTableToAddUniqueKeyCommand
in classAlterTableUniqueDelegate
- Parameters:
uniqueKey
- TheUniqueKey
instance. Contains all information about the columnsmetadata
- Access to the bootstrap mapping informationcontext
- A context for SQL string generation- Returns:
- The
alter table
command
-
getAlterTableToDropUniqueKeyCommand
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context)
Description copied from interface:UniqueDelegate
Get thealter table
command used to drop the given unique key which was previously created byUniqueDelegate.getAlterTableToAddUniqueKeyCommand(org.hibernate.mapping.UniqueKey, org.hibernate.boot.Metadata, org.hibernate.boot.model.relational.SqlStringGenerationContext)
.- Specified by:
getAlterTableToDropUniqueKeyCommand
in interfaceUniqueDelegate
- Overrides:
getAlterTableToDropUniqueKeyCommand
in classAlterTableUniqueDelegate
- Parameters:
uniqueKey
- TheUniqueKey
instance. Contains all information about the columnsmetadata
- Access to the bootstrap mapping informationcontext
- A context for SQL string generation- Returns:
- The
alter table
command
-
-