use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.
the class RdfController method performUpdate.
private void performUpdate(final String query, final SailRepositoryConnection conn, final ServletOutputStream os, final String infer, final String vis) throws RepositoryException, MalformedQueryException, IOException {
final Update update = conn.prepareUpdate(QueryLanguage.SPARQL, query);
if (infer != null && infer.length() > 0) {
update.setBinding(RdfCloudTripleStoreConfiguration.CONF_INFER, VALUE_FACTORY.createLiteral(Boolean.parseBoolean(infer)));
}
if (conn.getSailConnection() instanceof RdfCloudTripleStoreConnection && vis != null) {
final RdfCloudTripleStoreConnection<?> sailConnection = (RdfCloudTripleStoreConnection<?>) conn.getSailConnection();
sailConnection.getConf().set(RdfCloudTripleStoreConfiguration.CONF_CV, vis);
}
final long startTime = System.currentTimeMillis();
try {
update.execute();
} catch (final UpdateExecutionException e) {
final String message = "Update could not be successfully completed for query: ";
os.print(String.format(message + "%s\n\n", StringEscapeUtils.escapeHtml4(query)));
log.error(message + LogUtils.clean(query), e);
}
log.info(String.format("Update Time = %.3f\n", (System.currentTimeMillis() - startTime) / 1000.));
}
use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.
the class EntityTupleSet method evaluate.
@Override
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bindings) throws QueryEvaluationException {
// into the remainder of the star query to be evaluated
if (minCard < 1000 && starQuery.size() > 2 && numberOfSpVars(minSp) == 1 && !starQuery.commonVarConstant()) {
try {
RdfCloudTripleStoreConnection conn = getRyaSailConnection();
CloseableIteration<BindingSet, QueryEvaluationException> sol = (CloseableIteration<BindingSet, QueryEvaluationException>) conn.evaluate(minSp, null, bindings, false);
Set<BindingSet> bSet = Sets.newHashSet();
while (sol.hasNext()) {
// TODO this is not optimal - should check if bindings variables intersect minSp variables
// creating the following QueryBindingSet is only necessary if no intersection occurs
QueryBindingSet bs = new QueryBindingSet();
bs.addAll(sol.next());
bs.addAll(bindings);
bSet.add(bs);
}
List<StatementPattern> spList = starQuery.getNodes();
spList.remove(minSp);
StarQuery sq = new StarQuery(spList);
conn.close();
return new EntityTupleSet(sq, conf, true).evaluate(bSet);
} catch (Exception e) {
throw new QueryEvaluationException(e);
}
} else {
this.evalOptUsed = true;
return this.evaluate(Collections.singleton(bindings));
}
}
use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.
the class EntityTupleSet method getRyaSailConnection.
private RdfCloudTripleStoreConnection getRyaSailConnection() throws AccumuloException, AccumuloSecurityException, SailException {
RdfCloudTripleStore store = new RdfCloudTripleStore();
AccumuloRyaDAO crdfdao = new AccumuloRyaDAO();
crdfdao.setConnector(accCon);
AccumuloRdfConfiguration acc = new AccumuloRdfConfiguration(conf);
crdfdao.setConf(acc);
store.setRyaDAO(crdfdao);
store.initialize();
return (RdfCloudTripleStoreConnection) store.getConnection();
}
use of org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection in project incubator-rya by apache.
the class RdfController method loadRdf.
@RequestMapping(value = "/loadrdf", method = RequestMethod.POST)
public void loadRdf(@RequestParam(required = false) final String format, @RequestParam(value = RdfCloudTripleStoreConfiguration.CONF_CV, required = false) final String cv, @RequestParam(required = false) final String graph, @RequestBody final String body, final HttpServletResponse response) throws RepositoryException, IOException, RDFParseException {
RDFFormat format_r = RDFFormat.RDFXML;
if (format != null) {
format_r = RDFFormat.valueOf(format);
if (format_r == null) {
throw new RuntimeException("RDFFormat[" + format + "] not found");
}
}
// add named graph as context (if specified).
final List<Resource> contextList = new ArrayList<Resource>();
if (graph != null) {
contextList.add(VALUE_FACTORY.createURI(graph));
}
SailRepositoryConnection conn = null;
try {
conn = repository.getConnection();
if (conn.getSailConnection() instanceof RdfCloudTripleStoreConnection && cv != null) {
final RdfCloudTripleStoreConnection<?> sailConnection = (RdfCloudTripleStoreConnection<?>) conn.getSailConnection();
sailConnection.getConf().set(RdfCloudTripleStoreConfiguration.CONF_CV, cv);
}
conn.add(new StringReader(body), "", format_r, contextList.toArray(new Resource[contextList.size()]));
conn.commit();
} finally {
if (conn != null) {
conn.close();
}
}
}
Aggregations