HHH-6439: Added getAddUniqueConstraintString method to Dialect and updated UniqueKey classes to use it
This commit is contained in:
parent
88b6b4c67b
commit
f4c36a10f8
|
@ -482,7 +482,7 @@ public abstract class Dialect {
|
|||
}
|
||||
try {
|
||||
LobCreator lobCreator = session.getFactory().getJdbcServices().getLobCreator( session );
|
||||
return original == null
|
||||
return original == null
|
||||
? lobCreator.createBlob( ArrayHelper.EMPTY_BYTE_ARRAY )
|
||||
: lobCreator.createBlob( original.getBinaryStream(), original.length() );
|
||||
}
|
||||
|
@ -1793,6 +1793,16 @@ public abstract class Dialect {
|
|||
return " add constraint " + constraintName + " primary key ";
|
||||
}
|
||||
|
||||
/**
|
||||
* The syntax used to add a unique constraint to a table.
|
||||
*
|
||||
* @param constraintName The name of the unique constraint.
|
||||
* @return The "add unique" fragment
|
||||
*/
|
||||
public String getAddUniqueConstraintString(String constraintName) {
|
||||
return " add constraint " + constraintName + " unique ";
|
||||
}
|
||||
|
||||
public boolean hasSelfReferentialForeignKeyBug() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ package org.hibernate.mapping;
|
|||
import java.util.Iterator;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* A relational unique key constraint
|
||||
|
@ -54,13 +53,14 @@ public class UniqueKey extends Constraint {
|
|||
null;
|
||||
}
|
||||
|
||||
public String sqlConstraintString(
|
||||
@Override
|
||||
public String sqlConstraintString(
|
||||
Dialect dialect,
|
||||
String constraintName,
|
||||
String defaultCatalog,
|
||||
String defaultSchema) {
|
||||
StringBuffer buf = new StringBuffer(
|
||||
dialect.getAddPrimaryKeyConstraintString( constraintName )
|
||||
dialect.getAddUniqueConstraintString( constraintName )
|
||||
).append( '(' );
|
||||
Iterator iter = getColumnIterator();
|
||||
boolean nullable = false;
|
||||
|
@ -70,13 +70,11 @@ public class UniqueKey extends Constraint {
|
|||
buf.append( column.getQuotedName( dialect ) );
|
||||
if ( iter.hasNext() ) buf.append( ", " );
|
||||
}
|
||||
return !nullable || dialect.supportsNotNullUnique() ?
|
||||
StringHelper.replace( buf.append( ')' ).toString(), "primary key", "unique" ) :
|
||||
//TODO: improve this hack!
|
||||
null;
|
||||
return !nullable || dialect.supportsNotNullUnique() ? buf.append( ')' ).toString() : null;
|
||||
}
|
||||
|
||||
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
|
||||
@Override
|
||||
public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) {
|
||||
if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
|
||||
return super.sqlCreateString( dialect, p, defaultCatalog, defaultSchema );
|
||||
}
|
||||
|
@ -86,7 +84,8 @@ public class UniqueKey extends Constraint {
|
|||
}
|
||||
}
|
||||
|
||||
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
||||
@Override
|
||||
public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) {
|
||||
if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) {
|
||||
return super.sqlDropString( dialect, defaultCatalog, defaultSchema );
|
||||
}
|
||||
|
@ -95,7 +94,8 @@ public class UniqueKey extends Constraint {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isGenerated(Dialect dialect) {
|
||||
@Override
|
||||
public boolean isGenerated(Dialect dialect) {
|
||||
if ( dialect.supportsNotNullUnique() ) return true;
|
||||
Iterator iter = getColumnIterator();
|
||||
while ( iter.hasNext() ) {
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
package org.hibernate.metamodel.relational;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Models a SQL <tt>INDEX</tt> defined as UNIQUE
|
||||
|
@ -47,7 +46,8 @@ public class UniqueKey extends AbstractConstraint implements Constraint {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public boolean isCreationVetoed(Dialect dialect) {
|
||||
@Override
|
||||
public boolean isCreationVetoed(Dialect dialect) {
|
||||
if ( dialect.supportsNotNullUnique() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -82,9 +82,10 @@ public class UniqueKey extends AbstractConstraint implements Constraint {
|
|||
null;
|
||||
}
|
||||
|
||||
public String sqlConstraintStringInAlterTable(Dialect dialect) {
|
||||
@Override
|
||||
public String sqlConstraintStringInAlterTable(Dialect dialect) {
|
||||
StringBuffer buf = new StringBuffer(
|
||||
dialect.getAddPrimaryKeyConstraintString( getName() )
|
||||
dialect.getAddUniqueConstraintString( getName() )
|
||||
).append( '(' );
|
||||
boolean nullable = false;
|
||||
boolean first = true;
|
||||
|
@ -100,9 +101,6 @@ public class UniqueKey extends AbstractConstraint implements Constraint {
|
|||
}
|
||||
buf.append( column.getColumnName().encloseInQuotesIfQuoted( dialect ) );
|
||||
}
|
||||
return !nullable || dialect.supportsNotNullUnique() ?
|
||||
StringHelper.replace( buf.append( ')' ).toString(), "primary key", "unique" ) :
|
||||
//TODO: improve this hack!
|
||||
null;
|
||||
return !nullable || dialect.supportsNotNullUnique() ? buf.append( ')' ).toString() : null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue