.queryCollections(getDatabase().getSelfLink(), "SELECT * FROM root r WHERE r.id='" + collectionId + "'",
@Override public FeedResponse<DocumentCollection> invoke() throws Exception { return client.queryCollections(databaseLink, query, options); } });
@Override public FeedResponse<DocumentCollection> invoke() throws Exception { return client.queryCollections(databaseLink, querySpec, 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); }
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 <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 IllegalCollectionException("expect only one collection: " + collectionName + " in database: " + this.databaseName + ", but found " + collections.size()); } final FeedOptions feedOptions = new FeedOptions(); feedOptions.setEnableCrossPartitionQuery(true); final SqlQuerySpec sqlQuerySpec = new SqlQuerySpec("SELECT * FROM root c"); final List<Document> results = documentDbFactory.getDocumentClient() .queryDocuments(collections.get(0).getSelfLink(), sqlQuerySpec, feedOptions) .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; }
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); } }