HHH-13496 Identified some String appending in loops

This commit is contained in:
Sanne Grinovero 2019-07-05 15:13:49 +01:00
parent 35b67bd00e
commit f41b11ad3f
4 changed files with 29 additions and 19 deletions

View File

@ -254,7 +254,8 @@ public class Teradata14Dialect extends TeradataDialect {
final StringBuilder buf = new StringBuilder()
.append( "create index " )
.append( indexNameForCreation )
.append( "(" + colBuf )
.append( '(' )
.append( colBuf )
.append( " on " )
.append( tableName );

View File

@ -92,16 +92,20 @@ public class MapEntryNode extends AbstractMapComponentNode implements Aggregated
determineKeySelectExpressions( collectionPersister, selections );
determineValueSelectExpressions( collectionPersister, selections );
String text = "";
String[] columns = new String[selections.size()];
for ( int i = 0; i < selections.size(); i++ ) {
final int columnNumber = selections.size();
StringBuilder text = new StringBuilder( columnNumber * 12 ); //Some guess
String[] columns = new String[columnNumber];
for ( int i = 0; i < columnNumber; i++ ) {
SelectExpression selectExpression = (SelectExpression) selections.get( i );
text += ( ", " + selectExpression.getExpression() + " as " + selectExpression.getAlias() );
if ( i != 0 ) {
text.append( ", " );
}
text.append( selectExpression.getExpression() );
text.append( " as " );
text.append( selectExpression.getAlias() );
columns[i] = selectExpression.getExpression();
}
text = text.substring( 2 ); //strip leading ", "
setText( text );
setText( text.toString() );
setResolved();
return columns;
}

View File

@ -318,14 +318,15 @@ public final class StringHelper {
*/
public static String collapseQualifier(String qualifier, boolean includeDots) {
StringTokenizer tokenizer = new StringTokenizer( qualifier, "." );
String collapsed = Character.toString( tokenizer.nextToken().charAt( 0 ) );
StringBuilder sb = new StringBuilder();
sb.append( Character.toString( tokenizer.nextToken().charAt( 0 ) ) );
while ( tokenizer.hasMoreTokens() ) {
if ( includeDots ) {
collapsed += '.';
sb.append( '.' );
}
collapsed += tokenizer.nextToken().charAt( 0 );
sb.append( tokenizer.nextToken().charAt( 0 ) );
}
return collapsed;
return sb.toString();
}
/**

View File

@ -8,8 +8,10 @@ package org.hibernate.loader.collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.hibernate.FetchMode;
import org.hibernate.Filter;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.CascadeStyle;
@ -75,8 +77,9 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
batchSize
);
String manyToManyOrderBy = "";
String filter = collectionPersister.filterFragment( alias, getLoadQueryInfluencers().getEnabledFilters() );
StringBuilder sb = null;
final Map<String, Filter> enabledFilters = getLoadQueryInfluencers().getEnabledFilters();
String filter = collectionPersister.filterFragment( alias, enabledFilters );
if ( collectionPersister.isManyToMany() ) {
// from the collection of associations, locate OJA for the
// ManyToOne corresponding to this persister to fully
@ -84,16 +87,17 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
// use its alias here
// TODO : is there a better way here?
Iterator itr = associations.iterator();
sb = new StringBuilder( 20 );
AssociationType associationType = ( AssociationType ) collectionPersister.getElementType();
while ( itr.hasNext() ) {
OuterJoinableAssociation oja = ( OuterJoinableAssociation ) itr.next();
if ( oja.getJoinableType() == associationType ) {
// we found it
filter += collectionPersister.getManyToManyFilterFragment(
oja.getRHSAlias(),
getLoadQueryInfluencers().getEnabledFilters()
oja.getRHSAlias(),
enabledFilters
);
manyToManyOrderBy += collectionPersister.getManyToManyOrderByString( oja.getRHSAlias() );
sb.append( collectionPersister.getManyToManyOrderByString( oja.getRHSAlias() ) );
}
}
}
@ -103,7 +107,7 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
Select select = new Select( getDialect() )
.setSelectClause(
collectionPersister.selectFragment(alias, collectionSuffixes[0] ) +
selectString(associations)
selectString( associations )
)
.setFromClause( collectionPersister.getTableName(), alias )
.setWhereClause( whereString.toString() )
@ -112,7 +116,7 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
ojf.toWhereFragmentString()
);
select.setOrderByClause( orderBy( associations, mergeOrderings( collectionPersister.getSQLOrderByString(alias), manyToManyOrderBy ) ) );
select.setOrderByClause( orderBy( associations, mergeOrderings( collectionPersister.getSQLOrderByString( alias ), sb == null ? "" : sb.toString() ) ) );
if ( getFactory().getSettings().isCommentsEnabled() ) {
select.setComment( "load collection " + collectionPersister.getRole() );