private RequestOptions getRequestOptions(String key) { RequestOptions requestOptions = new RequestOptions(); requestOptions.setPartitionKey(new PartitionKey(key)); return requestOptions; }
headers.put(HttpConstants.HttpHeaders.PARTITION_KEY, options.getPartitionKey().toString());
/** * Sets the resource partition key associated with this permission object. * * @param partitionkey the partition key. */ public void setResourcePartitionKey(PartitionKey partitionkey) { super.set(Constants.Properties.RESOURCE_PARTITION_KEY, partitionkey.getKey()); } }
void addPartitionKeyInformation(AbstractDocumentServiceRequest request, Document document, RequestOptions options) { PartitionKeyInternal partitionKeyInternal; if (options != null && options.getPartitionKey() != null) { partitionKeyInternal = options.getPartitionKey().getInternalPartitionKey(); } else { // Resolve collection only when it's needed DocumentCollection collection = this.collectionCache.resolveCollection(request); PartitionKeyDefinition partitionKeyDefinition = collection.getPartitionKey(); if (partitionKeyDefinition == null || partitionKeyDefinition.getPaths().size() == 0) { // For backward compatibility, if collection doesn't have partition key defined, we assume all documents // have empty value for it and user doesn't need to specify it explicitly. partitionKeyInternal = PartitionKeyInternal.getEmpty(); } else if (document != null) { partitionKeyInternal = extractPartitionKeyValueFromDocument(document, partitionKeyDefinition); } else { throw new UnsupportedOperationException("PartitionKey value must be supplied for this operation."); } } request.getHeaders().put(HttpConstants.HttpHeaders.PARTITION_KEY, escapeNonAscii(partitionKeyInternal.toJson())); }
if (options != null) { if (options.getPartitionKey() != null) { requestHeaders.put(HttpConstants.HttpHeaders.PARTITION_KEY, options.getPartitionKey().toString());
private FeedOptions getFeedOptions(String key) { if (useSinglePartitionCollection) { return null; } FeedOptions feedOptions = new FeedOptions(); if (this.useHashQueryForScan) { feedOptions.setEnableCrossPartitionQuery(false); feedOptions.setPartitionKey(new PartitionKey(key)); } else { feedOptions.setEnableCrossPartitionQuery(true); feedOptions.setMaxDegreeOfParallelism(this.maxDegreeOfParallelismForQuery); } return feedOptions; }
private PartitionKey createKey(String partitionKeyValue) { if (StringUtils.isEmpty(partitionKeyValue)) { return null; } return new PartitionKey(partitionKeyValue); }
private PartitionKey createKey(String partitionKeyValue) { if (StringUtils.isEmpty(partitionKeyValue)) { return null; } return new PartitionKey(partitionKeyValue); }
/** * Create a new instance of the PartitionKey object from a serialized JSON string. * * @param jsonString the JSON string representation of this PartitionKey object. * @return the PartitionKey instance. */ public static PartitionKey FromJsonString(String jsonString) { JSONArray array = new JSONArray(jsonString); PartitionKey key = new PartitionKey(array.get(0)); return key; }
/** * Gets the resource partition key associated with this permission object. * * @return the partition key. */ public PartitionKey getResourcePartitionKey() { PartitionKey key = null; Object value = super.get(Constants.Properties.RESOURCE_PARTITION_KEY); if (value != null) { JSONArray arrayValue = (JSONArray) value; key = new PartitionKey(arrayValue.get(0)); } return key; }
public PartitionKey getPartitionKey() { List<Object> objList = new ArrayList<Object>(super.getCollection(Constants.Properties.PARTITION_KEY, Object.class)); return new PartitionKey(objList.get(0)); }
/** * delete one document per entity * * @param entity */ @Override public void delete(T entity) { Assert.notNull(entity, "entity to be deleted should not be null"); final String partitionKeyValue = information.getPartitionKeyFieldValue(entity); operation.deleteById(information.getCollectionName(), information.getId(entity), partitionKeyValue == null ? null : new PartitionKey(partitionKeyValue)); }
private void deleteDocument(@NonNull Document document, @NonNull List<String> partitionKeyNames) { try { final RequestOptions options = new RequestOptions(); Assert.isTrue(partitionKeyNames.size() <= 1, "Only one Partition is supported."); if (!partitionKeyNames.isEmpty() && StringUtils.hasText(partitionKeyNames.get(0))) { options.setPartitionKey(new PartitionKey(document.get(partitionKeyNames.get(0)))); } getDocumentClient().deleteDocument(document.getSelfLink(), options); } catch (DocumentClientException e) { throw new DocumentDBAccessException("Failed to delete document: " + document.getSelfLink(), e); } }
/** * delete one document per entity * * @param entity */ @Override public void delete(T entity) { final String paritionKeyValue = entityInformation.getPartitionKeyFieldValue(entity); documentDbOperations.deleteById(entityInformation.getCollectionName(), entityInformation.getId(entity), entityInformation.getJavaType(), paritionKeyValue == null ? null : new PartitionKey(paritionKeyValue)); }
@Override public <T> List<T> delete(Query query, Class<T> entityClass, String collectionName) { final SqlQuerySpec sqlQuerySpec = createSqlQuerySpec(query, entityClass); final Optional<Object> partitionKeyValue = getPartitionKeyValue(query, entityClass); final DocumentCollection collection = getDocCollection(collectionName); final FeedOptions feedOptions = new FeedOptions(); if (!partitionKeyValue.isPresent()) { feedOptions.setEnableCrossPartitionQuery(true); } final List<Document> results = documentDbFactory.getDocumentClient() .queryDocuments(collection.getSelfLink(), sqlQuerySpec, feedOptions).getQueryIterable().toList(); final RequestOptions options = new RequestOptions(); if (partitionKeyValue.isPresent()) { options.setPartitionKey(new PartitionKey(partitionKeyValue.get())); } final List<T> deletedResult = new ArrayList<>(); for (final Document document : results) { try { documentDbFactory.getDocumentClient().deleteDocument((document).getSelfLink(), options); deletedResult.add(getConverter().read(entityClass, document)); } catch (DocumentClientException e) { throw new DocumentDBAccessException( String.format("Failed to delete document [%s]", (document).getSelfLink()), e); } } return deletedResult; }
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); } }