HHH-7797 minor refactoring

This commit is contained in:
brmeyer 2012-12-14 11:58:09 -05:00
parent 49c8a8e4f0
commit 9bec5d12ff
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 "";
}

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

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

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