HHH-7797 minor refactoring

This commit is contained in:
brmeyer 2012-12-14 11:58:09 -05:00 committed by Brett Meyer
parent 98149d2534
commit 2cd062058c
4 changed files with 30 additions and 20 deletions

View File

@ -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() )

View File

@ -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,

View File

@ -423,7 +423,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() ) {
@ -522,8 +525,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 (" )

View File

@ -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() ) {