com.mkdoc.sesame
Class SeRQLQueryBuilder

java.lang.Object
  |
  +--com.mkdoc.sesame.SeRQLQueryBuilder

public class SeRQLQueryBuilder
extends java.lang.Object

A builder for SeRQL query strings.

This initial draft is string-based with no substantial validation of variable and namespace usage versus declaration. Conditional clauses are combined as OR statements.

Version:
0.3 2005-01-25
Author:
Philip Shaw

Field Summary
static java.lang.String APPEND_AND
          An AND keyword.
protected static java.lang.String APPEND_COMMA
          A comma separator.
static java.lang.String APPEND_OR
          An OR keyword.
static java.lang.String CONSTRUCT
          A CONSTRUCT query type.
static java.lang.String DISTINCT
          A DISTINCT keyword.
static java.lang.String FROM
          A FROM keyword.
static java.lang.String SELECT
          A SELECT query type.
protected static java.lang.String SPACE
          A single space character.
static java.lang.String USING
          A USING NAMESPACE declaration.
static java.lang.String WHERE
          A WHERE keyword.
 
Constructor Summary
SeRQLQueryBuilder()
           
 
Method Summary
 void addCondition(java.lang.String condition)
          Add a condition to the query selection.
 void addExpression(java.lang.String expression)
          Add a path expression to the query.
 void addNamespace(java.lang.String namespace)
          Add a namespace declaration to the query selection.
 void addVariable(java.lang.String name)
          Add a variable name.
protected  void appendList(java.util.Collection values, java.lang.StringBuffer buffer, java.lang.String separator)
          Concatenate a collection of string values with the given separator.
 void setDistinct(boolean distinct)
          Set whether the DISTINCT keyword is applied.
 void setQueryType(java.lang.String queryType)
          Set query type.
 java.lang.String toString()
          Get a string representation of the query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SPACE

protected static final java.lang.String SPACE
A single space character.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

APPEND_COMMA

protected static final java.lang.String APPEND_COMMA
A comma separator.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

SELECT

public static final java.lang.String SELECT
A SELECT query type.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

CONSTRUCT

public static final java.lang.String CONSTRUCT
A CONSTRUCT query type.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

DISTINCT

public static final java.lang.String DISTINCT
A DISTINCT keyword.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

FROM

public static final java.lang.String FROM
A FROM keyword.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

APPEND_AND

public static final java.lang.String APPEND_AND
An AND keyword.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

APPEND_OR

public static final java.lang.String APPEND_OR
An OR keyword.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

WHERE

public static final java.lang.String WHERE
A WHERE keyword.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values

USING

public static final java.lang.String USING
A USING NAMESPACE declaration.

Since:
Version 0.1 2005-01-24
See Also:
Constant Field Values
Constructor Detail

SeRQLQueryBuilder

public SeRQLQueryBuilder()
Method Detail

addVariable

public final void addVariable(java.lang.String name)
Add a variable name.

Parameters:
name - The name of a variable value to get from the query.
Since:
Version 0.1 2005-01-24

addExpression

public final void addExpression(java.lang.String expression)
Add a path expression to the query.

Parameters:
expression - A single path expression, no trailing comma or semi-colon.
Since:
Version 0.1 2005-01-24

addCondition

public final void addCondition(java.lang.String condition)
Add a condition to the query selection.

Parameters:
condition - A condition, no trailing comma or semi-colon.
Since:
Version 0.1 2005-01-24

addNamespace

public final void addNamespace(java.lang.String namespace)
Add a namespace declaration to the query selection.

Parameters:
namespace - A namespace, no trailing comma.
Since:
Version 0.1 2005-01-24

setDistinct

public final void setDistinct(boolean distinct)
Set whether the DISTINCT keyword is applied.

Parameters:
distinct - Whether the query interpreter should suppress duplicate results.
Since:
Version 0.1 2005-01-24

setQueryType

public final void setQueryType(java.lang.String queryType)
Set query type.

Parameters:
queryType - SELECT or CONSTRUCT.
Since:
Version 0.1 2005-01-24

toString

public final java.lang.String toString()
Get a string representation of the query.

At least one variable declaration and one path expression must be added to the query before calling this method.

Overrides:
toString in class java.lang.Object
Returns:
A SeRQL query string generated from the current builder configuration.
Since:
Version 0.1 2005-01-24

appendList

protected final void appendList(java.util.Collection values,
                                java.lang.StringBuffer buffer,
                                java.lang.String separator)
Concatenate a collection of string values with the given separator.

If there is more than one item in the collection, the separator text is inserted before each subsequent item. No leading or trailing spaces are added.

Parameters:
values - The list of string values to concatenate.
buffer - The string buffer to append values to.
separator - The separator characters to insert before each list item, e.g. " AND ", or ", ".
Since:
Version 0.1 2005-01-24