use of com.google.firestore.v1.StructuredQuery.CompositeFilter in project java-firestore by googleapis.
the class LocalFirestoreHelper method query.
public static RunQueryRequest query(@Nullable String transactionId, String parent, boolean allDescendants, boolean kindless, StructuredQuery... query) {
RunQueryRequest.Builder request = RunQueryRequest.newBuilder();
if (!parent.equals("")) {
parent = '/' + parent;
}
request.setParent(LocalFirestoreHelper.DATABASE_NAME + "/documents" + parent);
StructuredQuery.Builder structuredQuery = request.getStructuredQueryBuilder();
CollectionSelector.Builder builder = CollectionSelector.newBuilder().setAllDescendants(allDescendants);
if (!kindless) {
builder.setCollectionId("coll");
}
structuredQuery.addFrom(builder);
for (StructuredQuery option : query) {
structuredQuery.mergeFrom(option);
}
CompositeFilter compositeFilter = structuredQuery.getWhere().getCompositeFilter();
if (compositeFilter.getFiltersCount() == 1) {
if (compositeFilter.getFilters(0).hasFieldFilter()) {
FieldFilter fieldFilter = compositeFilter.getFilters(0).getFieldFilter();
structuredQuery.getWhereBuilder().setFieldFilter(fieldFilter);
} else {
UnaryFilter unaryFilter = compositeFilter.getFilters(0).getUnaryFilter();
structuredQuery.getWhereBuilder().setUnaryFilter(unaryFilter);
}
}
if (transactionId != null) {
request.setTransaction(ByteString.copyFromUtf8(transactionId));
}
return request.build();
}
Aggregations