com.hp.hpl.jena.rdql
Class QueryResultsFormatter

java.lang.Object
  extended bycom.hp.hpl.jena.rdql.QueryResultsFormatter

public class QueryResultsFormatter
extends java.lang.Object

Takes a QueryResult object and returns formatted (in various ways) Useful for the scripting interface. May help for display in other contexts.

Note: this is compute intensive and memory intensive. It needs to read all the results first (all the results are now in-memory - not kept here) in order to find things like the maximum length of a column value; then it needs to pass over the results again, turning them into Strings again, in order to return them.

We prefer slow and less memory intensive because it is more rebust for scripting.

Don't keep QueryResultsFormatter's around unnecessarily!

Version:
$Id: QueryResultsFormatter.java,v 1.9 2003/07/15 13:26:58 andy_seaborne Exp $
Author:
Andy Seaborne

Field Summary
static java.lang.String resultsNamespace
           
 
Constructor Summary
QueryResultsFormatter(QueryResults qresults)
          Create a formatter for a QueryResults object
 
Method Summary
 Resource asRDF(Model model)
          Encode the result set as RDF in the model provided.
 void close()
          Forcefully clearup.
 void consume()
          This operation faithfully walks the results but does nothing with them.
 void dump(java.io.PrintWriter pw, boolean format)
          Write out a compact form.
 int numColumns()
          How wide is the result table
 int numRows()
          How deep is the result table.
 void printAll(java.io.PrintWriter printwriter)
          Textual representation : default layout using " | " to separate columns
 void printAll(java.io.PrintWriter printwriter, java.lang.String colSep)
          Textual representation : layout using given separator
 void printAll(java.io.PrintWriter printwriter, java.lang.String colSep, java.lang.String lineEnd)
          Textual representation : layout using given separator
 void printHTML(java.io.PrintWriter pw)
          HTML representation
 Model toModel()
          Encode the result set as RDF.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resultsNamespace

public static final java.lang.String resultsNamespace
See Also:
Constant Field Values
Constructor Detail

QueryResultsFormatter

public QueryResultsFormatter(QueryResults qresults)
Create a formatter for a QueryResults object

Method Detail

numColumns

public int numColumns()
How wide is the result table


numRows

public int numRows()
How deep is the result table. Negative implies unknown


close

public void close()
Forcefully clearup. As results might have been read into memory, this operation signals intermediate data is no longer needed.


toModel

public Model toModel()
Encode the result set as RDF.

Returns:
Model Model contains the results

asRDF

public Resource asRDF(Model model)
Encode the result set as RDF in the model provided.

Parameters:
model - The place where to put the RDF.
Returns:
Resource The resource for the result set.

dump

public void dump(java.io.PrintWriter pw,
                 boolean format)
Write out a compact form. This encodes all the information is a vaguely readable way but is suitable for reading in again. Used for testing.


printAll

public void printAll(java.io.PrintWriter printwriter)
Textual representation : default layout using " | " to separate columns

Parameters:
printwriter - Output

printAll

public void printAll(java.io.PrintWriter printwriter,
                     java.lang.String colSep)
Textual representation : layout using given separator

Parameters:
printwriter - Output
colSep - Column separator

printAll

public void printAll(java.io.PrintWriter printwriter,
                     java.lang.String colSep,
                     java.lang.String lineEnd)
Textual representation : layout using given separator

Parameters:
printwriter - Output
colSep - Column separator
lineEnd - String to add to end of lines

printHTML

public void printHTML(java.io.PrintWriter pw)
HTML representation


consume

public void consume()
This operation faithfully walks the results but does nothing with them. Used in timing operations. Be careful that a compiler does not optimize some or all of it away!



Copyright © 2001-2003 Hewlett-Packard. All Rights Reserved.