Search in sources :

Example 1 with EntityStorageException

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;
}
Also used : Binding(org.openrdf.query.Binding) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) ArrayList(java.util.ArrayList) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Property(org.apache.rya.indexing.entity.model.Property) EntityStorageException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException)

Example 2 with EntityStorageException

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);
    }
}
Also used : SmartUriException(org.apache.rya.indexing.smarturi.SmartUriException) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) Property(org.apache.rya.indexing.entity.model.Property) EntityStorageException(org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException)

Aggregations

Property (org.apache.rya.indexing.entity.model.Property)2 TypedEntity (org.apache.rya.indexing.entity.model.TypedEntity)2 EntityStorageException (org.apache.rya.indexing.entity.storage.EntityStorage.EntityStorageException)2 ArrayList (java.util.ArrayList)1 RyaType (org.apache.rya.api.domain.RyaType)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 SmartUriException (org.apache.rya.indexing.smarturi.SmartUriException)1 Binding (org.openrdf.query.Binding)1 BindingSet (org.openrdf.query.BindingSet)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 MapBindingSet (org.openrdf.query.impl.MapBindingSet)1