return toColumns( tableAlias, path, inSelect, false );
}
String[] toColumns(String tableAlias, String path, boolean inSelect, boolean forceAlias) {
checkInitialized();
PropertyMapping propertyMapping = getPropertyMapping( path );
// If this from element is a collection and the path is a collection property (maxIndex, etc.) then
// generate a sub-query.
if ( !inSelect && queryableCollection != null && CollectionProperties.isCollectionProperty( path ) ) {
Map enabledFilters = fromElement.getWalker().getEnabledFilters();
String subquery = CollectionSubqueryFactory.createCollectionSubquery(
joinSequence,
enabledFilters,
propertyMapping.toColumns( tableAlias, path )
);
if ( log.isDebugEnabled() ) {
log.debug( "toColumns(" + tableAlias + "," + path + ") : subquery = " + subquery );
}
return new String[]{"(" + subquery + ")"};
}
else {
if ( forceAlias ) {
return propertyMapping.toColumns( tableAlias, path );
}
else if ( fromElement.getWalker().getStatementType() == HqlSqlTokenTypes.SELECT ) {
return propertyMapping.toColumns( tableAlias, path );
}
else if ( fromElement.getWalker().getCurrentClauseType() == HqlSqlTokenTypes.SELECT ) {
return propertyMapping.toColumns( tableAlias, path );
}
else if ( fromElement.getWalker().isSubQuery() ) {
// for a subquery, the alias to use depends on a few things (we
// already know this is not an overall SELECT):
// 1) if this FROM_ELEMENT represents a correlation to the
// outer-most query
// A) if the outer query represents a multi-table
// persister, we need to use the given alias
// in anticipation of one of the multi-table
// executors being used (as this subquery will
// actually be used in the "id select" phase
// of that multi-table executor)
// B) otherwise, we need to use the persister's
// table name as the column qualification
// 2) otherwise (not correlated), use the given alias
if ( isCorrelation() ) {
if ( isMultiTable() ) {
return propertyMapping.toColumns( tableAlias, path );
}
else {
return propertyMapping.toColumns( extractTableName(), path );
}
}
else {
return propertyMapping.toColumns( tableAlias, path );
}
}
else {
String[] columns = propertyMapping.toColumns( path );
log.trace( "Using non-qualified column reference [" + path + " -> (" + ArrayHelper.toString( columns ) + ")]" );
return columns;
}
}
}