Returns the set of data for a query.
@param accountId The id of the account to query
@param query The NRQL query to execute
@return The query data
169125
public Optional<QueryData> list(long accountId, String query)
    {
        QueryParameterList queryParams = new QueryParameterList();
        queryParams.add("nrql", encode(query));
        return HTTP.GET(String.format("/v1/accounts/%d/query", accountId), null, queryParams, QUERY_DATA);
    }
81881
@Override
  public ResultSet executeQuery(String sql) throws SQLException
  {
    raiseSQLExceptionIfStatementIsClosed();
    return executeQueryInternal(sql, null);
  }
362885
public <T extends SingleThreadSetQuery.Result<SetType, RuntimeType, ThreadType>> T query(SingleThreadSetQuery<T> query) {
        return query.<SetType, RuntimeType, ThreadType>query((SetType) this);
    }
548420
@Override
    public <R> R query(MonetaryQuery<R> query) {
        Objects.requireNonNull(query);
        try {
            return query.queryFrom(this);
        } catch (MonetaryException ex) {
            throw ex;
        } catch (RuntimeException ex) {
            throw new LocalizedMonetaryException("query failed", query, ex);
        }
    }
815636
protected Response getCalls(final String accountSid, UriInfo info,
                                MediaType responseType,
                                UserIdentityContext userIdentityContex) {
        Account account = daos.getAccountsDao().getAccount(accountSid);
        permissionEvaluator.secure(account, "RestComm:Read:Calls", userIdentityContex);

        boolean localInstanceOnly = true;
        try {
            String localOnly = info.getQueryParameters().getFirst("localOnly");
            if (localOnly != null && localOnly.equalsIgnoreCase("false"))
                localInstanceOnly = false;
        } catch (Exception e) {
        }
        // shall we include sub-accounts cdrs in our query ?
        boolean querySubAccounts = false; // be default we don't
        String querySubAccountsParam = info.getQueryParameters().getFirst("SubAccounts");
        if (querySubAccountsParam != null && querySubAccountsParam.equalsIgnoreCase("true"))
            querySubAccounts = true;

        String pageSize = info.getQueryParameters().getFirst("PageSize");
        String page = info.getQueryParameters().getFirst("Page");
        // String afterSid = info.getQueryParameters().getFirst("AfterSid");
        String recipient = info.getQueryParameters().getFirst("To");
        String sender = info.getQueryParameters().getFirst("From");
        String status = info.getQueryParameters().getFirst("Status");
        String startTime = info.getQueryParameters().getFirst("StartTime");
        String endTime = info.getQueryParameters().getFirst("EndTime");
        String parentCallSid = info.getQueryParameters().getFirst("ParentCallSid");
        String conferenceSid = info.getQueryParameters().getFirst("ConferenceSid");
        String reverse = info.getQueryParameters().getFirst("Reverse");

        // Format for sorting URL parameter is '?SortBy=<field>:<direction>', for example: '?SortBy=date_created:asc'. In the
        // future we can extend it to multiple sort fields, like ?SortBy=<field1>:<direction1>,<field2>:<direction2>
        String sortParameters = info.getQueryParameters().getFirst("SortBy");

        // Even though 'Reverse=true/false' URL query parameter isn't documented, old console is using it, so we need
        // to make sure we are backwards compatible:
        // - If 'Reverse' is found in the URL but SortBy is not found then we deem that we are servicing an old version of Console
        //   and we should support sorting only for Date field and translate as follows:
        //   > 'Reverse=true': corresponds to SortBy=DateCreated:desc
        //   > 'Reverse=false': corresponds to SortBy=DateCreated:asc
        // - If Reverse is found in the URL but SortBy is also found we just discard 'Reverse' and service request normally
        // - If only 'SortBy' is found in the URL then we service the request normally
        if (reverse != null && sortParameters == null) {
            if (reverse.equalsIgnoreCase("true")) {
                sortParameters = SORTING_URL_PARAM_DATE_CREATED + ":" + Sorting.Direction.DESC.name();
            }
            else {
                sortParameters = SORTING_URL_PARAM_DATE_CREATED + ":" + Sorting.Direction.ASC.name();
            }
        }

        CallDetailRecordFilter.Builder filterBuilder = CallDetailRecordFilter.Builder.builder();

        String sortBy = null;
        String sortDirection = null;

        if (sortParameters != null && !sortParameters.isEmpty()) {
            try {
                Map<String, String> sortMap = Sorting.parseUrl(sortParameters);
                sortBy = sortMap.get(Sorting.SORT_BY_KEY);
                sortDirection = sortMap.get(Sorting.SORT_DIRECTION_KEY);
            }
            catch (Exception e) {
                return status(BAD_REQUEST).entity(buildErrorResponseBody(e.getMessage(), responseType)).build();
            }
        }

        if (sortBy != null) {
            if (sortBy.equals(SORTING_URL_PARAM_DATE_CREATED)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByDate(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByDate(Sorting.Direction.DESC);
                    }
                }
            }
            if (sortBy.equals(SORTING_URL_PARAM_FROM)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByFrom(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByFrom(Sorting.Direction.DESC);
                    }
                }
            }
            if (sortBy.equals(SORTING_URL_PARAM_TO)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByTo(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByTo(Sorting.Direction.DESC);
                    }
                }
            }
            if (sortBy.equals(SORTING_URL_PARAM_DIRECTION)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByDirection(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByDirection(Sorting.Direction.DESC);
                    }
                }
            }
            if (sortBy.equals(SORTING_URL_PARAM_STATUS)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByStatus(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByStatus(Sorting.Direction.DESC);
                    }
                }
            }
            if (sortBy.equals(SORTING_URL_PARAM_DURATION)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByDuration(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByDuration(Sorting.Direction.DESC);
                    }
                }
            }
            if (sortBy.equals(SORTING_URL_PARAM_PRICE)) {
                if (sortDirection != null) {
                    if (sortDirection.equalsIgnoreCase(Sorting.Direction.ASC.name())) {
                        filterBuilder.sortedByPrice(Sorting.Direction.ASC);
                    } else {
                        filterBuilder.sortedByPrice(Sorting.Direction.DESC);
                    }
                }
            }
        }

        if (pageSize == null) {
            pageSize = "50";
        }

        if (page == null) {
            page = "0";
        }

        int limit = Integer.parseInt(pageSize);
        int offset = (page == "0") ? 0 : (((Integer.parseInt(page) - 1) * Integer.parseInt(pageSize)) + Integer
                .parseInt(pageSize));

        // Shall we query cdrs of sub-accounts too ?
        // if we do, we need to find the sub-accounts involved first
        List<String> ownerAccounts = null;
        if (querySubAccounts) {
            ownerAccounts = new ArrayList<String>();
            ownerAccounts.add(accountSid); // we will also return parent account cdrs
            ownerAccounts.addAll(accountsDao.getSubAccountSidsRecursive(new Sid(accountSid)));
        }

        CallDetailRecordsDao dao = daos.getCallDetailRecordsDao();

        filterBuilder.byAccountSid(accountSid)
                .byAccountSidSet(ownerAccounts)
                .byRecipient(recipient)
                .bySender(sender)
                .byStatus(status)
                .byStartTime(startTime)
                .byEndTime(endTime)
                .byParentCallSid(parentCallSid)
                .byConferenceSid(conferenceSid)
                .limited(limit, offset);
        if (!localInstanceOnly) {
            filterBuilder.byInstanceId(instanceId);
        }

        CallDetailRecordFilter filter;
        try {
            filter = filterBuilder.build();
        } catch (ParseException e) {
            return status(BAD_REQUEST).build();
        }

        final int total = dao.getTotalCallDetailRecords(filter);

        if (Integer.parseInt(page) > (total / limit)) {
            return status(javax.ws.rs.core.Response.Status.BAD_REQUEST).build();
        }

        final List<CallDetailRecord> cdrs = dao.getCallDetailRecords(filter);

        listConverter.setCount(total);
        listConverter.setPage(Integer.parseInt(page));
        listConverter.setPageSize(Integer.parseInt(pageSize));
        listConverter.setPathUri("/" + getApiVersion(null) + "/" + info.getPath());

        if (APPLICATION_XML_TYPE.equals(responseType)) {
            final RestCommResponse response = new RestCommResponse(new CallDetailRecordList(cdrs));
            return ok(xstream.toXML(response), APPLICATION_XML).build();
        } else if (APPLICATION_JSON_TYPE.equals(responseType)) {
            return ok(gson.toJson(new CallDetailRecordList(cdrs)), APPLICATION_JSON).build();
        } else {
            return null;
        }
    }
