HHH-13549 StringHelper: use char rather than string when possible
This commit is contained in:
parent
85d4ffda14
commit
0028c850b9
|
@ -98,7 +98,6 @@ public final class StringHelper {
|
||||||
return new String( buffer );
|
return new String( buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String replace(String template, String placeholder, String replacement) {
|
public static String replace(String template, String placeholder, String replacement) {
|
||||||
return replace( template, placeholder, replacement, false );
|
return replace( template, placeholder, replacement, false );
|
||||||
}
|
}
|
||||||
|
@ -142,7 +141,6 @@ public final class StringHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String replace(
|
public static String replace(
|
||||||
String beforePlaceholder,
|
String beforePlaceholder,
|
||||||
String afterPlaceholder,
|
String afterPlaceholder,
|
||||||
|
@ -493,7 +491,6 @@ public final class StringHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int firstIndexOfChar(String sqlString, String string, int startindex) {
|
public static int firstIndexOfChar(String sqlString, String string, int startindex) {
|
||||||
|
@ -502,7 +499,6 @@ public final class StringHelper {
|
||||||
keys.set( string.charAt( i ) );
|
keys.set( string.charAt( i ) );
|
||||||
}
|
}
|
||||||
return firstIndexOfChar( sqlString, keys, startindex );
|
return firstIndexOfChar( sqlString, keys, startindex );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String truncate(String string, int length) {
|
public static String truncate(String string, int length) {
|
||||||
|
@ -709,14 +705,14 @@ public final class StringHelper {
|
||||||
if ( columnNames.length == 1 ) {
|
if ( columnNames.length == 1 ) {
|
||||||
// non-composite key
|
// non-composite key
|
||||||
return new StringBuilder( StringHelper.qualify( alias, columnNames[0] ) )
|
return new StringBuilder( StringHelper.qualify( alias, columnNames[0] ) )
|
||||||
.append( " in (" ).append( BATCH_ID_PLACEHOLDER ).append( ")" );
|
.append( " in (" ).append( BATCH_ID_PLACEHOLDER ).append( ')' );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// composite key - the form to use here depends on what the dialect supports.
|
// composite key - the form to use here depends on what the dialect supports.
|
||||||
if ( dialect.supportsRowValueConstructorSyntaxInInList() ) {
|
if ( dialect.supportsRowValueConstructorSyntaxInInList() ) {
|
||||||
// use : (col1, col2) in ( (?,?), (?,?), ... )
|
// use : (col1, col2) in ( (?,?), (?,?), ... )
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append( "(" );
|
builder.append( '(' );
|
||||||
boolean firstPass = true;
|
boolean firstPass = true;
|
||||||
String deliminator = "";
|
String deliminator = "";
|
||||||
for ( String columnName : columnNames ) {
|
for ( String columnName : columnNames ) {
|
||||||
|
@ -728,14 +724,18 @@ public final class StringHelper {
|
||||||
}
|
}
|
||||||
builder.append( ") in (" );
|
builder.append( ") in (" );
|
||||||
builder.append( BATCH_ID_PLACEHOLDER );
|
builder.append( BATCH_ID_PLACEHOLDER );
|
||||||
builder.append( ")" );
|
builder.append( ')' );
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// use : ( (col1 = ? and col2 = ?) or (col1 = ? and col2 = ?) or ... )
|
// use : ( (col1 = ? and col2 = ?) or (col1 = ? and col2 = ?) or ... )
|
||||||
// unfortunately most of this building needs to be held off until we know
|
// unfortunately most of this building needs to be held off until we know
|
||||||
// the exact number of ids :(
|
// the exact number of ids :(
|
||||||
return new StringBuilder( "(" ).append( BATCH_ID_PLACEHOLDER ).append( ")" );
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append( '(' )
|
||||||
|
.append( BATCH_ID_PLACEHOLDER )
|
||||||
|
.append( ')' );
|
||||||
|
return stringBuilder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -753,16 +753,16 @@ public final class StringHelper {
|
||||||
else {
|
else {
|
||||||
// composite
|
// composite
|
||||||
if ( dialect.supportsRowValueConstructorSyntaxInInList() ) {
|
if ( dialect.supportsRowValueConstructorSyntaxInInList() ) {
|
||||||
final String tuple = "(" + StringHelper.repeat( "?", keyColumnNames.length, "," ) + ")";
|
final String tuple = '(' + StringHelper.repeat( "?", keyColumnNames.length, "," ) + ')';
|
||||||
return StringHelper.replace( sql, BATCH_ID_PLACEHOLDER, repeat( tuple, ids.length, "," ) );
|
return StringHelper.replace( sql, BATCH_ID_PLACEHOLDER, repeat( tuple, ids.length, "," ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final String keyCheck = "(" + joinWithQualifierAndSuffix(
|
final String keyCheck = '(' + joinWithQualifierAndSuffix(
|
||||||
keyColumnNames,
|
keyColumnNames,
|
||||||
alias,
|
alias,
|
||||||
" = ?",
|
" = ?",
|
||||||
" and "
|
" and "
|
||||||
) + ")";
|
) + ')';
|
||||||
return replace( sql, BATCH_ID_PLACEHOLDER, repeat( keyCheck, ids.length, " or " ) );
|
return replace( sql, BATCH_ID_PLACEHOLDER, repeat( keyCheck, ids.length, " or " ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -779,7 +779,7 @@ public final class StringHelper {
|
||||||
public static <T> String join(Collection<T> values, Renderer<T> renderer) {
|
public static <T> String join(Collection<T> values, Renderer<T> renderer) {
|
||||||
final StringBuilder buffer = new StringBuilder();
|
final StringBuilder buffer = new StringBuilder();
|
||||||
for ( T value : values ) {
|
for ( T value : values ) {
|
||||||
buffer.append( String.join(", ", renderer.render( value )) );
|
buffer.append( String.join(", ", renderer.render( value ) ) );
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue