sqlBuffer.append(whereString.toString());
}
// GROUP BY clause for view-entity
if (modelEntity instanceof ModelViewEntity) {
ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity;
String groupByString = modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), ", ", "", false);
if (UtilValidate.isNotEmpty(groupByString)) {
sqlBuffer.append(" GROUP BY ");
sqlBuffer.append(groupByString);
}
}
// HAVING clause
String entityCondHavingString = "";
List havingEntityConditionParams = FastList.newInstance();
if (havingEntityCondition != null) {
entityCondHavingString = havingEntityCondition.makeWhereString(modelEntity, havingEntityConditionParams, this.datasourceInfo);
}
if (entityCondHavingString.length() > 0) {
sqlBuffer.append(" HAVING ");
sqlBuffer.append(entityCondHavingString);
}
String sql = sqlBuffer.toString();
SQLProcessor sqlP = new SQLProcessor(helperName);
sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(), findOptions.getResultSetType(),
findOptions.getResultSetConcurrency(), findOptions.getFetchSize(), findOptions.getMaxRows());
if (verboseOn) {
// put this inside an if statement so that we don't have to generate the string when not used...
Debug.logVerbose("Setting the whereEntityConditionParams: " + whereEntityConditionParams, module);
}
// set all of the values from the Where EntityCondition
Iterator whereEntityConditionParamsIter = whereEntityConditionParams.iterator();
while (whereEntityConditionParamsIter.hasNext()) {
EntityConditionParam whereEntityConditionParam = (EntityConditionParam) whereEntityConditionParamsIter.next();
SqlJdbcUtil.setValue(sqlP, whereEntityConditionParam.getModelField(), modelEntity.getEntityName(), whereEntityConditionParam.getFieldValue(), modelFieldTypeReader);
}
if (verboseOn) {
// put this inside an if statement so that we don't have to generate the string when not used...
Debug.logVerbose("Setting the havingEntityConditionParams: " + havingEntityConditionParams, module);
}
// set all of the values from the Having EntityCondition
Iterator havingEntityConditionParamsIter = havingEntityConditionParams.iterator();
while (havingEntityConditionParamsIter.hasNext()) {
EntityConditionParam havingEntityConditionParam = (EntityConditionParam) havingEntityConditionParamsIter.next();
SqlJdbcUtil.setValue(sqlP, havingEntityConditionParam.getModelField(), modelEntity.getEntityName(), havingEntityConditionParam.getFieldValue(), modelFieldTypeReader);
}
try {
sqlP.executeQuery();
long count = 0;
ResultSet resultSet = sqlP.getResultSet();
boolean isGroupBy = false;
if (modelEntity instanceof ModelViewEntity) {
ModelViewEntity modelViewEntity = (ModelViewEntity) modelEntity;
String groupByString = modelViewEntity.colNameString(modelViewEntity.getGroupBysCopy(), ", ", "", false);
if (UtilValidate.isNotEmpty(groupByString)) {
isGroupBy = true;
}
}
if (isGroupBy) {