if (query.getSortOrder() != WorkflowExpressionQuery.SORT_NONE) { sel.append(" ORDER BY ");  if (query.getOrderBy() != 0) {  String fName = fieldName(query.getOrderBy());  if (log.isDebugEnabled()) { log.debug("Found fieldName as: " + fName); }  sel.append(fName);   String current = sel.toString();       String entry = current.substring(0, current.indexOf(columnName)) + columnName + ") , " + fName + " "; entry += current.substring(current.indexOf(columnName) + columnName.length() + 1);  sel = new StringBuffer(entry);  if (query.getSortOrder() == WorkflowExpressionQuery.SORT_ASC) { sel.append(" ASC"); } else { sel.append(" DESC"); }  if (log.isDebugEnabled()) { log.debug("Finalized query: " + sel.toString()); } } else {  sel.append(columnName); } }  if (log.isDebugEnabled()) { log.debug("Finished query is: " + sel.toString()); }  List results = doExpressionQuery(sel.toString(), columnName, values);  return results;
    public List query(WorkflowExpressionQuery query) throws StoreException {        Expression expression = query.getExpression();        StringBuffer sel = new StringBuffer();        List values = new ArrayList();        String columnName = null;        if (expression.isNested()) {            columnName = buildNested((NestedExpression) expression, sel, values);        } else {            columnName = buildSimple((FieldExpression) expression, sel, values);        }        if (query.getSortOrder() != WorkflowExpressionQuery.SORT_NONE) {            sel.append(" ORDER BY ");            if (query.getOrderBy() != 0) {                // Had the unexpected result of doing a "ORDER BY 1" w/o this in place                String fName = fieldName(query.getOrderBy());                if (log.isDebugEnabled()) {                    log.debug("Found fieldName as: " + fName);                }                sel.append(fName);                // In MySQL and Informix, you have to select any field you order by -- others?                String current = sel.toString();                // Remember that it will be surrounded by "DISTINCT (XXXX)"                // Should already be formatted as:                //      SELECT DISTINCT(columnName) FROM table WHERE ......                // Want to be in the format:                //      SELECT DISTINCT(columnName), fName FROM table WHERE .......                String entry = current.substring(0, current.indexOf(columnName)) + columnName + ") , " + fName + " ";                entry += current.substring(current.indexOf(columnName) + columnName.length() + 1);                sel = new StringBuffer(entry);                if (query.getSortOrder() == WorkflowExpressionQuery.SORT_ASC) {                    sel.append(" ASC");                } else {                    sel.append(" DESC");                }                if (log.isDebugEnabled()) {                    log.debug("Finalized query: " + sel.toString());                }            } else {                // Order by is empty, so order by the columnName                sel.append(columnName);            }        }        if (log.isDebugEnabled()) {            log.debug("Finished query is: " + sel.toString());        }        List results = doExpressionQuery(sel.toString(), columnName, values);        return results;    }