Package org.openrdf.query

Examples of org.openrdf.query.TupleQueryResult


                boolean first = true;
            ExpressionQueryResult eqr = ((ExpressionFragment) f).expression.computeOutputOnValue(
                value, database, connection);
           
                if (eqr != null) {
                      TupleQueryResult queryResult = eqr.tupleQuery.evaluate();
                      try {
                        while (queryResult.hasNext()) {
                          BindingSet bindingSet = queryResult.next();
                          Value value2 = bindingSet.getValue(eqr.resultVar.getName());
                         
                          if (first) {
                            first = false;
                          } else {
                            sb.append(";");
                          }
                         
                          sb.append(renderInnerValueToText(value2, database, connection));
                        }
                      } finally {
                          queryResult.close();
                      }
                } else {
                  sb.append(renderInnerValueToText(value, database, connection));
                }
          } catch (Exception e) {
View Full Code Here


        + "FROM {testURI} rdf:type {n3test:PositiveParserTest}; "
        + "               n3test:inputDocument {inputURL}; "
        + "               n3test:outputDocument {outputURL} "
        + "USING NAMESPACE n3test = <http://www.w3.org/2004/11/n3test#>";

    TupleQueryResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while(queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testURI = bindingSet.getValue("testURI").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();
      String outputURL = bindingSet.getValue("outputURL").toString();

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

    queryResult.close();

    // Add all negative parser tests to the test suite
    query = "SELECT testURI, inputURL "
        + "FROM {testURI} rdf:type {n3test:NegativeParserTest}; "
        + "               n3test:inputDocument {inputURL} "
        + "USING NAMESPACE n3test = <http://www.w3.org/2004/11/n3test#>";

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

    while(queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testURI = bindingSet.getValue("testURI").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();

      suite.addTest(new NegativeParserTest(testURI, inputURL));
    }
    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

    try {
      HTTPClient httpClient = new HTTPClient();
      httpClient.setServerURL(serverURL);
      httpClient.setUsernameAndPassword(username, password);

      TupleQueryResult responseFromServer = httpClient.getRepositoryList();
      while (responseFromServer.hasNext()) {
        BindingSet bindingSet = responseFromServer.next();
        RepositoryInfo repInfo = new RepositoryInfo();

        String id = LiteralUtil.getLabel(bindingSet.getValue("id"), null);

        if (skipSystemRepo && id.equals(SystemRepository.ID)) {
View Full Code Here

  }

  public void evaluate(TupleQueryResultHandler handler)
    throws QueryEvaluationException, TupleQueryResultHandlerException
  {
    TupleQueryResult queryResult = evaluate();
    QueryResultUtil.report(queryResult, handler);
  }
View Full Code Here

    HTTPRepository repo = (HTTPRepository)request.getSession().getAttribute(SessionKeys.REPOSITORY_KEY);

    SelectQueryInfo qInfo = (SelectQueryInfo)command;

    TupleQueryResult queryResult = null;

    RepositoryConnection conn = null;
    try {
      conn = repo.getConnection();

      HTTPTupleQuery query = (HTTPTupleQuery)conn.prepareTupleQuery(qInfo.getQueryLanguage(),
          qInfo.getQueryString());
      query.setIncludeInferred(qInfo.isIncludeInferred());
      try {
        queryResult = query.evaluate();
      }
      catch (HTTPQueryEvaluationException e) {
        if (e.isCausedByMalformedQueryException()) {
          throw e.getCauseAsMalformedQueryException();
        }
        else if (e.isCausedByRepositoryException()) {
          throw e.getCauseAsRepositoryException();
        }
        else if (e.isCausedByIOException()) {
          throw e.getCauseAsIOException();
        }
        else {
          throw e;
        }
      }
    }
    catch (RepositoryException e) {
      logger.info("Unable to process query", e);
      errors.reject("repository.error");
    }
    catch (MalformedQueryException e) {
      errors.rejectValue("queryString", "repository.query.error.malformed", new String[] { e.getMessage() }, "Malformed query");
    }
    catch (QueryEvaluationException e) {
      errors.reject("repository.query.error.evaluation");
    }
    finally {
      // FIXME: check to see where this connection gets closed
      // if (conn != null) {
      // try {
      // conn.close();
      // }
      // catch (RepositoryException e) {
      // e.printStackTrace();
      // }
      // }
    }

    if (errors.hasErrors()) {
      result = showForm(request, response, errors, errors.getModel());
    }
    else {
      @SuppressWarnings("unchecked")
      Map<String, Object> model = errors.getModel();

      model.put("bindingNames", queryResult.getBindingNames());
      model.put("solutions", queryResult);

      result = new ModelAndView(getSuccessView(), model);
    }
View Full Code Here

  private Literal hunt;

  public void testInline() throws Exception {
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryInline);
    TupleQueryResult result = query.evaluate();
    assertEquals(hunt, result.next().getValue("name"));
    assertFalse(result.hasNext());
    result.close();
  }
View Full Code Here

  public void testBinding() throws Exception {
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryBinding);
    query.setBinding("pattern", vf.createLiteral("@work.example"));
    TupleQueryResult result = query.evaluate();
    assertEquals(hunt, result.next().getValue("name"));
    assertFalse(result.hasNext());
    result.close();
  }
View Full Code Here

  public void testBindingFlags() throws Exception {
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryBindingFlags);
    query.setBinding("pattern", vf.createLiteral("@Work.example"));
    query.setBinding("flags", vf.createLiteral("i"));
    TupleQueryResult result = query.evaluate();
    assertEquals(hunt, result.next().getValue("name"));
    assertFalse(result.hasNext());
    result.close();
  }
View Full Code Here

    BNode bnode = vf.createBNode();
    conn.add(bnode, pattern, vf.createLiteral("@Work.example"));
    conn.add(bnode, flags, vf.createLiteral("i"));
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryExpr);
    TupleQueryResult result = query.evaluate();
    assertEquals(hunt, result.next().getValue("name"));
    assertFalse(result.hasNext());
    result.close();
  }
View Full Code Here

  private Repository repository;

  public void testValueExceptionLessThan() throws Exception {
    TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
        queryStr1);
    TupleQueryResult evaluate = query.evaluate();
    try {
      assertFalse(evaluate.hasNext());
    } finally {
      evaluate.close();
    }
  }
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.