Created
December 18, 2013 21:53
-
-
Save gbadner/8030497 to your computer and use it in GitHub Desktop.
org.hibernate.metamodel.spi.relational.UniqueKey
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UniqueKey extends AbstractConstraint implements Constraint { | |
private static final String GENERATED_NAME_PREFIX = "UK"; | |
protected UniqueKey(Table table, String name) { | |
super( table, name ); | |
} | |
@Override | |
public String getExportIdentifier() { | |
StringBuilder sb = new StringBuilder( getTable().getLoggableValueQualifier() ); | |
sb.append( ".UK" ); | |
for ( Column column : getColumns() ) { | |
sb.append( '_' ).append( column.getColumnName().getName() ); | |
} | |
return sb.toString(); | |
} | |
@Override | |
<<<<<<< HEAD | |
public String[] sqlCreateStrings(Dialect dialect) { | |
String s = dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand( this ); | |
return StringHelper.toArrayElement( s ); | |
======= | |
protected String getGeneratedNamePrefix() { | |
return GENERATED_NAME_PREFIX; | |
} | |
@Override | |
public boolean isCreationVetoed(Dialect dialect) { | |
if ( dialect.supportsNotNullUnique() ) { | |
return false; | |
} | |
for ( Column column : getColumns() ) { | |
if ( column.isNullable() ) { | |
return true; | |
} | |
} | |
return false; | |
>>>>>>> HHH-7092 : Create default name for foreign and unique key constraints | |
} | |
@Override | |
public String[] sqlDropStrings(Dialect dialect) { | |
String s = dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand( this ); | |
return StringHelper.toArrayElement( s ); | |
} | |
@Override | |
<<<<<<< HEAD | |
protected String sqlConstraintStringInAlterTable(Dialect dialect) { | |
// not used | |
return ""; | |
======= | |
public String sqlConstraintStringInAlterTable(Dialect dialect) { | |
StringBuilder buf = new StringBuilder( | |
dialect.getAddUniqueConstraintString( getOrGenerateName() ) | |
).append( '(' ); | |
boolean nullable = false; | |
boolean first = true; | |
for ( Column column : getColumns() ) { | |
if ( first ) { | |
first = false; | |
} | |
else { | |
buf.append( ", " ); | |
} | |
if ( !nullable && column.isNullable() ) { | |
nullable = true; | |
} | |
buf.append( column.getColumnName().encloseInQuotesIfQuoted( dialect ) ); | |
} | |
return !nullable || dialect.supportsNotNullUnique() ? buf.append( ')' ).toString() : null; | |
>>>>>>> HHH-7092 : Create default name for foreign and unique key constraints | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment