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);
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations