Method to retrieve records for the given list of query in asynchronous fashion

@param query
@param callbackHandler
the callback handler
@throws FMSException
971045
public void executeQueryAsync(String query, CallbackHandler callbackHandler) throws FMSException {
        IntuitMessage intuitMessage = prepareQuery(query);

        //set callback handler
        intuitMessage.getRequestElements().setCallbackHandler(callbackHandler);

        //execute async interceptors
        executeAsyncInterceptors(intuitMessage);
    }
1159289
private JsonArray getRecordsForQuery(SalesforceConnector connector, String query) {
    try {
      String soqlQuery = SalesforceExtractor.getSoqlUrl(query);
      List<Command> commands = RestApiConnector.constructGetCommand(connector.getFullUri(soqlQuery));
      CommandOutput<?, ?> response = connector.getResponse(commands);

      String output;
      Iterator<String> itr = (Iterator<String>) response.getResults().values().iterator();
      if (itr.hasNext()) {
        output = itr.next();
      } else {
        throw new DataRecordException("Failed to get data from salesforce; REST response has no output");
      }

      return GSON.fromJson(output, JsonObject.class).getAsJsonArray("records");
    } catch (RestApiClientException | RestApiProcessingException | DataRecordException e) {
      throw new RuntimeException("Fail to get data from salesforce", e);
    }
  }
992742
public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException
    {
        Class itemClass = query.getSearchClass();
        ClassDescriptor cld = getClassDescriptor(itemClass);
        return getIteratorFromQuery(query, cld);
    }
1084144
public List<QueryResult> executeQuery() throws SQLException {
        final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
        SQLExecuteCallback<QueryResult> executeCallback = new SQLExecuteCallback<QueryResult>(getDatabaseType(), isExceptionThrown) {
            
            @Override
            protected QueryResult executeSQL(final RouteUnit routeUnit, final Statement statement, final ConnectionMode connectionMode) throws SQLException {
                return getQueryResult(routeUnit, statement, connectionMode);
            }
        };
        return executeCallback(executeCallback);
    }
183555
protected void prepareQuery(org.hibernate.query.Query query) {
        if (cacheQueries) {
            query.setCacheable(true);
        }
        if (shouldPassReadOnlyToHibernate()) {
            query.setReadOnly(true);
        }
        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
        if (sessionHolder != null && sessionHolder.hasTimeout()) {
            query.setTimeout(sessionHolder.getTimeToLiveInSeconds());
        }
    }
17359
public void search(String query) {
        final Query newQuery = searcher.getQuery().setQuery(query);
        searcher.setQuery(newQuery).search();
    }
1211380
private void handleQueries(
      final HttpServletResponse response,
      final Map<String, List<String>> queries,
      final String version) throws IOException {

    LOG.log(Level.INFO, "HttpServerReefEventHandler handleQueries is called");

    for (final Map.Entry<String, List<String>> entry : queries.entrySet()) {
      final String queryTarget = entry.getKey().toLowerCase();

      switch (queryTarget) {
      case "id":
        if (version.equals(VER)) {
          writeEvaluatorInfoJsonOutput(response, entry.getValue());
        } else {
          writeEvaluatorInfoWebOutput(response, entry.getValue());
        }
        break;
      default:
        response.getWriter().println("Unsupported query : " + queryTarget);
        break;
      }
    }
  }
1138021
public Deferred<SearchQuery> executeSearch(final SearchQuery query) {
    if (search == null) {
      throw new IllegalStateException(
          "Searching has not been enabled on this TSD");
    }

    return search.executeQuery(query);
  }
1325082
private void sequenceQuery(QueryEntry entry, ServerSessionContext session, CompletableFuture<QueryResponse> future) {
    // If the query's sequence number is greater than the session's current sequence number, queue the request for
    // handling once the state machine is caught up.
    if (entry.getSequence() > session.getCommandSequence()) {
      session.registerSequenceQuery(entry.getSequence(), () -> indexQuery(entry, future));
    } else {
      indexQuery(entry, future);
    }
  }
