private Document getDocumentById(String collectionId, String id) { if (collection == null) { return null; } // Retrieve the document using the DocumentClient. List<Document> documentList = documentClient .queryDocuments(collection.getSelfLink(), "SELECT * FROM root r WHERE r.id='" + id + "'", feedOptions) .getQueryIterable() .toList(); if (documentList.size() > 0) { return documentList.get(0); } return null; } }
/** * Reads all databases. * * @param options the feed options. * @return the feed response with the read databases. */ public FeedResponse<Database> readDatabases(FeedOptions options) { logger.debug("Reading Databases."); return new FeedResponse<Database>(new QueryIterable<Database>(this, ResourceType.Database, Database.class, Paths.DATABASES_ROOT, options)); }
/** * Gets the response headers. * * @return the response headers. */ public Map<String, String> getResponseHeaders() { return this.inner.getResponseHeaders(); }
/** * Resets the iterable. */ public void reset() { this.queryExecutionContext = this.createQueryExecutionContext(this.client, this.resourceType, this.classT, this.resourceLink, this.querySpec, this.options, this.partitionKey); }
/** * Gets the query iterator of T. * * @return the iterator. */ public Iterator<T> getQueryIterator() { return this.inner.iterator(); }
int pageSize = getHeaderItemCount(header); List<T> pageResults = qi.fetchNextBlock(); if (pageResults == null) { pageResults = new ArrayList<>();
/** * Query for databases. * * @param querySpec the SQL query specification. * @param options the feed options. * @return the feed response with the obtained databases. */ public FeedResponse<Database> queryDatabases(SqlQuerySpec querySpec, FeedOptions options) { if (querySpec == null) { throw new IllegalArgumentException("querySpec"); } logger.debug("Querying Databases. querySpec: [{}]", querySpec); return new FeedResponse<Database>(new QueryIterable<Database>(this, ResourceType.Database, Database.class, Paths.DATABASES_ROOT, querySpec, options)); }
/** * Gets the activity ID for the request. * * @return the activity id. */ public String getActivityId() { return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), HttpConstants.HttpHeaders.ACTIVITY_ID); }
private Database getDatabase() { if (database == null) { // Get the database if it exists List<Database> databaseList = documentClient .queryDatabases( "SELECT * FROM root r WHERE r.id='" + databaseId + "'", null) .getQueryIterable() .toList(); if (databaseList.size() > 0) { // Cache the database object so we won't have to query for it // later to retrieve the selfLink. database = databaseList.get(0); } else { // Create the database if it doesn't exist. try { Database databaseDefinition = new Database(); databaseDefinition.setId(databaseId); database = documentClient.createDatabase(databaseDefinition, null) .getResource(); } catch (DocumentClientException e) { // TODO: Something has gone terribly wrong - the app wasn't // able to query or create the collection. // Verify your connection, endpoint, and key. e.printStackTrace(System.err); } } } return database; }
/** * Reads all users in a database. * * @param databaseLink the database link. * @param options the feed options. * @return the feed response with the read users. */ public FeedResponse<User> readUsers(String databaseLink, FeedOptions options) { if (StringUtils.isEmpty(databaseLink)) { throw new IllegalArgumentException("databaseLink"); } logger.debug("Reading Users. databaseLink [{}]", databaseLink); String path = Utils.joinPath(databaseLink, Paths.USERS_PATH_SEGMENT); return new FeedResponse<User>(new QueryIterable<User>(this, ResourceType.User, User.class, path, options)); }
/** * Gets the number of index paths (terms) generated by the operation. * * @return the request charge. */ public double getRequestCharge() { String value = FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), HttpConstants.HttpHeaders.REQUEST_CHARGE); if (StringUtils.isEmpty(value)) { return 0; } return Double.valueOf(value); }
new SqlParameter("@startkey", startkey))), getFeedOptions(startkey)); documents = feedResponse.getQueryIterable().toList(); } catch (Exception e) { if (!this.includeExceptionStackInLog) {
/** * Reads offers. * * @param options the feed options. * @return the feed response with the read offers. */ public FeedResponse<Offer> readOffers(FeedOptions options) { logger.debug("Reading Offers."); String path = Utils.joinPath(Paths.OFFERS_PATH_SEGMENT, null); return new FeedResponse<Offer>(new QueryIterable<Offer>(this, ResourceType.Offer, Offer.class, path, options)); }
/** * Gets the maximum size limit for this entity (in megabytes (MB) for server resources and in count for master * resources). * * @return the max resource quota. */ public String getMaxResourceQuota() { return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), HttpConstants.HttpHeaders.MAX_RESOURCE_QUOTA); }
null) .getQueryIterable() .toList();
/** * Reads all user defined functions in a document collection. * * @param collectionLink the collection link. * @param options the feed options. * @return the feed response with the read user defined functions. */ public FeedResponse<UserDefinedFunction> readUserDefinedFunctions(String collectionLink, FeedOptions options) { if (StringUtils.isEmpty(collectionLink)) { throw new IllegalArgumentException("collectionLink"); } logger.debug("Reading UserDefinedFunctions. collectionLink [{}]", collectionLink); String path = Utils.joinPath(collectionLink, Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT); return new FeedResponse<UserDefinedFunction>(new QueryIterable<UserDefinedFunction>(this, ResourceType.UserDefinedFunction, UserDefinedFunction.class, path, options)); }
/** * Gets the continuation token to be used for continuing the enumeration. * * @return the response continuation. */ public String getResponseContinuation() { String headerName = useEtagAsContinuation ? HttpConstants.HttpHeaders.E_TAG : HttpConstants.HttpHeaders.CONTINUATION; return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), headerName); }
private long getCountValue(SqlQuerySpec querySpec, boolean isCrossPartitionQuery, String collectionName) { final FeedResponse<Document> feedResponse = executeQuery(querySpec, isCrossPartitionQuery, collectionName); final Object value = feedResponse.getQueryIterable().toList().get(0).getHashMap().get(COUNT_VALUE_KEY); if (value instanceof Integer) { return Long.valueOf((Integer) value); } else if (value instanceof Long) { return (Long) value; } else { throw new IllegalStateException("Unexpected value type " + value.getClass() + " of value: " + value); } }
/** * Reads all attachments in a document. * * @param documentLink the document link. * @param options the feed options. * @return the feed response with the read attachments. */ public FeedResponse<Attachment> readAttachments(String documentLink, FeedOptions options) { if (StringUtils.isEmpty(documentLink)) { throw new IllegalArgumentException("documentLink"); } logger.debug("Reading Attachments. attachmentLink [{}]", documentLink); String path = Utils.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT); return new FeedResponse<Attachment>(new QueryIterable<Attachment>(this, ResourceType.Attachment, Attachment.class, path, options)); }
/** * Gets the current size of this entity (in megabytes (MB) for server resources and in count for master resources). * * @return the current resource quota usage. */ public String getCurrentResourceQuotaUsage() { return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), HttpConstants.HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE); }