queries.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import com.orientechnologies.orient.core.record.impl.ODocument;
  2. import java.util.HashMap;
  3. import permeagility.plus.json.JSONArray;
  4. import permeagility.plus.json.JSONObject;
  5. import permeagility.util.DatabaseConnection;
  6. import permeagility.web.Download;
  7. /** Test type 3: Multiple Database Queries
  8. */
  9. public final class queries extends Download {
  10. @Override public String getContentType() { return "application/json"; }
  11. @Override public String getContentDisposition() { return null; }
  12. @Override public byte[] getBytes(DatabaseConnection con, HashMap<String, String> parms) {
  13. String q = parms.get("queries");
  14. int qn = -1;
  15. try {
  16. qn = Integer.parseInt(q);
  17. } catch (Exception e) {
  18. }
  19. if (qn < 1) qn = 1;
  20. if (qn > 500) qn = 500;
  21. JSONArray ja = new JSONArray();
  22. int i = 0;
  23. do {
  24. JSONObject jo = new JSONObject();
  25. ODocument d = con.queryDocument("SELECT FROM World WHERE id="+Math.random()*10000);
  26. if (d != null) {
  27. jo.put("id", (int)d.field("id"));
  28. jo.put("randomNumber", (int)d.field("randomNumber"));
  29. ja.put(jo);
  30. i++;
  31. }
  32. } while (i < qn);
  33. return ja.toString().getBytes();
  34. }
  35. }