Examples of RepositoryConnection


Examples of org.openrdf.repository.RepositoryConnection

  */

  public void testInheritanceProperty()
    throws Exception
  {
    RepositoryConnection conn = repository.getConnection();
    try {
      String chordataQuery = "SELECT DISTINCT * WHERE {<" + RNA_CHORDATA + "> ?P ?Y . } ";

      // first test: evaluate the query anonymously
      TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, chordataQuery);

      TupleResult tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // second test: evaluate the query as an unauthorized user
      Session session = SessionManager.getOrCreate();
      session.setUsername("no_access");
      tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // third test: evaluate the query as an authorized user
      session.setUsername("trezorix");
      tr = query.evaluate();
      try {
        assertTrue(
            "query result should not be empty: current user has viewing permission by inheritance",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // fourth test: evaluate the query after user has logged out
      SessionManager.remove();
      tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }
    }
    finally {
      conn.close();
    }
  }

Examples of org.openrdf.repository.RepositoryConnection

  }

  public void testQuery1()
    throws Exception
  {
    RepositoryConnection con = repository.getConnection();

    try {
      Session session = SessionManager.getOrCreate();
      session.setUsername("trezorix");

      String conceptQuery = "SELECT DISTINCT ?X WHERE {?X a <" + SKOS_NS + "Concept" + "> ; ?P ?Y . } ";
      TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, conceptQuery);

      TupleResult tr = query.evaluate();
      System.out.println(query.toString());

      try {
        List<String> headers = tr.getBindingNames();

        boolean nsrRetrieved = false;
        boolean animaliaRetrieved = false;
        while (tr.hasNext()) {
          BindingSet bs = tr.next();

          for (String header : headers) {
            Value value = bs.getValue(header);

            if (!nsrRetrieved && RNA_NSR.equals(value.stringValue())) {
              nsrRetrieved = true;
            }

            if (!animaliaRetrieved && RNA_ANIMALIA.equals(value.stringValue())) {
              animaliaRetrieved = true;
            }

            assertFalse(RNA_NATURALIS + " should not be retrieved",
                RNA_NATURALIS.equals(value.stringValue()));
          }
        }

        assertTrue(RNA_NSR + " was not retrieved", nsrRetrieved);
        assertTrue(RNA_ANIMALIA + " was not retrieved", animaliaRetrieved);

      }
      finally {
        tr.close();
      }
    }
    finally {
      con.close();
    }
  }

Examples of org.openrdf.repository.RepositoryConnection

  }

  private void addProtectedStatement()
    throws StoreException
  {
    RepositoryConnection con = repository.getConnection();
    try {
      ValueFactory vf = con.getValueFactory();
      con.add(vf.createURI(RNA_RECYCLE), RDFS.LABEL, vf.createLiteral("test"));
    }
    finally {
      con.close();
    }
  }

Examples of org.openrdf.repository.RepositoryConnection

    negativeTests.setName("Negative Syntax Tests");

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();
    RepositoryConnection con = manifestRep.getConnection();

    URL manifestURL = SeRQLParserTestCase.class.getResource(MANIFEST_FILE);
    RDFFormat format = RDFFormat.forFileName(MANIFEST_FILE, RDFFormat.TURTLE);
    con.add(manifestURL, base(manifestURL.toExternalForm()), format);

    String query = "SELECT testName, query, result " + "FROM {} mf:name {testName}; "
        + "        mf:action {query}; " + "        mf:result {result} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  mfx = <http://www.openrdf.org/test-manifest-extensions#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = testBindings.getValue("testName").toString();
      String queryFile = testBindings.getValue("query").toString();
      Value result = testBindings.getValue("result");
      if (MFX_CORRECT.equals(result)) {
        positiveTests.addTest(factory.createTest(testName, queryFile, result));
      }
      else if (MFX_PARSE_ERROR.equals(result)) {
        negativeTests.addTest(factory.createTest(testName, queryFile, result));
      }
      else {
        logger.warn("Unexpected result value for test \"" + testName + "\": " + result);
      }
    }

    tests.close();
    con.close();
    manifestRep.shutDown();

    suite.addTest(positiveTests);
    suite.addTest(negativeTests);
    return suite;