237026
@Override
    public synchronized List<Map<String, ResultColumn>> query(final Expression query) throws DatabaseEngineException {
        return query(translate(query));
    }
1181155
function query(p, callback) {
		if (p.data) {
			extend(p.query, p.data);
			p.data = null;
		}

		callback(p.path);
	}
449636
private void handleLastDataPointQuery(final TSDB tsdb, final HttpQuery query) {
    
    final LastPointQuery data_query;
    if (query.method() == HttpMethod.POST) {
      switch (query.apiVersion()) {
      case 0:
      case 1:
        data_query = query.serializer().parseLastPointQueryV1();
        break;
      default: 
        throw new BadRequestException(HttpResponseStatus.NOT_IMPLEMENTED, 
            "Requested API version not implemented", "Version " + 
            query.apiVersion() + " is not implemented");
      }
    } else {
      data_query = this.parseLastPointQuery(tsdb, query);
    }
    
    if (data_query.sub_queries == null || data_query.sub_queries.isEmpty()) {
      throw new BadRequestException(HttpResponseStatus.BAD_REQUEST, 
          "Missing sub queries");
    }
    
    // a list of deferreds to wait on
    final ArrayList<Deferred<Object>> calls = new ArrayList<Deferred<Object>>();
    // final results for serialization
    final List<IncomingDataPoint> results = new ArrayList<IncomingDataPoint>();
    
    /**
     * Used to catch exceptions 
     */
    final class ErrBack implements Callback<Object, Exception> {
      public Object call(final Exception e) throws Exception {
        Throwable ex = e;
        while (ex.getClass().equals(DeferredGroupException.class)) {
          if (ex.getCause() == null) {
            LOG.warn("Unable to get to the root cause of the DGE");
            break;
          }
          ex = ex.getCause();
        }
        if (ex instanceof RuntimeException) {
          throw new BadRequestException(ex);
        } else {
          throw e;
        }
      }
      @Override
      public String toString() {
        return "Error back";
      }
    }
    
    final class FetchCB implements Callback<Deferred<Object>, ArrayList<IncomingDataPoint>> {
      @Override
      public Deferred<Object> call(final ArrayList<IncomingDataPoint> dps) throws Exception {
        synchronized(results) {
          for (final IncomingDataPoint dp : dps) {
            if (dp != null) {
              results.add(dp);
            }
          }
        }
        return Deferred.fromResult(null);
      }
      @Override
      public String toString() {
        return "Fetched data points CB";
      }
    }
    
    /**
     * Called after scanning the tsdb-meta table for TSUIDs that match the given
     * metric and/or tags. If matches were found, it fires off a number of
     * getLastPoint requests, adding the deferreds to the calls list
     */
    final class TSUIDQueryCB implements Callback<Deferred<Object>, ByteMap<Long>> {
      public Deferred<Object> call(final ByteMap<Long> tsuids) throws Exception {
        if (tsuids == null || tsuids.isEmpty()) {
          return null;
        }
        final ArrayList<Deferred<IncomingDataPoint>> deferreds =
            new ArrayList<Deferred<IncomingDataPoint>>(tsuids.size());
        for (Map.Entry<byte[], Long> entry : tsuids.entrySet()) {
          deferreds.add(TSUIDQuery.getLastPoint(tsdb, entry.getKey(), 
              data_query.getResolveNames(), data_query.getBackScan(), 
              entry.getValue()));
        }
        return Deferred.group(deferreds).addCallbackDeferring(new FetchCB());
      }
      @Override
      public String toString() {
        return "TSMeta scan CB";
      }
    }

    /**
     * Used to wait on the list of data point deferreds. Once they're all done
     * this will return the results to the call via the serializer
     */
    final class FinalCB implements Callback<Object, ArrayList<Object>> {
      public Object call(final ArrayList<Object> done) throws Exception {
        query.sendReply(query.serializer().formatLastPointQueryV1(results));
        return null;
      }
      @Override
      public String toString() {
        return "Final CB";
      }
    }
    
    try {   
      // start executing the queries
      for (final LastPointSubQuery sub_query : data_query.getQueries()) {
        final ArrayList<Deferred<IncomingDataPoint>> deferreds =
            new ArrayList<Deferred<IncomingDataPoint>>();
        // TSUID queries take precedence so if there are any TSUIDs listed, 
        // process the TSUIDs and ignore the metric/tags
        if (sub_query.getTSUIDs() != null && !sub_query.getTSUIDs().isEmpty()) {
          for (final String tsuid : sub_query.getTSUIDs()) {
            final TSUIDQuery tsuid_query = new TSUIDQuery(tsdb, 
                UniqueId.stringToUid(tsuid));
            deferreds.add(tsuid_query.getLastPoint(data_query.getResolveNames(), 
                data_query.getBackScan()));
          }
        } else {
          @SuppressWarnings("unchecked")
          final TSUIDQuery tsuid_query = 
              new TSUIDQuery(tsdb, sub_query.getMetric(), 
                  sub_query.getTags() != null ? 
                      sub_query.getTags() : Collections.EMPTY_MAP);
          if (data_query.getBackScan() > 0) {
            deferreds.add(tsuid_query.getLastPoint(data_query.getResolveNames(), 
                data_query.getBackScan()));
          } else {
            calls.add(tsuid_query.getLastWriteTimes()
                .addCallbackDeferring(new TSUIDQueryCB()));
          }
        }
        
        if (deferreds.size() > 0) {
          calls.add(Deferred.group(deferreds).addCallbackDeferring(new FetchCB()));
        }
      }
      
      Deferred.group(calls)
        .addCallback(new FinalCB())
        .addErrback(new ErrBack())
        .joinUninterruptibly();
      
    } catch (Exception e) {
      Throwable ex = e;
      while (ex.getClass().equals(DeferredGroupException.class)) {
        if (ex.getCause() == null) {
          LOG.warn("Unable to get to the root cause of the DGE");
          break;
        }
        ex = ex.getCause();
      }
      if (ex instanceof RuntimeException) {
        throw new BadRequestException(ex);
      } else {
        throw new RuntimeException("Shouldn't be here", e);
      }
    }
  }
