Search in sources :

Example 61 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class RyaDAOHelper method query.

public static CloseableIteration<? extends Map.Entry<Statement, BindingSet>, QueryEvaluationException> query(RyaDAO ryaDAO, Collection<Map.Entry<Statement, BindingSet>> statements, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException {
    Collection<Map.Entry<RyaStatement, BindingSet>> ryaStatements = new ArrayList<Map.Entry<RyaStatement, BindingSet>>(statements.size());
    for (Map.Entry<Statement, BindingSet> entry : statements) {
        ryaStatements.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>(RdfToRyaConversions.convertStatement(entry.getKey()), entry.getValue()));
    }
    final CloseableIteration<? extends Map.Entry<RyaStatement, BindingSet>, RyaDAOException> query;
    try {
        query = ryaDAO.getQueryEngine().queryWithBindingSet(ryaStatements, conf);
    } catch (RyaDAOException e) {
        throw new QueryEvaluationException(e);
    }
    return new // TODO: Create a new class struct for this
    CloseableIteration<Map.Entry<Statement, BindingSet>, QueryEvaluationException>() {

        private boolean isClosed = false;

        @Override
        public void close() throws QueryEvaluationException {
            isClosed = true;
            try {
                query.close();
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public boolean hasNext() throws QueryEvaluationException {
            try {
                return query.hasNext();
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public Map.Entry<Statement, BindingSet> next() throws QueryEvaluationException {
            if (!hasNext() || isClosed) {
                throw new NoSuchElementException();
            }
            try {
                Map.Entry<RyaStatement, BindingSet> next = query.next();
                if (next == null) {
                    return null;
                }
                return new RdfCloudTripleStoreUtils.CustomEntry<Statement, BindingSet>(RyaToRdfConversions.convertStatement(next.getKey()), next.getValue());
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public void remove() throws QueryEvaluationException {
            try {
                query.remove();
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }
    };
}
Also used : BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) RdfCloudTripleStoreUtils(org.apache.rya.api.RdfCloudTripleStoreUtils) CloseableIteration(info.aduna.iteration.CloseableIteration) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException)

Example 62 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class RyaDAOHelper method query.

public static CloseableIteration<Statement, QueryEvaluationException> query(RyaDAO ryaDAO, Statement stmt, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException {
    final CloseableIteration<RyaStatement, RyaDAOException> query;
    try {
        query = ryaDAO.getQueryEngine().query(RdfToRyaConversions.convertStatement(stmt), conf);
    } catch (RyaDAOException e) {
        throw new QueryEvaluationException(e);
    }
    // TODO: only support one context for now
    return new // TODO: Create a new class struct for this
    CloseableIteration<Statement, QueryEvaluationException>() {

        private boolean isClosed = false;

        @Override
        public void close() throws QueryEvaluationException {
            try {
                isClosed = true;
                query.close();
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public boolean hasNext() throws QueryEvaluationException {
            try {
                return query.hasNext();
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public Statement next() throws QueryEvaluationException {
            if (!hasNext() || isClosed) {
                throw new NoSuchElementException();
            }
            try {
                RyaStatement next = query.next();
                if (next == null) {
                    return null;
                }
                return RyaToRdfConversions.convertStatement(next);
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }

        @Override
        public void remove() throws QueryEvaluationException {
            try {
                query.remove();
            } catch (RyaDAOException e) {
                throw new QueryEvaluationException(e);
            }
        }
    };
}
Also used : CloseableIteration(info.aduna.iteration.CloseableIteration) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) NoSuchElementException(java.util.NoSuchElementException)

Example 63 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class HashJoin method join.

@Override
public CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) throws RyaDAOException {
    ConcurrentHashMap<RyaURI, Integer> ht = new ConcurrentHashMap<RyaURI, Integer>();
    int count = 0;
    boolean first = true;
    for (Map.Entry<RyaURI, RyaType> predObj : predObjs) {
        count++;
        RyaURI pred = predObj.getKey();
        RyaType obj = predObj.getValue();
        // query
        CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, obj), null);
        // add to hashtable
        while (results.hasNext()) {
            RyaURI subject = results.next().getSubject();
            if (!first) {
                if (!ht.containsKey(subject)) {
                    // not in join
                    continue;
                }
            }
            ht.put(subject, count);
        }
        // remove from hashtable values that are under count
        if (first) {
            first = false;
        } else {
            for (Map.Entry<RyaURI, Integer> entry : ht.entrySet()) {
                if (entry.getValue() < count) {
                    ht.remove(entry.getKey());
                }
            }
        }
    }
    return new EnumerationWrapper<RyaURI, RyaDAOException>(ht.keys());
}
Also used : EnumerationWrapper(org.apache.rya.api.utils.EnumerationWrapper) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) RyaURI(org.apache.rya.api.domain.RyaURI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 64 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class HashJoin method join.

@Override
public CloseableIteration<RyaStatement, RyaDAOException> join(C conf, RyaURI... preds) throws RyaDAOException {
    ConcurrentHashMap<Map.Entry<RyaURI, RyaType>, Integer> ht = new ConcurrentHashMap<Map.Entry<RyaURI, RyaType>, Integer>();
    int count = 0;
    boolean first = true;
    for (RyaURI pred : preds) {
        count++;
        // query
        CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, null), null);
        // add to hashtable
        while (results.hasNext()) {
            RyaStatement next = results.next();
            RyaURI subject = next.getSubject();
            RyaType object = next.getObject();
            Map.Entry<RyaURI, RyaType> entry = new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(subject, object);
            if (!first) {
                if (!ht.containsKey(entry)) {
                    // not in join
                    continue;
                }
            }
            ht.put(entry, count);
        }
        // remove from hashtable values that are under count
        if (first) {
            first = false;
        } else {
            for (Map.Entry<Map.Entry<RyaURI, RyaType>, Integer> entry : ht.entrySet()) {
                if (entry.getValue() < count) {
                    ht.remove(entry.getKey());
                }
            }
        }
    }
    final Enumeration<Map.Entry<RyaURI, RyaType>> keys = ht.keys();
    return new CloseableIteration<RyaStatement, RyaDAOException>() {

        @Override
        public void close() throws RyaDAOException {
        }

        @Override
        public boolean hasNext() throws RyaDAOException {
            return keys.hasMoreElements();
        }

        @Override
        public RyaStatement next() throws RyaDAOException {
            Map.Entry<RyaURI, RyaType> subjObj = keys.nextElement();
            return new RyaStatement(subjObj.getKey(), null, subjObj.getValue());
        }

        @Override
        public void remove() throws RyaDAOException {
            keys.nextElement();
        }
    };
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) CloseableIteration(info.aduna.iteration.CloseableIteration) RyaURI(org.apache.rya.api.domain.RyaURI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 65 with RyaDAOException

use of org.apache.rya.api.persist.RyaDAOException in project incubator-rya by apache.

the class AccumuloRyaStatementStore method addStatement.

@Override
public void addStatement(final RyaStatement statement) throws AddStatementException {
    try {
        accumuloRyaDao.add(statement);
        accumuloRyaDao.flush();
        // RYA-197 is the ticket for fixing this hack.
        if (!containsStatement(statement)) {
            statement.setTimestamp(statement.getTimestamp() + 1L);
            accumuloRyaDao.add(statement);
        }
    } catch (final RyaDAOException | ContainsStatementException e) {
        throw new AddStatementException("Unable to add the Rya Statement", e);
    }
}
Also used : AddStatementException(org.apache.rya.export.api.store.AddStatementException) ContainsStatementException(org.apache.rya.export.api.store.ContainsStatementException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException)

Aggregations

RyaDAOException (org.apache.rya.api.persist.RyaDAOException)100 RyaStatement (org.apache.rya.api.domain.RyaStatement)61 RyaURI (org.apache.rya.api.domain.RyaURI)45 Test (org.junit.Test)39 RyaType (org.apache.rya.api.domain.RyaType)28 IOException (java.io.IOException)26 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)23 AccumuloException (org.apache.accumulo.core.client.AccumuloException)22 SailException (org.openrdf.sail.SailException)15 HashSet (java.util.HashSet)12 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)12 RdfCloudTripleStoreUtils (org.apache.rya.api.RdfCloudTripleStoreUtils)12 Map (java.util.Map)11 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 RyaClientException (org.apache.rya.api.client.RyaClientException)11 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)10 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)8 Text (org.apache.hadoop.io.Text)8