HHH-8073 Corrected column alias creation

This commit is contained in:
Brett Meyer 2013-03-14 17:36:41 -04:00
parent d2c4588c86
commit 79073a98f0
1 changed files with 19 additions and 20 deletions

View File

@ -108,33 +108,32 @@ public class Column implements Selectable, Serializable, Cloneable {
name;
}
/**
* For any column name, generate an alias that is unique
* to that column name, and also 10 characters or less
* in length.
*/
@Override
public String getAlias(Dialect dialect) {
final int lastLetter = StringHelper.lastIndexOfLetter( name );
String suffix = Integer.toString(uniqueInteger) + '_';
String alias = name;
String unique = Integer.toString(uniqueInteger) + '_';
int lastLetter = StringHelper.lastIndexOfLetter(name);
if ( lastLetter == -1 ) {
alias = "column";
}
else if ( lastLetter < name.length()-1 ) {
alias = name.substring(0, lastLetter+1);
else if ( name.length() > lastLetter + 1 ) {
alias = name.substring( 0, lastLetter + 1 );
}
if ( alias.length() > dialect.getMaxAliasLength() ) {
alias = alias.substring( 0, dialect.getMaxAliasLength() - unique.length() );
}
boolean useRawName = name.equals(alias) &&
!quoted &&
!name.toLowerCase().equals("rowid");
if ( useRawName ) {
return alias;
}
else {
return alias + unique;
boolean useRawName = name.length() + suffix.length() <= dialect.getMaxAliasLength()
&& !quoted && !name.toLowerCase().equals( "rowid" );
if ( !useRawName ) {
if ( suffix.length() >= dialect.getMaxAliasLength() ) {
throw new MappingException( String.format(
"Unique suffix [%s] length must be less than maximum [%d]",
suffix, dialect.getMaxAliasLength() ) );
}
if ( alias.length() + suffix.length() > dialect.getMaxAliasLength() ) {
alias = alias.substring( 0, dialect.getMaxAliasLength() - suffix.length() );
}
}
return alias + suffix;
}
/**