コード例 #1
0
 private int executeCountQuery(String tableId, String countQuery) throws SynapseException {
   String jobToken =
       synapseAdmin.queryTableEntityBundleAsyncStart(countQuery, 0L, 1L, true, 1, tableId);
   QueryResultBundle qrb = null;
   long backoff = 100L;
   for (int i = 0; i < 100; i++) {
     try {
       qrb = synapseAdmin.queryTableEntityBundleAsyncGet(jobToken, tableId);
       break;
     } catch (SynapseResultNotReadyException e) {
       // keep waiting
       try {
         Thread.sleep(backoff);
       } catch (InterruptedException ie) {
         // continue
       }
       backoff *= 2L;
     }
   }
   if (qrb == null) throw new RuntimeException("Query failed to return");
   List<Row> rows = qrb.getQueryResult().getQueryResults().getRows();
   if (rows.size() != 1)
     throw new RuntimeException(
         "Expected one row for count query result but found " + rows.size());
   Row row = rows.get(0);
   List<String> rowValues = row.getValues();
   if (rowValues.size() != 1)
     throw new RuntimeException(
         "Expected one column for count query result but found " + rows.size());
   return Integer.parseInt(rowValues.get(0));
 }