List allSelectFields;
List<InLineCalculatedSelectField> selectInLineCalculatedFields = new ArrayList<InLineCalculatedSelectField>();
AbstractSelectField selectAbstractField;
DataMartSelectField selectField;
InLineCalculatedSelectField selectInLineField;
IModelEntity rootEntity;
IModelField datamartField;
String queryName;
String rootEntityAlias;
String selectClauseElement; // rootEntityAlias.queryName
Map entityAliases;
List<String> aliasEntityMapping;
logger.debug("IN");
buffer = new StringBuffer();
try {
selectFields = query.getSelectFields(true);
if(selectFields == null ||selectFields.size() == 0) {
return "";
}
entityAliases = (Map)entityAliasesMaps.get(query.getId());
buffer.append(SELECT);
if (query.isDistinctClauseEnabled()) {
buffer.append(" " + DISTINCT);
}
Iterator it = selectFields.iterator();
if(it.hasNext()){
selectAbstractField = (AbstractSelectField)it.next();
String[] idsForQuery = new String[selectFields.size()-query.getCalculatedSelectFields(true).size()];
int index=0;
do{
if(selectAbstractField.isDataMartField()){
selectField = (DataMartSelectField)selectAbstractField;
logger.debug("select field unique name [" + selectField.getUniqueName() + "]");
datamartField = getDataSource().getModelStructure().getField(selectField.getUniqueName());
queryName = (String)datamartField.getQueryName().getFirst();
logger.debug("select field query name [" + queryName + "]");
rootEntity = datamartField.getParent().getRoot();
logger.debug("select field root entity unique name [" + rootEntity.getUniqueName() + "]");
rootEntityAlias = (String)entityAliases.get(rootEntity.getUniqueName());
if(rootEntityAlias == null) {
rootEntityAlias = getNextAlias(entityAliasesMaps);
entityAliases.put(rootEntity.getUniqueName(), rootEntityAlias);
}
logger.debug("select field root entity alias [" + rootEntityAlias + "]");
selectClauseElement = rootEntityAlias + "." + queryName;