throws GenericEntityException {
if (modelEntity == null) {
return null;
}
ModelViewEntity modelViewEntity = null;
if (modelEntity instanceof ModelViewEntity) {
modelViewEntity = (ModelViewEntity) modelEntity;
}
// if no find options passed, use default
if (findOptions == null) findOptions = new EntityFindOptions();
boolean verboseOn = Debug.verboseOn();
if (verboseOn) {
// put this inside an if statement so that we don't have to generate the string when not used...
Debug.logVerbose("Doing selectListIteratorByCondition with whereEntityCondition: " + whereEntityCondition, module);
}
// make two ArrayLists of fields, one for fields to select and the other for where clause fields (to find by)
List<ModelField> selectFields = FastList.newInstance();
if (UtilValidate.isNotEmpty(fieldsToSelect)) {
Set<String> tempKeys = FastSet.newInstance();
tempKeys.addAll(fieldsToSelect);
for (String fieldToSelect : fieldsToSelect) {
if (tempKeys.contains(fieldToSelect)) {
ModelField curField = modelEntity.getField(fieldToSelect);
if (curField != null) {
selectFields.add(curField);
tempKeys.remove(fieldToSelect);
}
}
}
if (tempKeys.size() > 0) {
throw new GenericModelException("In selectListIteratorByCondition invalid field names specified: " + tempKeys.toString());
}
} else {
selectFields = modelEntity.getFieldsUnmodifiable();
}
StringBuilder sqlBuffer = new StringBuilder("SELECT ");
if (findOptions.getDistinct()) {
sqlBuffer.append("DISTINCT ");
}
if (selectFields.size() > 0) {
sqlBuffer.append(modelEntity.colNameString(selectFields, ", ", "", datasourceInfo.aliasViews));
} else {
sqlBuffer.append("*");
}
// populate the info from entity-condition in the view-entity, if it is one and there is one
List<EntityCondition> viewWhereConditions = null;
List<EntityCondition> viewHavingConditions = null;
List<String> viewOrderByList = null;
if (modelViewEntity != null) {
viewWhereConditions = FastList.newInstance();
viewHavingConditions = FastList.newInstance();
viewOrderByList = FastList.newInstance();
modelViewEntity.populateViewEntityConditionInformation(modelFieldTypeReader, viewWhereConditions, viewHavingConditions, viewOrderByList, null);
}
// FROM clause and when necessary the JOIN or LEFT JOIN clause(s) as well
sqlBuffer.append(SqlJdbcUtil.makeFromClause(modelEntity, datasourceInfo));
// WHERE clause
List<EntityConditionParam> whereEntityConditionParams = FastList.newInstance();
StringBuilder whereString = makeConditionWhereString(modelEntity, whereEntityCondition, viewWhereConditions, whereEntityConditionParams);
if (whereString.length() > 0) {
sqlBuffer.append(" WHERE ");
sqlBuffer.append(whereString.toString());
}
// GROUP BY clause for view-entity
if (modelViewEntity != null) {
String groupByString = modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(selectFields), ", ", "", false);
if (UtilValidate.isNotEmpty(groupByString)) {
sqlBuffer.append(" GROUP BY ");
sqlBuffer.append(groupByString);
}