Package org.openrdf.query

Examples of org.openrdf.query.TupleQueryResult


  }

  public void testValueExceptionEqual() throws Exception {
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryStr2);
    TupleQueryResult evaluate = query.evaluate();
    try {
      assertFalse(evaluate.hasNext());
    } finally {
      evaluate.close();
    }
  }
View Full Code Here


  private void assertResult(String queryStr, List<String> names)
      throws RepositoryException, MalformedQueryException,
      QueryEvaluationException {
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryStr);
    TupleQueryResult result = query.evaluate();
    for (String name : names) {
      Value value = result.next().getValue("name");
      assertEquals(name, ((Literal) value).getLabel());
    }
    assertFalse(result.hasNext());
    result.close();
  }
View Full Code Here

    RepositoryConnection conn = null;
    try {
      conn = repo.getConnection();
      String query = "SELECT DISTINCT C FROM {} rdf:type {C}";
      TupleQueryResult classes = conn.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
      try {
        while (classes.hasNext()) {
          BindingSet bindingSet = classes.next();
          Resource resource = (Resource)bindingSet.getValue("C");
          result.add(resource);
        }
      }
      finally {
        classes.close();
      }
    }
    finally {
      if (conn != null) {
        try {
View Full Code Here

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

    TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all positive parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testName = bindingSet.getValue("testName").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();
      String outputURL = bindingSet.getValue("outputURL").toString();

      String baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new PositiveParserTest(testName, inputURL, outputURL, baseURL));
    }

    queryResult.close();

    // Add the manifest for negative test cases to a repository and query it
    con.clear();
    url = TriGParserTest.class.getResource(MANIFEST_BAD_URL);
    con.add(url, url.toExternalForm(), RDFFormat.TURTLE);

    query = "SELECT testName, inputURL " + "FROM {} mf:name {testName}; "
        + "        mf:action {} qt:data {inputURL} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all negative parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testName = bindingSet.getValue("testName").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();

      String baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new NegativeParserTest(testName, inputURL, baseURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

        + "from {TESTCASE} rdf:type {test:PositiveParserTest}; "
        + "                test:inputDocument {INPUT}; "
        + "                test:outputDocument {OUTPUT}; "
        + "                test:status {\"APPROVED\"} "
        + "using namespace test = <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>";
    TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String caseURI = bindingSet.getValue("TESTCASE").toString();
      String inputURL = bindingSet.getValue("INPUT").toString();
      String outputURL = bindingSet.getValue("OUTPUT").toString();
      suite.addTest(new PositiveParserTest(caseURI, inputURL, outputURL));
    }

    queryResult.close();

    // Add all negative parser tests
    query = "select TESTCASE, INPUT " + "from {TESTCASE} rdf:type {test:NegativeParserTest}; "
        + "                test:inputDocument {INPUT}; " + "                test:status {\"APPROVED\"} "
        + "using namespace test = <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String caseURI = bindingSet.getValue("TESTCASE").toString();
      String inputURL = bindingSet.getValue("INPUT").toString();
      suite.addTest(new NegativeParserTest(caseURI, inputURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

    throws RepositoryException
  {
    try {
      List<Resource> contextList = new ArrayList<Resource>();

      TupleQueryResult contextIDs = getRepository().getHTTPClient().getContextIDs();
      try {
        while (contextIDs.hasNext()) {
          BindingSet bindingSet = contextIDs.next();
          Value context = bindingSet.getValue("contextID");

          if (context instanceof Resource) {
            contextList.add((Resource)context);
          }
        }
      }
      finally {
        contextIDs.close();
      }

      return createRepositoryResult(contextList);
    }
    catch (QueryEvaluationException e) {
View Full Code Here

    throws RepositoryException
  {
    try {
      List<Namespace> namespaceList = new ArrayList<Namespace>();

      TupleQueryResult namespaces = getRepository().getHTTPClient().getNamespaces();
      try {
        while (namespaces.hasNext()) {
          BindingSet bindingSet = namespaces.next();
          Value prefix = bindingSet.getValue("prefix");
          Value namespace = bindingSet.getValue("namespace");

          if (prefix instanceof Literal && namespace instanceof Literal) {
            String prefixStr = ((Literal)prefix).getLabel();
            String namespaceStr = ((Literal)namespace).getLabel();
            namespaceList.add(new NamespaceImpl(prefixStr, namespaceStr));
          }
        }
      }
      finally {
        namespaces.close();
      }

      return createRepositoryResult(namespaceList);
    }
    catch (QueryEvaluationException e) {
View Full Code Here

   * send SeRQL-select queries.
   */
  public void testSeRQLselect()
    throws Exception
  {
    TupleQueryResult queryResult = evaluate(TestServer.REPOSITORY_URL, "select * from {X} P {Y}",
        QueryLanguage.SERQL);
    QueryResultIO.write(queryResult, TupleQueryResultFormat.SPARQL, System.out);
  }
View Full Code Here

    setContentDisposition(model, response, qrFormat);

    OutputStream out = response.getOutputStream();
    try {
      TupleQueryResultWriter qrWriter = qrWriterFactory.getWriter(out);
      TupleQueryResult tupleQueryResult = (TupleQueryResult)model.get(QUERY_RESULT_KEY);
      QueryResultUtil.report(tupleQueryResult, qrWriter);
    }
    catch (QueryEvaluationException e) {
      logger.error("Query evaluation error", e);
      response.sendError(SC_INTERNAL_SERVER_ERROR, "Query evaluation error: " + e.getMessage());
View Full Code Here

        // query result directly to the client.

        List<String> bindingNames = new ArrayList<String>();
        List<BindingSet> bindingSets = new ArrayList<BindingSet>();

        TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, REPOSITORY_LIST_QUERY).evaluate();
        try {
          // Determine the repository's URI
          StringBuffer requestURL = request.getRequestURL();
          if (requestURL.charAt(requestURL.length() - 1) != '/') {
            requestURL.append('/');
          }
          String namespace = requestURL.toString();

          while (queryResult.hasNext()) {
            QueryBindingSet bindings = new QueryBindingSet(queryResult.next());

            String id = bindings.getValue("id").stringValue();
            bindings.addBinding("uri", vf.createURI(namespace, id));

            bindingSets.add(bindings);
          }

          bindingNames.add("uri");
          bindingNames.addAll(queryResult.getBindingNames());
        }
        finally {
          queryResult.close();
        }

        TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response,
            TupleQueryResultWriterRegistry.getInstance());
View Full Code Here

TOP

Related Classes of org.openrdf.query.TupleQueryResult

Copyright © 2018 www.massapicom. 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.