HHH-18153 Fix for Informix unique constraints on nullness columns
This commit is contained in:
parent
86d40a4f87
commit
a3f8addd51
|
@ -9,31 +9,42 @@ package org.hibernate.community.dialect.unique;
|
|||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.unique.AlterTableUniqueDelegate;
|
||||
import org.hibernate.dialect.unique.SkipNullableUniqueDelegate;
|
||||
import org.hibernate.mapping.UniqueKey;
|
||||
|
||||
/**
|
||||
* Informix requires the constraint name to come last on the alter table.
|
||||
* Informix requires the constraint name to come last.
|
||||
*
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class InformixUniqueDelegate extends AlterTableUniqueDelegate {
|
||||
public class InformixUniqueDelegate extends SkipNullableUniqueDelegate {
|
||||
|
||||
public InformixUniqueDelegate( Dialect dialect ) {
|
||||
super( dialect );
|
||||
}
|
||||
|
||||
// legacy model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@Override
|
||||
protected void appendUniqueConstraint(StringBuilder fragment, UniqueKey uniqueKey) {
|
||||
if ( !uniqueKey.hasNullableColumn() ) {
|
||||
fragment.append( ", " );
|
||||
fragment.append( uniqueConstraintSql(uniqueKey) );
|
||||
if ( uniqueKey.isNameExplicit() ) {
|
||||
fragment.append( " constraint " ).append( uniqueKey.getName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||
SqlStringGenerationContext context) {
|
||||
// Do this here, rather than allowing UniqueKey/Constraint to do it.
|
||||
// We need full, simplified control over whether it happens.
|
||||
final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() );
|
||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||
return dialect.getAlterTableString( tableName )
|
||||
+ " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName;
|
||||
if (uniqueKey.hasNullableColumn() || !context.isMigration()){
|
||||
return "";
|
||||
} else {
|
||||
final String tableName = context.format( uniqueKey.getTable().getQualifiedTableName() );
|
||||
final String constraintName = dialect.quote( uniqueKey.getName() );
|
||||
return dialect.getAlterTableString( tableName )
|
||||
+ " add constraint " + uniqueConstraintSql( uniqueKey ) + " constraint " + constraintName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue