Examples of QueryExecution


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

        System.out.println() ;
       
        // Create a single execution of this query, apply to a model
        // which is wrapped up as a Dataset
       
        QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
        // Or QueryExecutionFactory.create(queryString, model) ;

        try {
            // A ResultSet is an iterator - any query solutions returned by .next()
            // are not accessible again.
            // Create a ResultSetRewindable that can be reset to the beginning.
            // Do before first use.
           
            ResultSetRewindable rewindable = ResultSetFactory.makeRewindable(qexec.execSelect()) ;
            ResultSetFormatter.out(rewindable) ;
            rewindable.reset() ;
            ResultSetFormatter.out(rewindable) ;
        }
        finally
        {
            // QueryExecution objects should be closed to free any system resources
            qexec.close() ;
        }
    }
View Full Code Here

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

        // Prefix mapping just helps serialization
        query.getPrefixMapping().setNsPrefix("dc" , DC.getURI()) ;
        query.serialize(new IndentedWriter(System.out,true)) ;
        System.out.println() ;
       
        QueryExecution qexec = QueryExecutionFactory.create(query, model) ;

        try {
            // Assumption: it's a SELECT query.
            ResultSet rs = qexec.execSelect() ;
           
            // The order of results is undefined.
            System.out.println("Titles: ") ;
            for ( ; rs.hasNext() ; )
            {
                QuerySolution rb = rs.nextSolution() ;
               
                // Get title - variable names do not include the '?' (or '$')
                RDFNode x = rb.get("title") ;
               
                // Check the type of the result value
                if ( x instanceof Literal )
                {
                    Literal titleStr = (Literal)x  ;
                    System.out.println("    "+titleStr) ;
                }
                else
                    System.out.println("Strange - not a literal: "+x) ;
                   
            }
        }
        finally
        {
            // QueryExecution objects should be closed to free any system resources
            qexec.close() ;
        }
    }
View Full Code Here

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

        System.out.println() ;
       
        // Create a single execution of this query, apply to a model
        // which is wrapped up as a Dataset
       
        QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
        // Or QueryExecutionFactory.create(queryString, model) ;

        System.out.println("Titles: ") ;
       
        try {
            // Assumption: it's a SELECT query.
            ResultSet rs = qexec.execSelect() ;
           
            // The order of results is undefined.
            for ( ; rs.hasNext() ; )
            {
                QuerySolution rb = rs.nextSolution() ;
               
                // Get title - variable names do not include the '?' (or '$')
                RDFNode x = rb.get("title") ;
               
                // Check the type of the result value
                if ( x.isLiteral() )
                {
                    Literal titleStr = (Literal)x  ;
                    System.out.println("    "+titleStr) ;
                }
                else
                    System.out.println("Strange - not a literal: "+x) ;
                   
            }
        }
        finally
        {
            // QueryExecution objects should be closed to free any system resources
            qexec.close() ;
        }
    }
View Full Code Here

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

       
        Query query = QueryFactory.create(queryString) ;
        query.serialize(System.out) ;
        System.out.println();
                                         
        QueryExecution qExec = QueryExecutionFactory.create(query, model) ;
        //LARQ.setDefaultIndex(qExec.getContext(), index) ;
        ResultSetFormatter.out(System.out, qExec.execSelect(), query) ;
        qExec.close() ;
    }
View Full Code Here

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

        // Prefix mapping just helps serialization
        query.getPrefixMapping().setNsPrefix("dc" , DC.getURI()) ;
        query.serialize(new IndentedWriter(System.out,true)) ;
        System.out.println() ;
       
        QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
       
        try {
            // Assumption: it's a SELECT query.
            ResultSet rs = qexec.execSelect() ;
           
            // The order of results is undefined.
            System.out.println("Titles: ") ;
            for ( ; rs.hasNext() ; )
            {
                QuerySolution rb = rs.nextSolution() ;
               
                // Get title - variable names do not include the '?' (or '$')
                RDFNode x = rb.get("title") ;
               
                // Check the type of the result value
                if ( x instanceof Literal )
                {
                    Literal titleStr = (Literal)x  ;
                    System.out.println("    "+titleStr) ;
                }
                else
                    System.out.println("Strange - not a literal: "+x) ;
                   
            }
        }
        finally
        {
            // QueryExecution objects should be closed to free any system resources
            qexec.close() ;
        }
    }
