示例#1
0
  /**
   * Search
   *
   * @param callbackObject
   * @throws CloudException
   * @throws IOException
   * @throws ExecutionException
   * @throws InterruptedException
   * @throws JSONException
   */
  public void search(CloudObjectArrayCallback callbackObject) throws CloudException {
    String collectionString;
    if (this.collectionArray.size() > 0) {

      collectionString = "";
      for (int i = 0; i < this.collectionArray.size(); i++) {
        collectionString +=
            (i > 0 ? "," + this.collectionArray.get(i) : this.collectionArray.get(i));
      }
      this.collectionName = collectionString;
    } else {
      collectionString = this.collectionName;
    }
    try {
      this.query.put("filtered", this.filtered);
      JSONObject params = new JSONObject();
      params.put("collectionName", collectionString);

      params.put("query", this.query);
      params.put("sort", this.sort);
      params.put("limit", this.size);
      params.put("skip", this.from);
      params.put("key", CloudApp.getAppKey());
      String url =
          CloudApp.getServerUrl()
              + "/data/"
              + CloudApp.getAppId()
              + "/"
              + this.collectionName
              + "/search";
      CBResponse response = CBParser.callJson(url, "POST", params);

      if (response.getStatusCode() == 200) {
        JSONArray body = new JSONArray(response.getResponseBody());
        CloudObject[] object = new CloudObject[body.length()];

        for (int i = 0; i < object.length; i++) {
          object[i] = new CloudObject(body.getJSONObject(i).get("_tableName").toString());
          object[i].document = body.getJSONObject(i);
        }
        callbackObject.done(object, null);
      } else {
        CloudException e = new CloudException(response.getError());
        callbackObject.done((CloudObject[]) null, e);
      }
    } catch (JSONException e) {
      CloudException ee = new CloudException(e.getMessage());
      callbackObject.done((CloudObject[]) null, ee);
    }
  }
示例#2
0
  public static void main(String[] args) throws CloudException {
    CloudApp.init("cpnbzclvxjts", "67d3f4e4-97e6-4f2b-91af-d553b9160e20");
    SearchFilter filter = new SearchFilter();
    filter.exists("name");
    CloudSearch search = new CloudSearch("data", null, filter);
    search.search(
        new CloudObjectArrayCallback() {

          @Override
          public void done(CloudObject[] x, CloudException t) throws CloudException {
            // TODO Auto-generated method stub

          }
        });
  }