Package org.hibernate.dialect.unique
Class SkipNullableUniqueDelegate
- java.lang.Object
-
- org.hibernate.dialect.unique.AlterTableUniqueDelegate
-
- org.hibernate.dialect.unique.CreateTableUniqueDelegate
-
- org.hibernate.dialect.unique.SkipNullableUniqueDelegate
-
- All Implemented Interfaces:
UniqueDelegate
public class SkipNullableUniqueDelegate extends CreateTableUniqueDelegate
AUniqueDelegate
that only creates unique constraints on not-null columns, and ignores requests for uniqueness for nullable columns.Needed because unique constraints on nullable columns in Sybase always consider null values to be non-unique. There is simply no way to create a unique constraint with the semantics we want on a nullable column in Sybase.
You might argue that this behavior is bad because if the programmer explicitly specifies an
@UniqueKey
, then we should damn well respect their wishes. But the simple answer is that the user should have also specified@Column(nullable=false)
if that is what they wanted. A unique key on a nullable column just really doesn't make sense in Sybase, except, perhaps, in some incredibly corner cases.
-
-
Field Summary
-
Fields inherited from class org.hibernate.dialect.unique.AlterTableUniqueDelegate
dialect
-
-
Constructor Summary
Constructors Constructor Description SkipNullableUniqueDelegate(Dialect dialect)
-
Method Summary
-
Methods inherited from class org.hibernate.dialect.unique.CreateTableUniqueDelegate
getTableCreationUniqueConstraintsFragment
-
Methods inherited from class org.hibernate.dialect.unique.AlterTableUniqueDelegate
uniqueConstraintSql
-
-
-
-
Constructor Detail
-
SkipNullableUniqueDelegate
public SkipNullableUniqueDelegate(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 classCreateTableUniqueDelegate
- 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
-
appendUniqueConstraint
protected void appendUniqueConstraint(StringBuilder fragment, UniqueKey uniqueKey)
- Overrides:
appendUniqueConstraint
in classCreateTableUniqueDelegate
-
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 classCreateTableUniqueDelegate
- 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 classCreateTableUniqueDelegate
- 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
-
-