739870
@Override
    protected List<IPersonAttributes> getPeopleForQuery(final PartialWhereClause queryBuilder, final String queryUserName) {
        //Execute the query
        final RowMapper<R> rowMapper = this.getRowMapper();

        final List<R> results;
        if (queryBuilder != null) {
            //Merge the generated SQL with the base query template
            final StringBuilder partialSqlWhere = queryBuilder.sql;
            final Matcher queryMatcher = WHERE_PLACEHOLDER.matcher(this.queryTemplate);
            final String querySQL = queryMatcher.replaceAll(partialSqlWhere.toString());

            results = this.simpleJdbcTemplate.query(querySQL, rowMapper, queryBuilder.arguments.toArray());

            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Executed '" + this.queryTemplate + "' with arguments " + queryBuilder.arguments + " and got results " + results);
            }
        } else {
            results = this.simpleJdbcTemplate.query(this.queryTemplate, rowMapper);

            if (this.logger.isDebugEnabled()) {
                this.logger.debug("Executed '" + this.queryTemplate + "' and got results " + results);
            }
        }

        return this.parseAttributeMapFromResults(results, queryUserName);
    }
1064751
protected final List<T> findByQuery(String query, Object... params) {
        return this.dataAccess.findByQuery(query, params);
    }
691573
@Nullable
    public T query() throws SQLException {
        try (ResultSet r = executeQuery()) {
            if (r.next()) {
                return resultMapper.map(r);
            }
            return null;
        }
    }
