use of org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException in project incubator-rya by apache.
the class EntityQueryNode method findBindings.
private List<BindingSet> findBindings(final BindingSet bindingSet) throws QueryEvaluationException {
final MapBindingSet resultSet = new MapBindingSet();
try {
final ConvertingCursor<TypedEntity> entitiesCursor;
final String subj;
// If the subject needs to be filled in, check if the subject variable is in the binding set.
if (subjectIsConstant) {
// if it is, fetch that value and then fetch the entity for the subject.
subj = subjectConstant.get();
entitiesCursor = entities.search(Optional.of(new RyaURI(subj)), type, properties);
} else {
entitiesCursor = entities.search(Optional.empty(), type, properties);
}
while (entitiesCursor.hasNext()) {
final TypedEntity typedEntity = entitiesCursor.next();
final ImmutableCollection<Property> properties = typedEntity.getProperties();
// ensure properties match and only add properties that are in the statement patterns to the binding set
for (final RyaURI key : objectVariables.keySet()) {
final Optional<RyaType> prop = typedEntity.getPropertyValue(new RyaURI(key.getData()));
if (prop.isPresent()) {
final RyaType type = prop.get();
final String bindingName = objectVariables.get(key).getName();
resultSet.addBinding(bindingName, ValueFactoryImpl.getInstance().createLiteral(type.getData()));
}
}
}
} catch (final EntityStorageException e) {
throw new QueryEvaluationException("Failed to evaluate the binding set", e);
}
bindingSet.forEach(new Consumer<Binding>() {
@Override
public void accept(final Binding binding) {
resultSet.addBinding(binding);
}
});
final List<BindingSet> list = new ArrayList<>();
list.add(resultSet);
return list;
}
use of org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException in project incubator-rya by apache.
the class MongoDbSmartUri method queryEntity.
@Override
public ConvertingCursor<TypedEntity> queryEntity(final Type type, final Map<URI, Value> map) throws SmartUriException {
checkInit();
// Query it.
try {
final Set<Property> properties = SmartUriAdapter.mapToProperties(map);
final ConvertingCursor<TypedEntity> cursor = entityStorage.search(Optional.empty(), type, properties);
return cursor;
} catch (final EntityStorageException e) {
throw new SmartUriException("Failed to query entity storage", e);
}
}
Aggregations