HHH-3646 - don't append spurious comma in SQL select fragment

In the JoinWalker, we assemble an SQL select list fragment
from a list of Joinables. In the existing code, we see it's
possible for the selectFragment generated by a joinable to be empty.
However if the LAST joinable generates an empty fragment, we put
a spurious comma into the fragment. Fix this by only prepending a
comma when necessary.
This commit is contained in:
David Mansfield 2011-03-10 11:33:50 -05:00 committed by Steve Ebersole
parent 9f311a4698
commit 69b09dfcd2
1 changed files with 4 additions and 9 deletions

View File

@ -1044,8 +1044,7 @@ public class JoinWalker {
return "";
}
else {
StringBuffer buf = new StringBuffer( associations.size() * 100 )
.append(", ");
StringBuffer buf = new StringBuffer( associations.size() * 100 );
int entityAliasCount=0;
int collectionAliasCount=0;
for ( int i=0; i<associations.size(); i++ ) {
@ -1068,15 +1067,11 @@ public class JoinWalker {
collectionSuffix,
join.getJoinType()==JoinFragment.LEFT_OUTER_JOIN
);
buf.append(selectFragment);
if (selectFragment.trim().length() > 0) {
buf.append(", ").append(selectFragment);
}
if ( joinable.consumesEntityAlias() ) entityAliasCount++;
if ( joinable.consumesCollectionAlias() && join.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) collectionAliasCount++;
if (
i<associations.size()-1 &&
selectFragment.trim().length()>0
) {
buf.append(", ");
}
}
return buf.toString();
}