use of org.openrdf.repository.sail.SailRepository in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testNamedGraphLoadWAuth.
public void testNamedGraphLoadWAuth() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
RdfCloudTripleStore tstore = new MockRdfCloudStore();
NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
tstore.setNamespaceManager(nm);
SailRepository repo = new SailRepository(tstore);
tstore.getRyaDAO().getConf().setCv("1|2");
repo.initialize();
RepositoryConnection conn = repo.getConnection();
conn.add(stream, "", RDFFormat.TRIG);
conn.commit();
String query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + // "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
"WHERE\n" + "{\n" + " GRAPH ex:G1\n" + " {\n" + " ?m voc:name ?name ;\n" + " voc:homepage ?hp .\n" + " } .\n" + " GRAPH ex:G2\n" + " {\n" + " ?m voc:hasSkill ?skill .\n" + " } .\n" + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
// no auth
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
repo.shutDown();
}
use of org.openrdf.repository.sail.SailRepository in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testUpdateWAuthOnConfig.
// Set the persistence visibilites on the config
public void testUpdateWAuthOnConfig() throws Exception {
String sparqlUpdate = getSparqlUpdate();
RdfCloudTripleStore tstore = new MockRdfCloudStore();
NamespaceManager nm = new NamespaceManager(tstore.getRyaDAO(), tstore.getConf());
tstore.setNamespaceManager(nm);
SailRepository repo = new SailRepository(tstore);
tstore.getRyaDAO().getConf().setCv("1|2");
repo.initialize();
RepositoryConnection conn = repo.getConnection();
Update u = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlUpdate);
u.execute();
String query = "PREFIX ex: <http://www.example.org/exampleDocument#>\n" + "PREFIX voc: <http://www.example.org/vocabulary#>\n" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" + "\n" + "SELECT * \n" + // "FROM NAMED <http://www.example.org/exampleDocument#G1>\n" +
"WHERE\n" + "{\n" + " GRAPH ex:G1\n" + " {\n" + " ?m voc:name ?name ;\n" + " voc:homepage ?hp .\n" + " } .\n" + " GRAPH ex:G2\n" + " {\n" + " ?m voc:hasSkill ?skill .\n" + " } .\n" + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
CountTupleHandler tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(1, tupleHandler.getCount());
// no auth
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
tupleHandler = new CountTupleHandler();
tupleQuery.evaluate(tupleHandler);
assertEquals(0, tupleHandler.getCount());
conn.close();
repo.shutDown();
}
use of org.openrdf.repository.sail.SailRepository in project incubator-rya by apache.
the class InferenceIT method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
dao = new AccumuloRyaDAO();
connector = new MockInstance().getConnector("", new PasswordToken(""));
dao.setConnector(connector);
conf = new AccumuloRdfConfiguration();
conf.setInfer(true);
dao.setConf(conf);
dao.init();
store = new RdfCloudTripleStore();
store.setConf(conf);
store.setRyaDAO(dao);
inferenceEngine = new InferenceEngine();
inferenceEngine.setRyaDAO(dao);
store.setInferenceEngine(inferenceEngine);
inferenceEngine.refreshGraph();
store.initialize();
repository = new SailRepository(store);
conn = repository.getConnection();
solutions = new LinkedList<>();
resultHandler = new TupleQueryResultHandler() {
@Override
public void endQueryResult() throws TupleQueryResultHandlerException {
}
@Override
public void handleBoolean(final boolean value) throws QueryResultHandlerException {
}
@Override
public void handleLinks(final List<String> linkUrls) throws QueryResultHandlerException {
}
@Override
public void handleSolution(final BindingSet bindingSet) throws TupleQueryResultHandlerException {
if (bindingSet != null && bindingSet.iterator().hasNext()) {
solutions.add(bindingSet);
}
}
@Override
public void startQueryResult(final List<String> bindingNames) throws TupleQueryResultHandlerException {
solutions.clear();
}
};
}
use of org.openrdf.repository.sail.SailRepository in project incubator-rya by apache.
the class SailExecutionStrategy method initialize.
/**
* Connect to the Rya SAIL. If a DAO wasn't provided, instantiate one from
* the configuration.
* @throws ForwardChainException if connecting fails.
*/
@Override
public void initialize() throws ForwardChainException {
try {
if (dao == null) {
dao = getDAO();
}
repo = new SailRepository(RyaSailFactory.getInstance(conf));
conn = repo.getConnection();
initialized = true;
} catch (Exception e) {
shutDown();
throw new ForwardChainException("Error connecting to SAIL", e);
}
}
use of org.openrdf.repository.sail.SailRepository in project incubator-rya by apache.
the class MongoLoadStatements method loadStatements.
@Override
public void loadStatements(final String ryaInstanceName, final Iterable<? extends Statement> statements) throws InstanceDoesNotExistException, RyaClientException {
requireNonNull(ryaInstanceName);
requireNonNull(statements);
// Ensure the Rya Instance exists.
if (!instanceExists.exists(ryaInstanceName)) {
throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName));
}
Sail sail = null;
SailRepositoryConnection sailRepoConn = null;
try {
// Get a Sail object that is connected to the Rya instance.
final MongoDBRdfConfiguration ryaConf = connectionDetails.build(ryaInstanceName);
sail = RyaSailFactory.getInstance(ryaConf);
final SailRepository sailRepo = new SailRepository(sail);
sailRepoConn = sailRepo.getConnection();
// Load the statements.
sailRepoConn = sailRepo.getConnection();
sailRepoConn.add(statements);
} catch (SailException | RyaDAOException | InferenceEngineException | AccumuloException | AccumuloSecurityException e) {
throw new RyaClientException("Could not load statements into Rya because of a problem while creating the Sail object.", e);
} catch (final RepositoryException e) {
throw new RyaClientException("Could not load the statements into Rya.", e);
} finally {
// Close the resources that were opened.
if (sailRepoConn != null) {
try {
sailRepoConn.close();
} catch (final RepositoryException e) {
log.error("Couldn't close the SailRepositoryConnection object.", e);
}
}
if (sail != null) {
try {
sail.shutDown();
} catch (final SailException e) {
log.error("Couldn't close the Sail object.", e);
}
}
}
}
Aggregations