Package com.hp.hpl.jena.query

Examples of com.hp.hpl.jena.query.QueryExecution


   
    public static boolean containsGraph(Store store, Node graphNode)
    {
        String qs = "SELECT * { GRAPH "+FmtUtils.stringForNode(graphNode)+" { ?s ?p ?o }} LIMIT 1" ;
        Dataset ds = SDBFactory.connectDataset(store) ;
        QueryExecution qExec = QueryExecutionFactory.create(qs, ds) ;
        ResultSet rs = qExec.execSelect() ;
        boolean b = rs.hasNext() ;
        qExec.close();
        return b ;
    }
View Full Code Here


           
            if ( printPlan )
            {
                divider() ;
                // This forces internal query initialization - must be after QueryUtils.checkQuery
                QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createMem()) ;
                QueryOutputUtils.printPlan(query, qExec) ;
            }
        }
        catch (ARQInternalErrorException intEx)
        {
View Full Code Here

    {
        Query query = modQuery.getQuery() ;

        try {
            String serviceURL = modRemote.getServiceURL() ;
            QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURL, query) ;
            if ( modRemote.usePost() )
                HttpQuery.urlLimit = 0 ;

            QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat()) ;
        } catch (QueryExceptionHTTP ex)
View Full Code Here

                                             "PREFIX  rdfs:   <http://www.w3.org/2000/01/rdf-schema#>",
                                             "PREFIX  xsd:    <http://www.w3.org/2001/XMLSchema#>",
                                             "PREFIX  owl:    <http://www.w3.org/2002/07/owl#>",
                                             "PREFIX skos:    <http://www.w3.org/2004/02/skos/core#>") ;
        Query query = QueryFactory.create(preamble+"\n"+qs, Syntax.syntaxARQ) ;
        QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
        ResultSet rs = qexec.execSelect() ;
        for ( ; rs.hasNext() ; )
        {
            QuerySolution soln= rs.next() ;
            Node x = soln.get("x").asNode() ;
            Node y = soln.get("y").asNode() ;
View Full Code Here

      "ORDER BY ?in";

    Query query = QueryFactory.create(queryString);

//     Execute the query and obtain results
    QueryExecution qe = QueryExecutionFactory.create(query, manifest);
    ResultSet results = qe.execSelect();
   
    WDSingleTest one = null;
    Resource last = null;
    while (results.hasNext()) {
      QuerySolution s = results.nextSolution();
      Resource in = s.getResource("in");
      Resource out = s.getResource("out");
      Resource test = s.getResource("test");
     
      Property approval = m.createProperty(
          TestSchema, "approval");
      if (!test.hasProperty(approval))
        System.out.println("#"+test.getLocalName());
      if (!in.equals(last)) {
        one = new WDSingleTest(in);
        tests.add(one);
        last = in;
      }
        one.addOutput(out,test);
     
    }
    qe.close();

  }
View Full Code Here

//    System.err.println(license);
    if (license.exists() && user != null && !user.equals("")) {
      try {
        model.read(new FileInputStream(license), null);

        QueryExecution qexec = QueryExecutionFactory.create(
            queryString, model);
        try {
          ResultSet results = qexec.execSelect();
          while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            try {
              Literal u = soln.getLiteral("user");
//              System.err.println("user: "+u.getString());
              Literal s = soln.getLiteral("software");
//              System.err.println("software: "+s);
              Calendar d = ((XSDDateTime) soln.getLiteral("date")
                  .getValue()).asCalendar();
//              System.err.println("date: "+d);
             
              if (u.getString().equals(user)
                  && s.getString().equals(software)
                  && d.before(Calendar.getInstance())) {
                return true;
              }
            } catch (JenaException e) {
              // ignore
            } catch (ClassCastException e) {
              System.err.println(e.getMessage());
            }
          }
        } finally {
          qexec.close();
        }

      } catch (FileNotFoundException e) {
      }
    }
View Full Code Here

    // when calling QueryFactory.create causes ExceptionInInitializerError
    // to be thrown.
    // QueryExecutionFactory.create requires
    // (java.io.FilePermission [etc/]location-mapping.* read)
    // Thus, they are placed within doPrivileged
    QueryExecution qexec = AccessController.doPrivileged (
        new PrivilegedAction<QueryExecution>() {

      @Override
      public QueryExecution run() {
        com.hp.hpl.jena.query.Query jenaQuery =
            QueryFactory.create(query.toString());
        return QueryExecutionFactory.create(jenaQuery, dataset);
      }
    });

    try {
      try {
        return new ResultSetWrapper(qexec.execSelect());
      } catch (QueryExecException e) {
        try {
          return Boolean.valueOf(qexec.execAsk());
        } catch (QueryExecException e2) {
          try {
            return new JenaGraphAdaptor(
                qexec.execDescribe().getGraph()).getGraph();
          } catch (QueryExecException e3) {
            return new JenaGraphAdaptor(
                qexec.execConstruct().getGraph()).getGraph();
          }
        }
      }
    } finally {
      qexec.close();
    }

  }
View Full Code Here

            expectedLabel = "Results file" ;
        }
        else
        {
            QueryEngineFactory f = QueryEngineRef.getFactory() ;
            QueryExecution qExec1 = new QueryExecutionBase(query, ds, null, f) ;
            rs1 = ResultSetFactory.makeRewindable(qExec1.execSelect()) ;
            qExec1.close() ;
            expectedLabel = "Standard engine" ;
        }
       
        // ---- Second, execute in DB

        QueryEngineFactory f2 = QueryEngineSDB.getFactory() ;
        ds = DatasetStore.create(store) ;
        QueryExecution qExec2 = new QueryExecutionBase(query, ds, null, f2) ;
       
        try {
            SDBConnection.logSQLExceptions = true ;
            rs = qExec2.execSelect() ;
           
            ResultSetRewindable rs2 = ResultSetFactory.makeRewindable(rs) ;
            boolean b = ResultSetCompare.equalsByTerm(rs1, rs2) ;
            if ( !b )
            {
View Full Code Here

//            // THis filter does not hide the graph itself, just the quads associated with the graph.
//            "SELECT * { GRAPH ?g {} }"
//            } ;
        Query query = QueryFactory.create(qs) ;
       
        QueryExecution qExec = QueryExecutionFactory.create(query, ds) ;
        // Install filter for this query only.
        qExec.getContext().set(SystemTDB.symTupleFilter, filter) ;
        qExec.getContext().setTrue(TDB.symUnionDefaultGraph) ;
        long x1 = ResultSetFormatter.consume(qExec.execSelect()) ;
        qExec.close() ;
        assertEquals(withFilter, x1) ;

        // No filter.
        qExec = QueryExecutionFactory.create(query, ds) ;
        qExec.getContext().setTrue(TDB.symUnionDefaultGraph) ;
        long x2 = ResultSetFormatter.consume(qExec.execSelect()) ;
        qExec.close() ;
        assertEquals(withoutFilter, x2) ;

    }
View Full Code Here

    System.out.println("RESULTS:");
   
    Query query = QueryFactory.create(Q);

    // Execute the query and obtain results
    QueryExecution qe = QueryExecutionFactory.create(query, model);
   
    if ( query.isSelectType() ) {
      ResultSet results = qe.execSelect();
      ResultSetFormatter.out(System.out, results, query);
    }
    else if ( query.isConstructType() ) {
      Model model_ = qe.execConstruct();
     
//      _listStatements(model_);

      StringWriter writer = new StringWriter();
      model_.getWriter().write(model_, writer, null);

      String result = writer.getBuffer().toString();
      System.out.println(result);

    }
    qe.close();
  }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.query.QueryExecution

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.