returnTypes = new Type[scalarSize];
for ( int i = 0; i < scalarSize; i++ ) {
returnTypes[i] = ( Type ) scalarTypes.get( i );
}
QuerySelect sql = new QuerySelect( getFactory().getDialect() );
sql.setDistinct( distinct );
if ( !shallowQuery ) {
renderIdentifierSelect( sql );
renderPropertiesSelect( sql );
}
if ( collectionPersister != null ) {
sql.addSelectFragmentString( collectionPersister.selectFragment( fetchName, "__" ) );
}
if ( hasScalars || shallowQuery ) sql.addSelectFragmentString( scalarSelect );
//TODO: for some dialects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings
mergeJoins( sql.getJoinFragment() );
sql.setWhereTokens( whereTokens.iterator() );
sql.setGroupByTokens( groupByTokens.iterator() );
sql.setHavingTokens( havingTokens.iterator() );
sql.setOrderByTokens( orderByTokens.iterator() );
if ( collectionPersister != null && collectionPersister.hasOrdering() ) {
sql.addOrderBy( collectionPersister.getSQLOrderByString( fetchName ) );
}
scalarColumnNames = NameGenerator.generateColumnNames( returnTypes, getFactory() );
// initialize the Set of queried identifier spaces (ie. tables)
Iterator iter = collections.values().iterator();
while ( iter.hasNext() ) {
CollectionPersister p = getCollectionPersister( ( String ) iter.next() );
addQuerySpaces( p.getCollectionSpaces() );
}
iter = typeMap.keySet().iterator();
while ( iter.hasNext() ) {
Queryable p = getEntityPersisterForName( ( String ) iter.next() );
addQuerySpaces( p.getQuerySpaces() );
}
sqlString = sql.toQueryString();
if ( holderClass != null ) holderConstructor = ReflectHelper.getConstructor( holderClass, returnTypes );
if ( hasScalars ) {
actualReturnTypes = returnTypes;