public void deleteAll(String collectionName) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("execute deleteCollection in database {} collection {} with id {}", this.databaseName, collectionName); } try { documentDbFactory.getDocumentClient() .deleteCollection(getCollectionLink(this.databaseName, collectionName), null); if (this.collectionCache.contains(collectionName)) { this.collectionCache.remove(collectionName); } } catch (DocumentClientException ex) { if (ex.getStatusCode() == 404) { LOGGER.warn("deleteAll in database {} collection {} met NOTFOUND error {}", this.databaseName, collectionName, ex.getMessage()); } else { throw new RuntimeException("deleteAll exception", ex); } } }
private static Observable<Long> handleRetryAttempt(Throwable t, int attemptNumber, RxRetryHandler retryPolicy) { Throwable cause = extractDocumentClientCause(t, attemptNumber); if (LOGGER.isDebugEnabled()) { if (cause instanceof DocumentClientException) { DocumentClientException ex = (DocumentClientException) cause; LOGGER.debug("Handling Failure Attempt [{}], StatusCode [{}], SubStatusCode," + " Error: [{}] ", attemptNumber, ex.getStatusCode(), ex.getSubStatusCode(), ex.getError(), ex); } else { LOGGER.debug("Handling Failure Attempt [{}], req [{}]", attemptNumber, cause); } } try { return retryPolicy.handleRetryAttempt(cause, attemptNumber); } catch (Exception e) { return Observable.error(e); } } }
public void deleteAll(String collectionName) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("execute deleteCollection in database {} collection {}", this.databaseName, collectionName); } try { documentDbFactory.getDocumentClient() .deleteCollection(getCollectionLink(this.databaseName, collectionName), null); if (this.collectionCache.contains(collectionName)) { this.collectionCache.remove(collectionName); } } catch (DocumentClientException ex) { if (ex.getStatusCode() == 404) { LOGGER.warn("deleteAll in database {} collection {} met NOTFOUND error {}", this.databaseName, collectionName, ex.getMessage()); } else { throw new DocumentDBAccessException("deleteAll exception", ex); } } }
private Observable<Long> handleRetryAttemptInternal(DocumentClientException e, int attemptNumber) throws DocumentClientException { RetryPolicy retryPolicy = null; if (e.getStatusCode() == HttpConstants.StatusCodes.BADREQUEST && e.getSubStatusCode() != null && e.getSubStatusCode() == HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH) { // If HttpStatusCode is 404 (NotFound) and SubStatusCode is // 1001 (PartitionKeyMismatch), invoke the partition key mismatch retry policy retryPolicy = keyMismatchRetryPolicy; } if (retryPolicy == null || !retryPolicy.shouldRetry(e)) { LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Won't retry!", e.getMessage(), e.getStatusCode(), e.getSubStatusCode()); return Observable.error(e); } LOGGER.trace("Execution encontured exception: {}, status code {} sub status code {}. Will retry in {}ms", e.getMessage(), e.getStatusCode(), e.getSubStatusCode(), retryPolicy.getRetryAfterInMilliseconds()); long waitTime = retryPolicy.getRetryAfterInMilliseconds(); return Observable.just(waitTime); } }
if (e.getStatusCode() == HttpConstants.StatusCodes.FORBIDDEN && e.getSubStatusCode() != null && e.getSubStatusCode() == HttpConstants.SubStatusCodes.FORBIDDEN_WRITEFORBIDDEN) { } else if (e.getStatusCode() == HttpConstants.StatusCodes.TOO_MANY_REQUESTS) { } else if (e.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND && e.getSubStatusCode() != null && e.getSubStatusCode() == HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE) { e.getMessage(), e.getStatusCode(), e.getSubStatusCode()); return Observable.error(e); e.getMessage(), e.getStatusCode(), e.getSubStatusCode(), retryPolicy.getRetryAfterInMilliseconds());
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); } }