Examples of org.openrdf.repository.RepositoryConnection

    String query = readQuery();

    File dataDir = FileUtil.createTempDir("serql");
    Repository dataRep = createRepository(dataDir, entailment);
    try {
      RepositoryConnection con = dataRep.getConnection();
      try {
        // Add unnamed graph
        con.add(url(dataFile), base(dataFile), RDFFormat.forFileName(dataFile));

        // add named graphs
        for (String graphName : graphNames) {
          con.add(url(graphName), base(graphName), RDFFormat.forFileName(graphName), new URIImpl(
              graphName));
        }

        // Evaluate the query on the query data
        GraphResult result = con.prepareGraphQuery(getQueryLanguage(), query).evaluate();
        try {
          actualStatements = result.asList();
        }
        finally {
          result.close();
        }
      }
      finally {
        con.close();
      }
    }
    finally {
      dataRep.shutDown();
      FileUtil.deleteDir(dataDir);
    }

    // Create a repository with the expected result data
    dataDir = FileUtil.createTempDir("serql");
    Repository expectedResultRep = createRepository(dataDir);
    try {
      RepositoryConnection con = expectedResultRep.getConnection();
      try {
        con.add(url(resultFile), base(resultFile), RDFFormat.forFileName(resultFile));

        expectedStatements = con.match(null, null, null, false).asList();
      }
      finally {
        con.close();
      }
    }
    finally {
      expectedResultRep.shutDown();
      FileUtil.deleteDir(dataDir);

Examples of org.openrdf.repository.RepositoryConnection

  {
    Repository dataRep = new SailRepository(createSail(entailment));
    dataRep.setDataDir(dataDir);
    dataRep.initialize();

    RepositoryConnection con = dataRep.getConnection();
    try {
      con.clear();
      con.clearNamespaces();
    }
    finally {
      con.close();
    }

    return dataRep;
  }

Examples of org.openrdf.repository.RepositoryConnection

    // Read manifest and create declared test cases
    Repository manifestRep = new SailRepository(new MemoryStore());
    manifestRep.initialize();

    RepositoryConnection con = manifestRep.getConnection();

    URL manifestURL = SeRQLQueryTestCase.class.getResource(MANIFEST_FILE);
    RDFFormat format = RDFFormat.forFileName(MANIFEST_FILE, RDFFormat.TURTLE);
    con.add(manifestURL, base(manifestURL.toExternalForm()), format);

    String query = "SELECT testName, entailment, input, query, result " + "FROM {} mf:name {testName};"
        + "        mf:result {result}; " + "        tck:entailment {entailment}; "
        + "        mf:action {} qt:query {query}; " + "                     qt:data {input} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>, "
        + "  tck = <urn:openrdf.org:sesame:tests#> ";

    TupleResult tests = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (tests.hasNext()) {
      BindingSet testBindings = tests.next();
      String testName = ((Literal)testBindings.getValue("testName")).getLabel();
      String inputFile = testBindings.getValue("input").toString();
      String queryFile = testBindings.getValue("query").toString();
      String resultFile = testBindings.getValue("result").toString();
      String entailment = ((Literal)testBindings.getValue("entailment")).getLabel();

      query = "SELECT graph " + "FROM {} mf:name {testName}; "
          + "        mf:action {} qt:graphData {graph} " + "WHERE testName = \""
          + SeRQLUtil.encodeString(testName) + "\" " + "USING NAMESPACE"
          + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>,"
          + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

      List<String> graphNames = new ArrayList<String>();

      TupleResult graphs = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
      while (graphs.hasNext()) {
        BindingSet graphBindings = graphs.next();
        graphNames.add(graphBindings.getValue("graph").toString());
      }
      graphs.close();

      if (testName.startsWith("test-029:")) {
        logger.error("test-029 SKIPPED in {}", SeRQLQueryTestCase.class.getName());
        continue;
      }
      suite.addTest(factory.createTest(testName, inputFile, graphNames, queryFile, resultFile, entailment));
    }

    tests.close();
    con.close();
    manifestRep.shutDown();

    return suite;
  }

Examples of org.openrdf.repository.RepositoryConnection

    Collection<? extends Statement> expectedStatements = null;

    Repository repository = new SailRepository(sailStack);
    repository.initialize();

    RepositoryConnection con = repository.getConnection();

    // clear the input store
    con.clear();

    // Upload input data
    InputStream stream = getClass().getResourceAsStream(inputData);
    try {
      con.add(stream, inputData, RDFFormat.NTRIPLES);
      entailedStatements = con.match(null, null, null, true).asSet();
    }
    finally {
      stream.close();
      con.close();
    }

    // Upload output data
    Repository outputRepository = new SailRepository(new MemoryStore());
    outputRepository.initialize();
    con = outputRepository.getConnection();

    stream = getClass().getResourceAsStream(outputData);
    try {
      con.add(stream, outputData, RDFFormat.NTRIPLES);
      expectedStatements = con.match(null, null, null, false).asSet();
    }
    finally {
      stream.close();
      con.close();
      outputRepository.shutDown();
      repository.shutDown();
    }

    // Check whether all expected statements are present in the entailment

Examples of org.openrdf.repository.RepositoryConnection

    throws Exception
  {
    Repository rep1 = new SailRepository(new MemoryStore());
    rep1.initialize();

    RepositoryConnection con1 = rep1.getConnection();

    URL rdf = this.getClass().getResource("/testcases/rdfa-test.rdf");

    con1.add(rdf, rdf.toExternalForm(), RDFFormat.forFileName(rdf.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.setBaseURI(rdf.toExternalForm());
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();

    Repository rep2 = new SailRepository(new MemoryStore());
    rep2.initialize();

    RepositoryConnection con2 = rep2.getConnection();

    con2.add(new StringReader(writer.toString()), rdf.toExternalForm(), rdfWriterFactory.getRDFFormat());
    long after = con2.size();
    con2.close();

    assertEquals("result of serialization and re-upload should be equal to original", before, after);

    assertTrue("result of serialization and re-upload should be equal to original", RepositoryUtil.equals(
        rep1, rep2));

Examples of org.openrdf.repository.RepositoryConnection

    QueryLanguage queryLn = getQueryLanguage(params, response);
    String baseURI = params.getFirstValue(BASEURI_PARAM_NAME);

    try {
      RepositoryConnection connection = RequestAtt.getConnection(request);
      Query query = connection.prepareQuery(queryLn, queryStr, baseURI);
      parseQueryParameters(query, params, connection.getValueFactory());
      return query;
    }
    catch (StoreException e) {
      throw new ResourceException(SERVER_ERROR_INTERNAL, "Failed to prepare query", e);
    }
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.