toolbox.dao
Class Query

Package class diagram package Query
java.lang.Object
  extended by toolbox.dao.Query

public class Query
extends java.lang.Object

Class that generates SQL query strings in Java prepared statement format.

The Query object is initialised with a prefix and postfix to be used in the generation of the query. Fields to be queried on are added to the object as name/value pairs.

The accessor method getSQL() returns the query string formatted in Java prepared statement format.

The accessor method getValues() returns an object array of the field values of the query object.


Nested Class Summary
(package private)  class Query.Field
          The Field class represents a field within the query being generated.
 
Field Summary
static java.lang.String EQUALS
          Equals operator (=).
static java.lang.String GREATER_EQUALS
          Greater than or equals operator (>=).
static java.lang.String LESS_EQUALS
          Less than or equals operator (<=).
static java.lang.String LIKE
          Like operator.
static java.lang.String NOT_EQUALS
          Not equals operator (!=).
static java.lang.String RANGE
          Specifies a range (x >= y1 and x <= y2).
 
Constructor Summary
Query()
          Default constructor
Query(java.lang.String prefix, java.lang.String postfix)
          Creates a new Query object with the given database table name and additional information that must be added to the generated query e.g order by clauses.
 
Method Summary
 void addField(java.lang.String name, java.lang.String type, java.lang.Object[] values)
          Adds a field to the query object.
 java.lang.String getSQL()
          Generates a SQL query in Java prepared statement format.
 java.lang.Object[] getValues()
          Returns an Object array of field values contained in this query object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EQUALS

public static final java.lang.String EQUALS
Equals operator (=).

See Also:
Constant Field Values

NOT_EQUALS

public static final java.lang.String NOT_EQUALS
Not equals operator (!=).

See Also:
Constant Field Values

LESS_EQUALS

public static final java.lang.String LESS_EQUALS
Less than or equals operator (<=).

See Also:
Constant Field Values

GREATER_EQUALS

public static final java.lang.String GREATER_EQUALS
Greater than or equals operator (>=).

See Also:
Constant Field Values

LIKE

public static final java.lang.String LIKE
Like operator.

See Also:
Constant Field Values

RANGE

public static final java.lang.String RANGE
Specifies a range (x >= y1 and x <= y2).

See Also:
Constant Field Values
Constructor Detail

Query

public Query()
Default constructor


Query

public Query(java.lang.String prefix,
             java.lang.String postfix)
Creates a new Query object with the given database table name and additional information that must be added to the generated query e.g order by clauses.

Parameters:
prefix - Use this prefix instead of select *
postfix - Additional information to add on to the generated query.
Method Detail

addField

public void addField(java.lang.String name,
                     java.lang.String type,
                     java.lang.Object[] values)
Adds a field to the query object. A null value will be discarded and will not form part of the generated query.

Parameters:
name - Name of the field to add.
type - Type of the field to add: single or range.
values - Values of the field to add.

getSQL

public java.lang.String getSQL()
Generates a SQL query in Java prepared statement format.

Returns:
String containing a query string in Java prepared statement format.

getValues

public java.lang.Object[] getValues()
Returns an Object array of field values contained in this query object.

Returns:
Object array of field values.