
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import java.util.HashMap;
import permeagility.plus.json.JSONArray;
import permeagility.plus.json.JSONObject;
import permeagility.util.DatabaseConnection;
import permeagility.web.Download;

/** Test type 3: Multiple Database Queries
 */
public class queries extends Download {

    @Override public String getContentType() { return "application/json"; }
    
    @Override public String getContentDisposition() { return null; }
    
    @Override public byte[] getBytes(DatabaseConnection con, HashMap<String, String> parms) {
         String q = parms.get("queries");
        int qn = -1;
        try { 
            qn = Integer.parseInt(q);
        } catch (Exception e) {
        }
        if (qn < 1) qn = 500;

//        JSONArray ja = new JSONArray();
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        String comma = "";
        for (int i=0; i<qn; i++) {
//            JSONObject jo = new JSONObject();
            ODocument d = con.queryDocument("SELECT FROM World WHERE id="+Math.random()*10000);
            if (d != null) {
                sb.append(comma+"{\"id\":"+d.field("id")+",\"randomNumber\":+"+d.field("randomNumber")+"}");
                if (comma.isEmpty()) comma = ",";
                //jo.put("id", );
                //jo.put("randomNumber", );
                //ja.put(jo);
            }
        }
//        return ja.toString().getBytes();
        sb.append("]");
        return sb.toString().getBytes();
    }

}

@@ -1,68 +1,4 @@
-%0Aimport com.orientechnologies.orient.core.metadata.schema.OType;
 %0Aimp
@@ -773,18 +773,16 @@
 = 500;%0A%0A
-//
         
@@ -817,107 +817,8 @@
 ();%0A
-        StringBuilder sb = new StringBuilder();%0A        sb.append(%22%5B%22);%0A        String comma = %22%22;%0A
     
@@ -848,18 +848,16 @@
  i++) %7B%0A
-//
         
@@ -1039,209 +1039,93 @@
     
-sb.append(comma+%22%7B%5C%22id%5C%22:%22+d.field(%22id%22)+%22,%5C%22randomNumber%5C%22:+%22+d.field(%22randomNumber%22)+%22%7D%22);%0A                if (comma.isEmpty()) comma = %22,%22;%0A                //jo.put(%22id%22, );%0A                //jo.put
+jo.put(%22id%22, (int)d.field(%22id%22));%0A                jo.put(%22randomNumber%22, (int)d.field
 (%22ra
@@ -1135,18 +1135,17 @@
 mNumber%22
-, 
+)
 );%0A     
@@ -1155,18 +1155,16 @@
         
-//
 ja.put(j
@@ -1195,10 +1195,8 @@
   %7D%0A
-//
     
@@ -1236,73 +1236,8 @@
 ();%0A
-        sb.append(%22%5D%22);%0A        return sb.toString().getBytes();%0A
     

Update queries to use JSONObject