674910
public void configureQuery(ListQueryParameterObject query) {

    AuthorizationCheck authCheck = query.getAuthCheck();
    authCheck.getPermissionChecks().clear();

    if(isAuthCheckExecuted()) {
      Authentication currentAuthentication = getCurrentAuthentication();
      authCheck.setAuthUserId(currentAuthentication.getUserId());
      authCheck.setAuthGroupIds(currentAuthentication.getGroupIds());
      enableQueryAuthCheck(authCheck);
    }
    else {
      authCheck.setAuthorizationCheckEnabled(false);
      authCheck.setAuthUserId(null);
      authCheck.setAuthGroupIds(null);
    }
  }
465139
public Object getObjectByQuery(Query query) throws PersistenceBrokerException
    {
        Object result = null;
        if (query instanceof QueryByIdentity)
        {
            // example obj may be an entity or an Identity
            Object obj = query.getExampleObject();
            if (obj instanceof Identity)
            {
                Identity oid = (Identity) obj;
                result = getObjectByIdentity(oid);
            }
            else
            {
                // TODO: This workaround doesn't allow 'null' for PK fields
                if (!serviceBrokerHelper().hasNullPKField(getClassDescriptor(obj.getClass()), obj))
                {
                    Identity oid = serviceIdentity().buildIdentity(obj);
                    result = getObjectByIdentity(oid);
                }
            }
        }
        else
        {
            Class itemClass = query.getSearchClass();
            ClassDescriptor cld = getClassDescriptor(itemClass);
            /*
            use OJB intern Iterator, thus we are able to close used
            resources instantly
            */
            OJBIterator it = getIteratorFromQuery(query, cld);
            /*
            arminw:
            patch by Andre Clute, instead of taking the first found result
            try to get the first found none null result.
            He wrote:
            I have a situation where an item with a certain criteria is in my
            database twice -- once deleted, and then a non-deleted version of it.
            When I do a PB.getObjectByQuery(), the RsIterator get's both results
            from the database, but the first row is the deleted row, so my RowReader
            filters it out, and do not get the right result.
            */
            try
            {
                while (result==null && it.hasNext())
                {
                    result = it.next();
                }
            } // make sure that we close the used resources
            finally
            {
                if(it != null) it.releaseDbResources();
            }
        }
        return result;
    }
721075
public PowerFormsFormDataResponse getPowerFormData(String accountId, String powerFormId) throws ApiException {
    return getPowerFormData(accountId, powerFormId, null);
  }
698060
public List executeNativeQuery(String n1qlQuery, EntityMetadata em)
    {
        N1qlQueryResult result = bucket
                .query(N1qlQuery.simple(n1qlQuery, N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS)));
        LOGGER.debug("Executed query : " + n1qlQuery + " on the " + bucket.name() + " Bucket");

        validateQueryResults(n1qlQuery, result);
        return result.allRows();

    }
1183551
public static HashMap<String, String> getParameters(String query) {
        HashMap<String, String> params = new HashMap<String, String>();
        if (query == null || query.length() == 0) {
            return params;
        }

        String[] splitQuery = query.split("&");
        for (String splitItem : splitQuery) {
            String[] items = splitItem.split("=");

            if (items.length == 1) {
                params.put(items[0], "");
            } else {
                params.put(items[0], items[1]);
            }
        }

        return params;
    }
443323
@Override
	public QueryRequest<ArrayNode> query(String fql) {
		return this.query(fql, mapper.getTypeFactory().constructType(ArrayNode.class));
	}
171792
public Accounts getChildAccounts(final String accountCode) {
        return doGET(Account.ACCOUNT_RESOURCE + "/" + accountCode + "/child_accounts", Accounts.class, new QueryParams());
    }
970232
public T fql_query(CharSequence query)
    throws FacebookException, IOException {
    assert (null != query);
    return this.callMethod(FacebookMethod.FQL_QUERY,
                           new Pair<String, CharSequence>("query", query));
  }
882880
public QueryRequestBuilder<T,ID> query(QueryExpression query)
    {
        return new QueryRequestBuilder<T, ID>(version,type,entityName,query.build());
    }