try { feedResponse = AzureCosmosClient.client.queryDocuments(getDocumentCollectionLink(this.databaseName, table), new SqlQuerySpec(queryText, new SqlParameterCollection(new SqlParameter("@recordcount", recordcount), new SqlParameter("@startkey", startkey))),
/** * Initializes a new instance of the SqlQuerySpec class with the text of the * query. * * @param queryText * the query text. */ public SqlQuerySpec(String queryText) { super(); this.setQueryText(queryText); }
switch (queryCompatibilityMode) { case SqlQuery: if (querySpec.getParameters() != null && querySpec.getParameters().size() > 0) { throw new IllegalArgumentException( String.format("Unsupported argument in query compatibility mode '{%s}'", queryText = querySpec.getQueryText(); break; default: operation = OperationType.Query; queryText = querySpec.toJson(); break;
/** * Query for aggregation values in a document collection. * * @param collectionLink the link to the parent document collection. * @param query the query string. * @param feedOptions the feed options. * @return a list containing the aggregation values */ public List<Object> queryAggregateValues(String collectionLink, String query, FeedOptions feedOptions) { return this.queryAggregateValues(collectionLink, new SqlQuerySpec(query, null), feedOptions); }
/** * Initializes a new instance of the SqlQuerySpec class with the text of the * query and parameters. * * @param queryText the query text. * @param parameters the query parameters. */ public SqlQuerySpec(String queryText, SqlParameterCollection parameters) { super(); this.setQueryText(queryText); this.parameters = parameters; }
/** * Query for offers in a database. * * @param query the query. * @param options the feed options. * @return the feed response with the obtained offers. */ public FeedResponse<Offer> queryOffers(String query, FeedOptions options) { if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryOffers(new SqlQuerySpec(query, null), options); }
/** * Query for databases. * * @param query the query. * @param options the feed options. * @return the feed response with the obtained databases. */ public FeedResponse<Database> queryDatabases(String query, FeedOptions options) { if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryDatabases(new SqlQuerySpec(query, null), options); }
/** * Query for aggregation values in a document collection. * * @param collectionLink the link to the parent document collection. * @param query the query string. * @param feedOptions the feed options. * @param partitionKey the partitionKey. * @return a list containing the aggregation values */ public List<Object> queryAggregateValues(String collectionLink, String query, FeedOptions feedOptions, String partitionKey) { return this.queryAggregateValues(collectionLink, new SqlQuerySpec(query, null), feedOptions, partitionKey); }
/** * Query for permissions. * * @param userLink the user link. * @param query the query. * @param options the feed options. * @return the feed response with the obtained permissions. */ public FeedResponse<Permission> queryPermissions(String userLink, String query, FeedOptions options) { if (StringUtils.isEmpty(userLink)) { throw new IllegalArgumentException("permissionLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryPermissions(userLink, new SqlQuerySpec(query, null), options); }
/** * Query for attachments. * * @param documentLink the document link. * @param query the query. * @param options the feed options. * @return the feed response with the obtained attachments. */ public FeedResponse<Attachment> queryAttachments(String documentLink, String query, FeedOptions options) { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryAttachments(documentLink, new SqlQuerySpec(query, null), options); }
/** * Query for conflicts. * * @param collectionLink the collection link. * @param query the query. * @param options the feed options. * @return the feed response of the obtained conflicts. */ public FeedResponse<Conflict> queryConflicts(String collectionLink, String query, FeedOptions options) { if (StringUtils.isEmpty(collectionLink)) { throw new IllegalArgumentException("collectionLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryConflicts(collectionLink, new SqlQuerySpec(query, null), options); }
/** * Query for document collections in a database. * * @param databaseLink the database link. * @param query the query. * @param options the feed options. * @return the feed response with the obtained collections. */ public FeedResponse<DocumentCollection> queryCollections(String databaseLink, String query, FeedOptions options) { if (StringUtils.isEmpty(databaseLink)) { throw new IllegalArgumentException("databaseLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryCollections(databaseLink, new SqlQuerySpec(query, null), options); }
/** * Query for users. * * @param databaseLink the database link. * @param query the query. * @param options the feed options. * @return the feed response of the obtained users. */ public FeedResponse<User> queryUsers(String databaseLink, String query, FeedOptions options) { if (StringUtils.isEmpty(databaseLink)) { throw new IllegalArgumentException("databaseLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryUsers(databaseLink, new SqlQuerySpec(query, null), options); }
/** * Query for stored procedures in a document collection. * * @param collectionLink the collection link. * @param query the query. * @param options the feed options. * @return the feed response with the obtained stored procedures. */ public FeedResponse<StoredProcedure> queryStoredProcedures(String collectionLink, String query, FeedOptions options) { if (StringUtils.isEmpty(collectionLink)) { throw new IllegalArgumentException("collectionLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryStoredProcedures(collectionLink, new SqlQuerySpec(query, null), options); }
/** * Query for triggers. * * @param collectionLink the collection link. * @param query the query. * @param options the feed options. * @return the feed response with the obtained triggers. */ public FeedResponse<Trigger> queryTriggers(String collectionLink, String query, FeedOptions options) { if (StringUtils.isEmpty(collectionLink)) { throw new IllegalArgumentException("collectionLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryTriggers(collectionLink, new SqlQuerySpec(query, null), options); }
/** * Query for documents in a document collection with a partitionKey * * @param collectionLink the link to the parent document collection. * @param query the query. * @param options the feed options. * @param partitionKey the partitionKey. * @return the feed response with the obtained documents. */ public FeedResponse<Document> queryDocuments(String collectionLink, String query, FeedOptions options, Object partitionKey) { if (StringUtils.isEmpty(collectionLink)) { throw new IllegalArgumentException("collectionLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryDocuments(collectionLink, new SqlQuerySpec(query, null), options, partitionKey); }
/** * Query for user defined functions. * * @param collectionLink the collection link. * @param query the query. * @param options the feed options. * @return the feed response with the obtained user defined functions. */ public FeedResponse<UserDefinedFunction> queryUserDefinedFunctions(String collectionLink, String query, FeedOptions options) { if (StringUtils.isEmpty(collectionLink)) { throw new IllegalArgumentException("collectionLink"); } if (StringUtils.isEmpty(query)) { throw new IllegalArgumentException("query"); } return queryUserDefinedFunctions(collectionLink, new SqlQuerySpec(query, null), options); }
private <T> SqlQuerySpec createSqlQuerySpec(Query query, Class<T> entityClass) { String queryStr = "SELECT * FROM ROOT r WHERE "; final SqlParameterCollection parameterCollection = new SqlParameterCollection(); for (final Map.Entry<String, Object> entry : query.getCriteria().entrySet()) { if (queryStr.contains("=@")) { queryStr += " AND "; } String fieldName = entry.getKey(); if (isIdField(fieldName, entityClass)) { fieldName = "id"; } queryStr += "r." + fieldName + "=@" + entry.getKey(); parameterCollection.add(new SqlParameter("@" + entry.getKey(), mappingDocumentDbConverter.mapToDocumentDBValue(entry.getValue()))); } return new SqlQuerySpec(queryStr, parameterCollection); }
public <T> List<T> findAll(String collectionName, final Class<T> entityClass) { final List<DocumentCollection> collections = documentDbFactory.getDocumentClient(). queryCollections( getDatabaseLink(this.databaseName), new SqlQuerySpec("SELECT * FROM ROOT r WHERE r.id=@id", new SqlParameterCollection(new SqlParameter("@id", collectionName))), null) .getQueryIterable().toList(); if (collections.size() != 1) { throw new RuntimeException("expect only one collection: " + collectionName + " in database: " + this.databaseName + ", but found " + collections.size()); } final List<Document> results = documentDbFactory.getDocumentClient() .queryDocuments(collections.get(0).getSelfLink(), "SELECT * FROM c", null) .getQueryIterable().toList(); final List<T> entities = new ArrayList<>(); for (int i = 0; i < results.size(); i++) { final T entity = mappingDocumentDbConverter.read(entityClass, results.get(i)); entities.add(entity); } return entities; }
/** * Generate SqlQuerySpec with given DocumentQuery and query head. * * @param query DocumentQuery represent one query method. * @param queryHead * @return The SqlQuerySpec for DocumentClient. */ protected SqlQuerySpec generateQuery(@NonNull DocumentQuery query, @NonNull String queryHead) { Assert.hasText(queryHead, "query head should have text."); final Pair<String, List<Pair<String, Object>>> queryBody = generateQueryBody(query); final String queryString = String.join(" ", queryHead, queryBody.getValue0(), generateQueryTail(query)); final List<Pair<String, Object>> parameters = queryBody.getValue1(); final SqlParameterCollection sqlParameters = new SqlParameterCollection(); sqlParameters.addAll( parameters.stream() .map(p -> new SqlParameter("@" + p.getValue0(), toDocumentDBValue(p.getValue1()))) .collect(Collectors.toList()) ); return new SqlQuerySpec(queryString, sqlParameters); } }