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