HHH-8037 Pulled duplicate code into StringHelper

This commit is contained in:
Brett Meyer 2013-03-05 20:26:44 -05:00
parent 6b368e9512
commit fd772a47db
2 changed files with 14 additions and 2 deletions

View File

@ -747,4 +747,15 @@ public final class StringHelper {
}
}
}
/**
* Takes a String s and returns a new String[1] with s as the only element.
* If s is null or "", return String[0].
*
* @param s
* @return String[]
*/
public static String[] toArrayElement(String s) {
return ( s == null || s.length() == 0 ) ? new String[0] : new String[] { s };
}
}

View File

@ -24,6 +24,7 @@
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
@ -49,13 +50,13 @@ public class UniqueKey extends AbstractConstraint implements Constraint {
@Override
public String[] sqlCreateStrings(Dialect dialect) {
String s = dialect.getUniqueDelegate().applyUniquesOnAlter(this);
return (s == null || s.length() == 0) ? new String[0] : new String[]{s};
return StringHelper.toArrayElement( s );
}
@Override
public String[] sqlDropStrings(Dialect dialect) {
String s = dialect.getUniqueDelegate().dropUniquesOnAlter(this);
return (s == null || s.length() == 0) ? new String[0] : new String[]{s};
return StringHelper.toArrayElement( s );
}
@Override