try { feedResponse = AzureCosmosClient.client.queryDocuments(getDocumentCollectionLink(this.databaseName, table), new SqlQuerySpec(queryText, new SqlParameterCollection(new SqlParameter("@recordcount", recordcount), new SqlParameter("@startkey", startkey))),
/** * 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); }
/** * 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 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 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 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; }
private DocumentCollection getDocCollection(String collectionName) { 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 IllegalCollectionException("expect only one collection: " + collectionName + " in database: " + this.databaseName + ", but found " + collections.size()); } return collections.get(0); }
public DocumentCollection createCollectionIfNotExists(String collectionName, String partitionKeyFieldName, Integer requestUnit, IndexingPolicy policy) { if (this.databaseCache == null) { this.databaseCache = createDatabaseIfNotExists(this.databaseName); } final List<DocumentCollection> collectionList = 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 (!collectionList.isEmpty()) { return collectionList.get(0); } else { final RequestOptions requestOptions = getRequestOptions(null, requestUnit); return createCollection(this.databaseName, collectionName, requestOptions, partitionKeyFieldName, policy); } }
private DocumentCollection createCollectionIfNotExists(String dbName, String collectionName) { if (this.databaseCache == null) { this.databaseCache = createDatabaseIfNotExists(dbName); } final List<DocumentCollection> collectionList = documentDbFactory.getDocumentClient() .queryCollections(getDatabaseLink(dbName), new SqlQuerySpec("SELECT * FROM root r WHERE r.id=@id", new SqlParameterCollection(new SqlParameter("@id", collectionName))), null) .getQueryIterable().toList(); if (!collectionList.isEmpty()) { return collectionList.get(0); } else { final RequestOptions requestOptions = new RequestOptions(); requestOptions.setOfferThroughput(1000); return createCollection(dbName, collectionName, requestOptions); } }
@Override public DocumentCollection createCollectionIfNotExists(@NonNull DocumentDbEntityInformation information) { if (this.databaseCache == null) { this.databaseCache = createDatabaseIfNotExists(this.databaseName); } final String collectionName = information.getCollectionName(); final String partitionKeyFieldName = information.getPartitionKeyFieldName(); final List<DocumentCollection> collectionList = 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 (!collectionList.isEmpty()) { return collectionList.get(0); } else { return createCollection(this.databaseName, partitionKeyFieldName, information); } }