code: protected void appendOrderByClause(List orderByFields, List selectedFields, StringBuffer buf)
      {
  
          if (orderByFields == null || orderByFields.size() == 0)
          {
              return;
          }
          
          buf.append(" ORDER BY ");
          for (int i = 0; i < orderByFields.size(); i++)
          {
              FieldHelper cf = (FieldHelper) orderByFields.get(i);
              int colNumber = selectedFields.indexOf(cf.name);
              
              if (i > 0)
              {
                  buf.append(",");
              }
              
              if (colNumber >= 0)
              {
                  buf.append(colNumber + 1);                
              }
              else
              {            
                  appendColName(cf.name, false, null, buf);
              }
              
              if (!cf.isAscending)
              {
                  buf.append(" DESC");
              }
          }
      }
docs: Appends the ORDER BY clause for the Query.
  <br>
  If the orderByField is found in the list of selected fields it's index is added.
  Otherwise it's name is added.
  @param orderByFields
  @param selectedFields the names of the fields in the SELECT clause
  @param buf