use of org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method validateExample.
private <T> void validateExample(Example<T> example) {
Assert.notNull(example, "A non-null example is expected");
ExampleMatcher matcher = example.getMatcher();
if (!matcher.isAllMatching()) {
throw new DatastoreDataException("Unsupported MatchMode. Only MatchMode.ALL is supported");
}
if (matcher.isIgnoreCaseEnabled()) {
throw new DatastoreDataException("Ignore case matching is not supported");
}
if (!(matcher.getDefaultStringMatcher() == ExampleMatcher.StringMatcher.EXACT || matcher.getDefaultStringMatcher() == ExampleMatcher.StringMatcher.DEFAULT)) {
throw new DatastoreDataException("Unsupported StringMatcher. Only EXACT and DEFAULT are supported");
}
Optional<String> path = example.getMatcher().getIgnoredPaths().stream().filter((s) -> s.contains(".")).findFirst();
if (path.isPresent()) {
throw new DatastoreDataException("Ignored paths deeper than 1 are not supported");
}
if (matcher.getPropertySpecifiers().hasValues()) {
throw new DatastoreDataException("Property matchers are not supported");
}
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException in project spring-cloud-gcp by spring-cloud.
the class DatastoreServiceObjectToKeyFactory method getKeyFromId.
@Override
public Key getKeyFromId(Object id, String kindName) {
Assert.notNull(id, "Cannot get key for null ID value.");
if (id instanceof Key) {
return (Key) id;
}
KeyFactory keyFactory = getKeyFactory();
keyFactory.setKind(kindName);
Key key;
if (id instanceof String) {
key = keyFactory.newKey((String) id);
} else if (id instanceof Long) {
key = keyFactory.newKey((long) id);
} else {
// in the future.
throw new DatastoreDataException("Keys can only be created using String or long values.");
}
return key;
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException 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]);
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException in project spring-cloud-gcp by spring-cloud.
the class GqlDatastoreQuery method setOriginalParamTags.
private void setOriginalParamTags() {
this.originalParamTags = new ArrayList<>();
Set<String> seen = new HashSet<>();
Parameters parameters = getQueryMethod().getParameters();
for (int i = 0; i < parameters.getNumberOfParameters(); i++) {
Parameter param = parameters.getParameter(i);
if (Pageable.class.isAssignableFrom(param.getType()) || Sort.class.isAssignableFrom(param.getType())) {
continue;
}
Optional<String> paramName = param.getName();
if (!paramName.isPresent()) {
throw new DatastoreDataException("Query method has a parameter without a valid name: " + getQueryMethod().getName());
}
String name = paramName.get();
if (seen.contains(name)) {
throw new DatastoreDataException("More than one param has the same name: " + name);
}
seen.add(name);
this.originalParamTags.add(name);
}
}
use of org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException in project spring-cloud-gcp by spring-cloud.
the class GqlDatastoreQuery method getNonEntityObjectFromRow.
private static Object getNonEntityObjectFromRow(Object x) {
Object mappedResult;
if (x instanceof Key) {
mappedResult = x;
} else {
BaseEntity entity = (BaseEntity) x;
Set<String> colNames = entity.getNames();
if (colNames.size() > 1) {
throw new DatastoreDataException("The query method returns non-entity types, but the query result has " + "more than one column. Use a Projection entity type instead.");
}
mappedResult = entity.getValue((String) colNames.toArray()[0]).get();
}
return mappedResult;
}
Aggregations