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() final StringBuilder buf = new StringBuilder()
.append( "create index " ) .append( "create index " )
.append( indexNameForCreation ) .append( indexNameForCreation )
.append( "(" + colBuf ) .append( '(' )
.append( colBuf )
.append( " on " ) .append( " on " )
.append( tableName ); .append( tableName );

View File

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

View File

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