@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { String documentLink = getDocumentLink(this.databaseName, table, key); ResourceResponse<Document> readResource = null; Document document; long startTime = System.nanoTime(); try { readResource = AzureCosmosClient.client.readDocument(documentLink, getRequestOptions(key)); document = readResource.getResource(); } catch (DocumentClientException e) { if (!this.includeExceptionStackInLog) { e = null; } LOGGER.error("Failed to read key {} in collection {} in database {}", key, table, this.databaseName, e); return Status.ERROR; } finally { long elapsed = (System.nanoTime() - startTime) / NS_IN_US; LOGGER.debug("Read key {} in {}us - ActivityID: {}", key, elapsed, readResource != null ? readResource.getActivityId() : NA_STRING); } if (null != document) { result.putAll(extractResult(document)); LOGGER.trace("Read result: {}", document); } return Status.OK; }
@Override public ResourceResponse<Document> invoke() throws Exception { return client.readDocument(documentLink, options); } });
.readDocument(getDocumentLink(this.databaseName, collectionName, id), null) .getResource();
public <T> T findById(String collectionName, Object id, Class<T> entityClass) { try { final Resource resource = documentDbFactory.getDocumentClient() .readDocument( getDocumentLink(this.databaseName, collectionName, id.toString()), null) .getResource(); if (resource instanceof Document) { final Document document = (Document) resource; return mappingDocumentDbConverter.read(entityClass, document); } else { return null; } } catch (DocumentClientException e) { if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) { return null; } throw new RuntimeException("findById exception", e); } }
public <T> T findById(String collectionName, Object id, Class<T> domainClass) { Assert.hasText(collectionName, "collectionName should not be null, empty or only whitespaces"); Assert.notNull(domainClass, "entityClass should not be null"); assertValidId(id); try { final RequestOptions options = new RequestOptions(); if (isIdFieldAsPartitionKey(domainClass)) { options.setPartitionKey(new PartitionKey(id)); } final String documentLink = getDocumentLink(this.databaseName, collectionName, id); final Resource document = getDocumentClient().readDocument(documentLink, options).getResource(); if (document instanceof Document) { return mappingDocumentDbConverter.read(domainClass, (Document) document); } else { return null; } } catch (DocumentClientException e) { if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) { return null; } throw new DocumentDBAccessException("findById exception", e); } }
public <T> T findById(String collectionName, Object id, Class<T> entityClass) { try { final Resource resource = documentDbFactory.getDocumentClient() .readDocument(getDocumentLink(this.databaseName, collectionName, id), new RequestOptions()).getResource(); if (resource instanceof Document) { final Document document = (Document) resource; return mappingDocumentDbConverter.read(entityClass, document); } else { return null; } } catch (DocumentClientException e) { if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) { return null; } throw new DocumentDBAccessException("findById exception", e); } }