@Override
  protected QueryExecution createQueryExecution(Query q) throws SQLException {
    if (this.remoteConn.getQueryEndpoint() == null)
      throw new SQLException(
          "This statement is backed by a write-only connection, read operations are not supported");

    // Create basic execution
    QueryEngineHTTP exec =
        (QueryEngineHTTP)
            QueryExecutionFactory.sparqlService(this.remoteConn.getQueryEndpoint(), q);

    // Apply HTTP settings
    if (this.client != null) {
      exec.setClient(this.client);
    }

    // Apply default and named graphs if appropriate
    if (this.remoteConn.getDefaultGraphURIs() != null) {
      exec.setDefaultGraphURIs(this.remoteConn.getDefaultGraphURIs());
    }
    if (this.remoteConn.getNamedGraphURIs() != null) {
      exec.setNamedGraphURIs(this.remoteConn.getNamedGraphURIs());
    }

    // Set result types
    if (this.remoteConn.getSelectResultsType() != null) {
      exec.setSelectContentType(this.remoteConn.getSelectResultsType());
    }
    if (this.remoteConn.getModelResultsType() != null) {
      exec.setModelContentType(this.remoteConn.getModelResultsType());
    }

    // Return execution
    return exec;
  }
예제 #2
0
  @Test
  public void testSparql() {

    String queryStr = "select distinct ?Concept where {[] a ?Concept} LIMIT 10";
    Query query = QueryFactory.create(queryStr);

    // Remote execution.
    try (QueryExecution qexec =
        QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query)) {
      // Set the DBpedia specific timeout.
      ((QueryEngineHTTP) qexec).addParam("timeout", "10000");

      // Execute.
      ResultSet rs = qexec.execSelect();
      ResultSetFormatter.out(System.out, rs, query);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }