Package org.openrdf.query

Examples of org.openrdf.query.TupleQueryResult


    try {
      RepositoryConnection conn = m_source.getConnection();
      String query = "SELECT * FROM {<" + ((URI) subject).toString() + ">} <"
              + property.toString() + "> {y}";
            TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SERQL, query);
            TupleQueryResult results = q.evaluate();
      answer = results.hasNext();
      results.close();
      conn.close();
    } catch (Exception e) {
      ;
    }
    return answer;
View Full Code Here


    try {
      RepositoryConnection conn = m_source.getConnection();
      String query = "SELECT y FROM {<" + ((URI) subject).toString() + ">} <"
              + property.toString() + "> {y}";
      TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SERQL, query);
      TupleQueryResult results = q.evaluate();
      if (results.hasNext()) {
        Value object = results.next().getValue("y");
        answer = new StatementImpl(subject, property, object);
      }
      results.close();
      conn.close();
    } catch (Exception e) {
      ;
    }
   
View Full Code Here

    RepositoryConnection conn;
    try {
      conn = in.getConnection();

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, this._SPARQL);
      TupleQueryResult result = tupleQuery.evaluate();

      String firstBindingName = result.getBindingNames().get(0);

      while (result.hasNext()) {
        Value uri = result.next().getBinding(firstBindingName).getValue();
        if (uri instanceof URI) {
          resources.add((Resource) uri);
        }
      }

      result.close();
      conn.close();
    } catch (RepositoryException e) {
      throw new InvalidResultSetException("Repository exception encountered selecting resources", e);
    } catch (MalformedQueryException e) {
      throw new InvalidResultSetException("Bad query encountered selecting resources using " + this._SPARQL, e);
View Full Code Here

    RepositoryConnection conn;
    try {
      conn = in.getConnection();

      TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, this._SPARQL);
      TupleQueryResult result = tupleQuery.evaluate();

      String firstBindingName = result.getBindingNames().get(0);

      while (result.hasNext()) {
        Value uri = result.next().getBinding(firstBindingName).getValue();
        if (uri instanceof URI) {
          values.add(uri);
        }
      }

      result.close();
      conn.close();
    } catch (RepositoryException e) {
      throw new InvalidResultSetException("Repository exception encountered selecting nodes", e);
    } catch (MalformedQueryException e) {
      throw new InvalidResultSetException("Bad query encountered selecting nodes using " + this._SPARQL, e);
View Full Code Here

    try {
      RepositoryConnection con = repos.getConnection();
      try {

        TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL,CLASSES_QUERY_P1 + uri + CLASSES_QUERY_P2);
        TupleQueryResult res = query.evaluate();

        Set<String> seen = new HashSet<String>();
        while (res.hasNext()) {
          BindingSet solution = res.next();
          String clazzURI = solution.getValue("resource").stringValue();
          if (seen.contains(clazzURI)) {
            continue;
          }
          seen.add(clazzURI);
          String label = getFirstNotNull(new Value[] {
              solution.getValue("en_label"),
              solution.getValue("label") });
          String description = getFirstNotNull(new Value[] {
              solution.getValue("en_definition"),
              solution.getValue("definition"),
              solution.getValue("en_description"),
              solution.getValue("description") });
          RDFSClass clazz = new RDFSClass(clazzURI, label,
              description, name, uri);
          classes.add(clazz);
        }
       
        query = con.prepareTupleQuery(QueryLanguage.SPARQL,PROPERTIES_QUERY_P1 + uri + PROPERTIES_QUERY_P2);
        res = query.evaluate();
        seen = new HashSet<String>();
        while (res.hasNext()) {
          BindingSet solution = res.next();
          String propertyUri = solution.getValue("resource").stringValue();
          if (seen.contains(propertyUri)) {
            continue;
          }
          seen.add(propertyUri);
View Full Code Here

        try {
            RepositoryConnection connection = sesameService.getConnection();
            try {
                connection.begin();
                TupleQuery tupleQuery = connection.prepareTupleQuery(queryLanguage, query);
                TupleQueryResult r = tupleQuery.evaluate();
                try {
                    while (r.hasNext()) {
                        BindingSet s = r.next();
                        Map<String, Value> map = new HashMap<String, Value>();
                        for (Binding binding : s) {
                            map.put(binding.getName(), binding.getValue());
                        }
                        result.add(map);
                    }
                } finally {
                    r.close();
                }
                //
                connection.commit();
            } finally {
                connection.close();
View Full Code Here

        RepositoryConnection con2 = reference.getConnection();
        try {
            con1.begin();

            TupleQuery query1 = con1.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
            TupleQueryResult result1 = query1.evaluate();

            con1.commit();

            Assert.assertTrue(result1.hasNext());


            con2.begin();

            TupleQuery query2 = con2.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
            TupleQueryResult result2 = query2.evaluate();

            con2.commit();

            compareResults(result1,result2);
View Full Code Here

        try {
            RepositoryConnection connection = sesameService.getConnection();
            try {
                connection.begin();
                TupleQuery tupleQuery = connection.prepareTupleQuery(queryLanguage, query);
                TupleQueryResult r = tupleQuery.evaluate();
                try {
                    while (r.hasNext()) {
                        BindingSet s = r.next();
                        Map<String, Value> map = new HashMap<String, Value>();
                        for (Binding binding : s) {
                            map.put(binding.getName(), binding.getValue());
                        }
                        result.add(map);
                    }
                } finally {
                    r.close();
                }
                //
                connection.commit();
            } finally {
                connection.close();
View Full Code Here

    private void doQuery(final String query,
                         final RepositoryConnection rc,
                         final PrintStream ps,
                         final CSVOutputter outputter) throws Exception {
        TupleQuery q = rc.prepareTupleQuery(QueryLanguage.SPARQL, query);
        TupleQueryResult r = q.evaluate();
        while (r.hasNext()) {
            StringBuilder sb = new StringBuilder();
            outputter.output(r.next(), sb);
            ps.println(sb.toString());
        }
    }
View Full Code Here

   * @param <T> generic type of RowMapper
   * @return List of results from the RowMapper calls
   */
  public <T> List<T> query(String sparql, Map<String, Object> args, RowMapper<T> mapper) {
    Connection connection = dataSource.getConnection();
    TupleQueryResult result = null;
    try {
      SelectQuery query = connection.select(sparql);
     
      if (args != null) {
        for (Entry<String, Object> arg : args.entrySet()) {          
          query.parameter(arg.getKey(), arg.getValue());
        }
      }
     
      ArrayList<T> list = new ArrayList<T>();
     
      result = query.execute();
     
      // return empty lists for empty queries
      if (result == null) {
        return list;
      }
     
      while (result.hasNext()) {
        list.add(mapper.mapRow(result.next()));
      }

      return list;
    } catch (StardogException e) {
      log.error("Error sending query to Stardog", e);
      throw new RuntimeException(e);
    } catch (QueryEvaluationException e) {
      log.error("Error evaluating SPARQL query", e);
      throw new RuntimeException(e);
    } finally {
      if (result != null) {
        try {
          result.close();
        }
        catch (QueryEvaluationException e) { }
      }
      dataSource.releaseConnection(connection);
    }
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.