Interface UniqueDelegate

All Known Implementing Classes:
DelegatingUniqueDelegate

@SPI({USE,IMPLEMENT,SUPPLY}) public interface UniqueDelegate

Applies logical unique declarations to database DDL.

A delegate owns all three possible emission points: a single-column definition, the create table constraint list, and separate add/drop commands. It also selects whether metadata and DDL represent a logical declaration as a constraint or a unique index. Keep those decisions coherent by consulting representation(UniqueKeyRepresentationRequest) instead of a separate Dialect capability.

Implement this contract for provider-specific behavior, decorate a stock strategy with DelegatingUniqueDelegate, or obtain a standard strategy from UniqueDelegates. Return empty fragments or commands when the selected emission point does not apply. Do not retain the mutable mapping arguments.

Hibernate requires null values in nullable unique declarations to be distinct. A delegate for a database with different native semantics must use a suitable index, suppress an unsupported nullable declaration, or otherwise preserve that behavior.

Since:
8.0
See Also:
  • Method Details

    • representation

      default UniqueKeyRepresentation representation(UniqueKeyRepresentationRequest request)
      Select whether a logical unique declaration is represented as a constraint or an index.
    • supportsNullsNotDistinct

      default boolean supportsNullsNotDistinct()
      Whether this delegate can render nulls not distinct for a requested unique constraint.
    • getColumnDefinitionUniquenessFragment

      String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context)
      Render the column-definition uniqueness fragment for a column explicitly marked [Column#isUnique() unique]. Return an empty string when uniqueness belongs at another emission point.
    • getTableCreationUniqueConstraintsFragment

      String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context)
      Render all unique declarations embedded in create table. Include the required leading comma, or return an empty string when no declaration is emitted at this point.
    • getAlterTableToAddUniqueKeyCommand

      String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context)
      Render the complete command which adds the unique key. Return an empty string when it was already emitted during table creation or is unsupported.
    • getAlterTableToDropUniqueKeyCommand

      String getAlterTableToDropUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context)
      Render the complete command which drops the unique key previously emitted by getAlterTableToAddUniqueKeyCommand(UniqueKey, Metadata, SqlStringGenerationContext). Return an empty string when no corresponding database object was created.