HHH-7797 minor refactoring
This commit is contained in:
parent
49c8a8e4f0
commit
9bec5d12ff
|
@ -42,19 +42,22 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String applyUniqueToColumn( org.hibernate.mapping.Table table,
|
||||
public void generateUniqueKey( org.hibernate.mapping.Table table,
|
||||
org.hibernate.mapping.Column column ) {
|
||||
org.hibernate.mapping.UniqueKey uk = table.getOrCreateUniqueKey(
|
||||
column.getQuotedName( dialect ) + '_' );
|
||||
uk.addColumn( column );
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String applyUniqueToColumn( Table table, Column column ) {
|
||||
public void generateUniqueKey( Table table, Column column ) {
|
||||
UniqueKey uk = table.getOrCreateUniqueKey( column.getColumnName()
|
||||
.encloseInQuotesIfQuoted( dialect ) + '_' );
|
||||
uk.addColumn( column );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String applyUniqueToColumn() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -85,8 +88,8 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
|
|||
@Override
|
||||
public String applyUniquesOnAlter( UniqueKey uniqueKey ) {
|
||||
// Do this here, rather than allowing UniqueKey/Constraint to do it.
|
||||
// We need full, simplified control over whether or not it happens.
|
||||
return new StringBuilder( "alter table " )
|
||||
// We need full, simplified control over whether or not it happens.
|
||||
return new StringBuilder( "alter table " )
|
||||
.append( uniqueKey.getTable().getQualifiedName( dialect ) )
|
||||
.append( " add constraint " )
|
||||
.append( uniqueKey.getName() )
|
||||
|
|
|
@ -45,29 +45,32 @@ import org.hibernate.metamodel.relational.UniqueKey;
|
|||
public interface UniqueDelegate {
|
||||
|
||||
/**
|
||||
* If the delegate supports unique constraints, this method should simply
|
||||
* create the UniqueKey on the Table. Otherwise, the constraint isn't
|
||||
* supported and "unique" should be returned in order to add it
|
||||
* to the column definition.
|
||||
* If the dialect supports unique constraints, create and add a UniqueKey
|
||||
* to the Table.
|
||||
*
|
||||
* @param table
|
||||
* @param column
|
||||
* @return String
|
||||
*/
|
||||
public String applyUniqueToColumn( org.hibernate.mapping.Table table,
|
||||
public void generateUniqueKey( org.hibernate.mapping.Table table,
|
||||
org.hibernate.mapping.Column column );
|
||||
|
||||
/**
|
||||
* If the delegate supports unique constraints, this method should simply
|
||||
* create the UniqueKey on the Table. Otherwise, the constraint isn't
|
||||
* supported and "unique" should be returned in order to add it
|
||||
* to the column definition.
|
||||
* If the dialect supports unique constraints, create and add a UniqueKey
|
||||
* to the Table.
|
||||
*
|
||||
* @param table
|
||||
* @param column
|
||||
*/
|
||||
public void generateUniqueKey( Table table, Column column );
|
||||
|
||||
/**
|
||||
* If the dialect does not supports unique constraints, this method should
|
||||
* return the syntax necessary to mutate the column definition
|
||||
* (usually "unique").
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String applyUniqueToColumn( Table table, Column column );
|
||||
public String applyUniqueToColumn();
|
||||
|
||||
/**
|
||||
* If constraints are supported, but not in seperate alter statements,
|
||||
|
|
|
@ -422,7 +422,10 @@ public class Table implements RelationalModel, Serializable {
|
|||
}
|
||||
|
||||
if ( column.isUnique() ) {
|
||||
alter.append( dialect.getUniqueDelegate().applyUniqueToColumn( this, column ) );
|
||||
dialect.getUniqueDelegate().generateUniqueKey(
|
||||
this, column );
|
||||
alter.append(
|
||||
dialect.getUniqueDelegate().applyUniqueToColumn() );
|
||||
}
|
||||
|
||||
if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
|
||||
|
@ -521,8 +524,8 @@ public class Table implements RelationalModel, Serializable {
|
|||
}
|
||||
|
||||
if ( col.isUnique() ) {
|
||||
buf.append( dialect.getUniqueDelegate().applyUniqueToColumn( this, col ) );
|
||||
}
|
||||
dialect.getUniqueDelegate().generateUniqueKey( this, col );
|
||||
buf.append( dialect.getUniqueDelegate().applyUniqueToColumn() ); }
|
||||
|
||||
if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
|
||||
buf.append( " check (" )
|
||||
|
|
|
@ -200,7 +200,8 @@ public class Table extends AbstractTableSpecification implements Exportable {
|
|||
}
|
||||
|
||||
if ( col.isUnique() ) {
|
||||
buf.append( dialect.getUniqueDelegate().applyUniqueToColumn( this, col ) );
|
||||
dialect.getUniqueDelegate().generateUniqueKey( this, col );
|
||||
buf.append( dialect.getUniqueDelegate().applyUniqueToColumn() );
|
||||
}
|
||||
|
||||
if ( col.getCheckCondition() != null && dialect.supportsColumnCheck() ) {
|
||||
|
|
Loading…
Reference in New Issue