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
A
UniqueDelegate 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendUniqueConstraint(StringBuilder fragment, UniqueKey uniqueKey) getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context) Get thealter tablecommand used to create the given unique key constraint, or return the empty string if the constraint was already included in thecreate tablestatement byUniqueDelegate.getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table, org.hibernate.boot.model.relational.SqlStringGenerationContext).getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context) Get thealter tablecommand 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).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.Methods inherited from class org.hibernate.dialect.unique.CreateTableUniqueDelegate
getTableCreationUniqueConstraintsFragmentMethods inherited from class org.hibernate.dialect.unique.AlterTableUniqueDelegate
uniqueConstraintSql
-
Constructor Details
-
SkipNullableUniqueDelegate
-
-
Method Details
-
getColumnDefinitionUniquenessFragment
public String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context) Description copied from interface:UniqueDelegateGet 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:
getColumnDefinitionUniquenessFragmentin interfaceUniqueDelegate- Overrides:
getColumnDefinitionUniquenessFragmentin 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
- Overrides:
appendUniqueConstraintin classCreateTableUniqueDelegate
-
getAlterTableToAddUniqueKeyCommand
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context) Description copied from interface:UniqueDelegateGet thealter tablecommand used to create the given unique key constraint, or return the empty string if the constraint was already included in thecreate tablestatement byUniqueDelegate.getTableCreationUniqueConstraintsFragment(org.hibernate.mapping.Table, org.hibernate.boot.model.relational.SqlStringGenerationContext).- Specified by:
getAlterTableToAddUniqueKeyCommandin interfaceUniqueDelegate- Overrides:
getAlterTableToAddUniqueKeyCommandin classCreateTableUniqueDelegate- Parameters:
uniqueKey- TheUniqueKeyinstance. Contains all information about the columnsmetadata- Access to the bootstrap mapping informationcontext- A context for SQL string generation- Returns:
- The
alter tablecommand
-
getAlterTableToDropUniqueKeyCommand
public String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context) Description copied from interface:UniqueDelegateGet thealter tablecommand 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:
getAlterTableToDropUniqueKeyCommandin interfaceUniqueDelegate- Overrides:
getAlterTableToDropUniqueKeyCommandin classCreateTableUniqueDelegate- Parameters:
uniqueKey- TheUniqueKeyinstance. Contains all information about the columnsmetadata- Access to the bootstrap mapping informationcontext- A context for SQL string generation- Returns:
- The
alter tablecommand
-