View Full Code Here

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

        String prologue = "PREFIX ext: <java:arq.examples.propertyfunction.>\n" ;

        String qs = prologue+"SELECT * { ?x ext:labelSearch 'EF' }" ;
        Query query = QueryFactory.create(qs) ;
        Model model = make() ;
        QueryExecution qExec = QueryExecutionFactory.create(query, model) ;
        try {
            ResultSet rs = qExec.execSelect() ;
            ResultSetFormatter.out(rs) ;
        } finally { qExec.close() ; }
       
        // Or register it.
        PropertyFunctionRegistry.get().put("http://example/f#search", labelSearch.class) ;
        prologue = "PREFIX ext: <http://example/f#>\n" ;
        qs = prologue+"SELECT * { ?x ext:search 'EF' }" ;
        query = QueryFactory.create(qs) ;
        qExec = QueryExecutionFactory.create(query, model) ;
        try {
            ResultSet rs = qExec.execSelect() ;
            ResultSetFormatter.out(rs) ;
        } finally { qExec.close() ; }
    }
View Full Code Here

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

            StageGenerator stageGenAlt = new StageGeneratorAlt(origStageGen) ;
            ARQ.getContext().set(ARQ.stageGenerator, stageGenAlt) ;
        }
       
        Query query = QueryFactory.create( StrUtils.strjoin("\n", queryString)) ;
        QueryExecution engine = QueryExecutionFactory.create(query, makeData()) ;
       
        // ... or set on a per-execution basis.
        if ( true )
        {
            StageGenerator origStageGen = (StageGenerator)engine.getContext().get(ARQ.stageGenerator) ;
            StageGenerator stageGenAlt = new StageGeneratorAlt(origStageGen) ;
            engine.getContext().set(ARQ.stageGenerator, stageGenAlt) ;
        }
       
        QueryExecUtils.executeQuery(query, engine) ;
    }
View Full Code Here

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

        SDBConnection conn = new SDBConnection(jdbcConnection) ;
       
        Store store = StoreFactory.create(storeDesc, conn) ;
       
        Dataset ds = DatasetStore.create(store) ;
        QueryExecution qe = QueryExecutionFactory.create(query, ds) ;
        try {
            ResultSet rs = qe.execSelect() ;
            ResultSetFormatter.out(rs) ;
        } finally { qe.close() ; }
        // Does not close the JDBC connection.
        // Do not call : store.getConnection().close() , which does close the underlying connection.
        store.close() ;
    }
View Full Code Here

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

    private static void example(Dataset ds, String qs, Filter<Tuple<NodeId>> filter)
    {
        System.out.println() ;
        Query query = QueryFactory.create(qs) ;
        System.out.println(qs) ;
        QueryExecution qExec = QueryExecutionFactory.create(query, ds) ;
        // Install filter for this query only.
        if ( filter != null )
        {
            System.out.println("Install quad-level filter") ;
            qExec.getContext().set(SystemTDB.symTupleFilter, filter) ;
        }
        else
            System.out.println("No quad-level filter") ;
        ResultSetFormatter.out(qExec.execSelect()) ;
        qExec.close() ;

    }
View Full Code Here

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

        // Potentially expensive query.
        String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
        // See http://www.openjena.org/ARQ/app_api.html
       
        Query query = QueryFactory.create(sparqlQueryString) ;
        QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
        try {
          ResultSet results = qexec.execSelect() ;
          for ( ; results.hasNext() ; )
          {
              QuerySolution soln = results.nextSolution() ;
              int count = soln.getLiteral("count").getInt() ;
              System.out.println("count = "+count) ;
          }
        } finally { qexec.close() ; }

        // Close the dataset.
        dataset.close();
       
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.