Search in sources :

Example 26 with SailRepository

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();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) NamespaceManager(org.apache.rya.rdftriplestore.namespace.NamespaceManager) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) SailRepository(org.openrdf.repository.sail.SailRepository) InputStream(java.io.InputStream) TupleQuery(org.openrdf.query.TupleQuery)

Example 27 with SailRepository

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();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) NamespaceManager(org.apache.rya.rdftriplestore.namespace.NamespaceManager) RyaSailRepository(org.apache.rya.rdftriplestore.RyaSailRepository) SailRepository(org.openrdf.repository.sail.SailRepository) TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 28 with SailRepository

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();
        }
    };
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) RdfCloudTripleStore(org.apache.rya.rdftriplestore.RdfCloudTripleStore) BindingSet(org.openrdf.query.BindingSet) ListBindingSet(org.openrdf.query.impl.ListBindingSet) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException) SailRepository(org.openrdf.repository.sail.SailRepository) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) MockInstance(org.apache.accumulo.core.client.mock.MockInstance) TupleQueryResultHandler(org.openrdf.query.TupleQueryResultHandler) QueryResultHandlerException(org.openrdf.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.openrdf.query.TupleQueryResultHandlerException)

Example 29 with SailRepository

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);
    }
}
Also used : SailRepository(org.openrdf.repository.sail.SailRepository) ForwardChainException(org.apache.rya.forwardchain.ForwardChainException) RepositoryException(org.openrdf.repository.RepositoryException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) RDFHandlerException(org.openrdf.rio.RDFHandlerException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ForwardChainException(org.apache.rya.forwardchain.ForwardChainException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException)

Example 30 with SailRepository

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);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaClientException(org.apache.rya.api.client.RyaClientException) SailRepository(org.openrdf.repository.sail.SailRepository) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) RepositoryException(org.openrdf.repository.RepositoryException) InstanceDoesNotExistException(org.apache.rya.api.client.InstanceDoesNotExistException) SailException(org.openrdf.sail.SailException) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) Sail(org.openrdf.sail.Sail) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MongoDBRdfConfiguration(org.apache.rya.mongodb.MongoDBRdfConfiguration)

Aggregations

SailRepository (org.openrdf.repository.sail.SailRepository)64 Sail (org.openrdf.sail.Sail)45 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)41 Test (org.junit.Test)27 BindingSet (org.openrdf.query.BindingSet)14 RepositoryException (org.openrdf.repository.RepositoryException)14 TupleQueryResult (org.openrdf.query.TupleQueryResult)13 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)11 TupleQuery (org.openrdf.query.TupleQuery)10 Configuration (org.apache.hadoop.conf.Configuration)9 SailException (org.openrdf.sail.SailException)9 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 RyaClientException (org.apache.rya.api.client.RyaClientException)7 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)7 Repository (org.openrdf.repository.Repository)7 IOException (java.io.IOException)6 RyaURI (org.apache.rya.api.domain.RyaURI)6