Search in sources :

Example 66 with RyaDAOException

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

the class InferenceEngine method init.

public void init() throws InferenceEngineException {
    try {
        if (isInitialized()) {
            return;
        }
        checkNotNull(conf, "Configuration is null");
        checkNotNull(ryaDAO, "RdfDao is null");
        checkArgument(ryaDAO.isInitialized(), "RdfDao is not initialized");
        ryaDaoQueryWrapper = new RyaDaoQueryWrapper(ryaDAO, conf);
        refreshGraph();
        if (schedule.get()) {
            timer = new Timer(InferenceEngine.class.getName());
            timer.scheduleAtFixedRate(new TimerTask() {

                @Override
                public void run() {
                    try {
                        refreshGraph();
                    } catch (final InferenceEngineException e) {
                        throw new RuntimeException(e);
                    }
                }
            }, refreshGraphSchedule.get(), refreshGraphSchedule.get());
        }
        setInitialized(true);
    } catch (final RyaDAOException e) {
        throw new InferenceEngineException(e);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) RyaDaoQueryWrapper(org.apache.rya.api.persist.utils.RyaDaoQueryWrapper)

Example 67 with RyaDAOException

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

the class RdfCloudTripleStoreConnection method removeStatementsInternal.

@Override
protected void removeStatementsInternal(final Resource subject, final URI predicate, final Value object, final Resource... contexts) throws SailException {
    if (!(subject instanceof URI)) {
        throw new SailException("Subject[" + subject + "] must be URI");
    }
    try {
        if (contexts != null && contexts.length > 0) {
            for (final Resource context : contexts) {
                if (!(context instanceof URI)) {
                    throw new SailException("Context[" + context + "] must be URI");
                }
                final RyaStatement statement = new RyaStatement(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertURI(predicate), RdfToRyaConversions.convertValue(object), RdfToRyaConversions.convertResource(context));
                ryaDAO.delete(statement, conf);
            }
        } else {
            final RyaStatement statement = new RyaStatement(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertURI(predicate), RdfToRyaConversions.convertValue(object), null);
            ryaDAO.delete(statement, conf);
        }
    } catch (final RyaDAOException e) {
        throw new SailException(e);
    }
}
Also used : Resource(org.openrdf.model.Resource) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) SailException(org.openrdf.sail.SailException) URI(org.openrdf.model.URI) RyaURI(org.apache.rya.api.domain.RyaURI)

Example 68 with RyaDAOException

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

the class RdfCloudTripleStoreConnection method clearInternal.

@Override
protected void clearInternal(final Resource... aresource) throws SailException {
    try {
        final RyaURI[] graphs = new RyaURI[aresource.length];
        for (int i = 0; i < graphs.length; i++) {
            graphs[i] = RdfToRyaConversions.convertResource(aresource[i]);
        }
        ryaDAO.dropGraph(conf, graphs);
    } catch (final RyaDAOException e) {
        throw new SailException(e);
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) SailException(org.openrdf.sail.SailException)

Example 69 with RyaDAOException

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

the class RdfCloudTripleStoreConnection method addStatementInternal.

@Override
protected void addStatementInternal(final Resource subject, final URI predicate, final Value object, final Resource... contexts) throws SailException {
    try {
        final String cv_s = conf.getCv();
        final byte[] cv = cv_s == null ? null : cv_s.getBytes(StandardCharsets.UTF_8);
        final List<RyaStatement> ryaStatements = new ArrayList<>();
        if (contexts != null && contexts.length > 0) {
            for (final Resource context : contexts) {
                final RyaStatement statement = new RyaStatement(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertURI(predicate), RdfToRyaConversions.convertValue(object), RdfToRyaConversions.convertResource(context), null, new StatementMetadata(), cv);
                ryaStatements.add(statement);
            }
        } else {
            final RyaStatement statement = new RyaStatement(RdfToRyaConversions.convertResource(subject), RdfToRyaConversions.convertURI(predicate), RdfToRyaConversions.convertValue(object), null, null, new StatementMetadata(), cv);
            ryaStatements.add(statement);
        }
        ryaDAO.add(ryaStatements.iterator());
    } catch (final RyaDAOException e) {
        throw new SailException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(org.openrdf.model.Resource) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) SailException(org.openrdf.sail.SailException)

Example 70 with RyaDAOException

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

the class MergeJoinTest method testSimpleMergeJoinPredicateOnly2.

@Test
public void testSimpleMergeJoinPredicateOnly2() throws Exception {
    // add data
    RyaURI pred1 = new RyaURI(litdupsNS, "pred1");
    RyaURI pred2 = new RyaURI(litdupsNS, "pred2");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred1, one));
    dao.add(new RyaStatement(subj1, pred1, two));
    dao.add(new RyaStatement(subj1, pred1, three));
    dao.add(new RyaStatement(subj1, pred2, one));
    dao.add(new RyaStatement(subj1, pred2, two));
    dao.add(new RyaStatement(subj1, pred2, three));
    dao.add(new RyaStatement(subj2, pred1, one));
    dao.add(new RyaStatement(subj2, pred1, two));
    dao.add(new RyaStatement(subj2, pred1, three));
    dao.add(new RyaStatement(subj2, pred2, one));
    dao.add(new RyaStatement(subj2, pred2, two));
    dao.add(new RyaStatement(subj2, pred2, three));
    dao.add(new RyaStatement(subj3, pred1, one));
    dao.add(new RyaStatement(subj3, pred1, two));
    dao.add(new RyaStatement(subj3, pred1, three));
    dao.add(new RyaStatement(subj3, pred2, one));
    dao.add(new RyaStatement(subj3, pred2, two));
    dao.add(new RyaStatement(subj3, pred2, three));
    dao.add(new RyaStatement(subj4, pred1, one));
    dao.add(new RyaStatement(subj4, pred1, two));
    dao.add(new RyaStatement(subj4, pred1, three));
    dao.add(new RyaStatement(subj4, pred2, one));
    dao.add(new RyaStatement(subj4, pred2, two));
    dao.add(new RyaStatement(subj4, pred2, three));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaStatement, RyaDAOException> join = mergeJoin.join(null, pred1, pred2);
    int count = 0;
    while (join.hasNext()) {
        RyaStatement next = join.next();
        count++;
    }
    assertEquals(12, count);
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

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