use of com.google.cloud.datastore.StructuredQuery.PropertyFilter in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplateTests method combineFiltersDiscrimination.
@Test
public void combineFiltersDiscrimination() {
PropertyFilter propertyFilter = PropertyFilter.eq("field", "some value");
EntityQuery.Builder builder = Query.newEntityQueryBuilder().setKind("test_kind").setFilter(propertyFilter);
DatastoreTemplate.applyQueryOptions(builder, new DatastoreQueryOptions.Builder().setLimit(1).setOffset(2).build(), new DatastoreMappingContext().getPersistentEntity(SimpleDiscriminationTestEntity.class));
assertThat(builder.build().getFilter()).isEqualTo(StructuredQuery.CompositeFilter.and(propertyFilter, PropertyFilter.eq("discrimination_field", "A")));
assertThat(builder.build().getLimit()).isEqualTo(1);
assertThat(builder.build().getOffset()).isEqualTo(2);
}
use of com.google.cloud.datastore.StructuredQuery.PropertyFilter in project spring-cloud-gcp by spring-cloud.
the class PartTreeDatastoreQuery method applySelectWithFilter.
private void applySelectWithFilter(Object[] parameters, Builder builder) {
Iterator it = Arrays.asList(parameters).iterator();
Filter[] filters = this.filterParts.stream().map((part) -> {
// build properties chain for nested properties
// if the property is not nested, the list would contain only one property
List<DatastorePersistentProperty> propertiesChain = getPropertiesChain(part);
String fieldName = propertiesChain.stream().map(DatastorePersistentProperty::getFieldName).collect(Collectors.joining("."));
if (part.getType() == Part.Type.IS_NULL) {
return PropertyFilter.isNull(fieldName);
}
BiFunction<String, Value, PropertyFilter> filterFactory = FILTER_FACTORIES.get(part.getType());
if (filterFactory == null) {
throw new DatastoreDataException("Unsupported predicate keyword: " + part.getType());
}
if (!it.hasNext()) {
throw new DatastoreDataException("Too few parameters are provided for query method: " + getQueryMethod().getName());
}
Value convertedValue = convertParam(propertiesChain.get(propertiesChain.size() - 1), it.next());
return filterFactory.apply(fieldName, convertedValue);
}).toArray(Filter[]::new);
builder.setFilter((filters.length > 1) ? CompositeFilter.and(filters[0], Arrays.copyOfRange(filters, 1, filters.length)) : filters[0]);
}
Aggregations