59788
public void queryService(List<StringCommand> commands, final QueryServiceCallback cb, Object context){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.QueryService);

        List<QueryCommand> cs = new ArrayList<QueryCommand>();
        for(StringCommand c : commands){
            cs.add(c.getStringCommand());
        }

        QueryServiceProtocol p = new QueryServiceProtocol(cs);

        ProtocolCallback pcb = new ProtocolCallback(){

            @Override
            public void call(boolean result, Response response,
                    ErrorCode error, Object ctx) {
                List<ModelServiceInstance> rsp = null;
                if(response != null){
                    rsp = ((QueryServiceResponse) response).getInstances();
                }
                cb.call(result, rsp, error, ctx);
            }

        };

        connection.submitCallbackRequest(header, p, pcb, context);
    }
10827
protected <T> ArrayList<T> loadAll (final Table<T> table,
                                        final String query)
        throws PersistenceException
    {
        return execute(new Operation<ArrayList<T>>() {
            public ArrayList<T> invoke (
                Connection conn, DatabaseLiaison liaison)
                throws SQLException, PersistenceException
            {
                return table.select(conn, query).toArrayList();
            }
        });
    }
479975
public List<T> query(String query, QueryType type)
    {
        switch (type)
        {
        case JPQL:
            return query(query);

        case NATIVE:
            return nativeQuery(query);

        default:
            throw new KunderaException("invalid query type");
        }
    }
18566
public <T extends IEntity> void uploadAsync(T entity, InputStream docContent, CallbackHandler callbackHandler) throws FMSException {

        IntuitMessage intuitMessage = prepareUpload(entity, docContent);

        //set callback handler
        intuitMessage.getRequestElements().setCallbackHandler(callbackHandler);

        //execute async interceptors
        executeAsyncInterceptors(intuitMessage);
    }
1190337
function load(query, callback) {
      if (!query.length) return callback();

      pagelet.complete(query, function complete(err, results) {
        if (err) return callback();

        callback(results);
      });
    }