org.liquidsite.util.db
Class DatabaseQuery

java.lang.Object
  extended byorg.liquidsite.util.db.DatabaseQuery

public class DatabaseQuery
extends java.lang.Object

A database query. This class encapsulates an SQL query or statement that can be executed on a database connection.


Constructor Summary
DatabaseQuery()
          Creates a new empty database query.
DatabaseQuery(java.lang.String name)
          Creates a new database query with the specified name.
 
Method Summary
 void addParameter(boolean value)
          Adds a boolean query parameter.
 void addParameter(int value)
          Adds an integer query parameter.
 void addParameter(java.lang.Object obj)
          Adds a query parameter.
 java.lang.String getName()
          Returns the query name.
 java.lang.Object getParameter(int pos)
          Returns a query parameter.
 int getParameterCount()
          Returns the number of query parameters.
 java.lang.String getSql()
          Returns the SQL text for the query.
 boolean hasResults()
          Checks if this database query will create a result.
 boolean hasSql()
          Checks if this query has SQL text.
 void setSql(java.lang.String sql)
          Sets the SQL text for the query.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DatabaseQuery

public DatabaseQuery()
Creates a new empty database query. In order to execute this query, the SQL text must be set.

See Also:
setSql(java.lang.String)

DatabaseQuery

public DatabaseQuery(java.lang.String name)
Creates a new database query with the specified name. The query name can be used by the database connector to retrieve the SQL for the query.

Parameters:
name - the query name
Method Detail

hasSql

public boolean hasSql()
Checks if this query has SQL text. This method will return false for named queries, until they have been executed once.

Returns:
true if the query has SQL text, or false otherwise

hasResults

public boolean hasResults()
Checks if this database query will create a result. This method will always return false, if no SQL has been set to the query.

Returns:
true if the query will return a result, or false otherwise

getName

public java.lang.String getName()
Returns the query name.

Returns:
the query name, or null if no name has been set

getSql

public java.lang.String getSql()
Returns the SQL text for the query.

Returns:
the SQL text for the query, or null if no SQL text has been set

setSql

public void setSql(java.lang.String sql)
Sets the SQL text for the query. This is normally not needed when using named queries, as the database connector will then retrieve the SQL text and call this method.

Parameters:
sql - the SQL text

getParameterCount

public int getParameterCount()
Returns the number of query parameters.

Returns:
the number of query parameters

getParameter

public java.lang.Object getParameter(int pos)
Returns a query parameter.

Parameters:
pos - the parameter position, 0 <= pos < count
Returns:
the query parameter object

addParameter

public void addParameter(java.lang.Object obj)
Adds a query parameter. Note that this method DOES NOT support adding arrays are parameters.

Parameters:
obj - the query parameter

addParameter

public void addParameter(int value)
Adds an integer query parameter.

Parameters:
value - the query parameter value

addParameter

public void addParameter(boolean value)
Adds a boolean query parameter. This method converts the boolean value to an integer before adding it, using zero (0) for false and one (1) for true.

Parameters:
value - the query parameter value

toString

public java.lang.String toString()
Returns a string representation of this object.

Returns:
a string representation of this object