org.brains2b.data.sql
Class SqlCondition

java.lang.Object
  extended by org.brains2b.data.Condition
      extended by org.brains2b.data.sql.SqlCondition
Direct Known Subclasses:
OracleCondition

public class SqlCondition
extends Condition

SqlCondition is a specific implementation of Condition for SQL databases.

Version:
0.24.1 [15-03-2008]
Author:
dennis@brains2b.nl
See Also:
Condition

Field Summary
 
Fields inherited from class org.brains2b.data.Condition
m_cond, m_orderBy
 
Constructor Summary
SqlCondition()
          Default Constructor
SqlCondition(java.lang.String orderBy)
          Constructor for SqlCondition
SqlCondition(java.lang.String field, java.lang.Object value)
          Constructor for SqlCondition
SqlCondition(java.lang.String field, java.lang.Object value, java.lang.String orderBy)
          Constructor for SqlCondition
 
Method Summary
 void addCondition(java.lang.String field, java.lang.Object value)
          Implementation of addCondition which checks for null values and makes them absolute so the condition will have a condition FIELD IS NULL in the query.
 void addOrderBy(java.lang.String field, boolean descending)
          adds an Order By statement with the option to sort it descending
 void addParameter(int idx, int i)
          adds a integer value for the given placeholder position in the prepared statement.
 void addParameter(int idx, java.lang.Object o)
          adds a value for the given placeholder position in the prepared statement.
 java.lang.Object getCondition()
          abstract function left to specific datasource implementation to actually use condition and order by in a way the implementation does understand
 java.lang.String getPreparedQuery()
          get the SQL WHERE clause
 java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con, java.lang.String select)
          returns a prepared statement build from the prepared query set, the parameters added, the conditions set and the order by supplied.
 void setPreparedQuery(java.lang.String preparedQuery)
          set the SQL WHERE clause for this condition.
 
Methods inherited from class org.brains2b.data.Condition
addCondition, addCondition, addOrderBy, clearOrderBy, equals, getConditions, getOrderBy, removeCondition
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlCondition

public SqlCondition()
Default Constructor


SqlCondition

public SqlCondition(java.lang.String orderBy)
Constructor for SqlCondition


SqlCondition

public SqlCondition(java.lang.String field,
                    java.lang.Object value)
Constructor for SqlCondition


SqlCondition

public SqlCondition(java.lang.String field,
                    java.lang.Object value,
                    java.lang.String orderBy)
Constructor for SqlCondition

Method Detail

getCondition

public java.lang.Object getCondition()
Description copied from class: Condition
abstract function left to specific datasource implementation to actually use condition and order by in a way the implementation does understand

Specified by:
getCondition in class Condition
Returns:
Object, most general implementation.

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.sql.Connection con,
                                                       java.lang.String select)
                                                throws java.sql.SQLException
returns a prepared statement build from the prepared query set, the parameters added, the conditions set and the order by supplied.

If a prepared query has placeholders, the addParameters must be called for every placeholder supplied.

Parameters:
con - Connection, the connection for which to prepare the query
select - String, the select containing the fields to retrieve and the table

This should be a valid ANSI-SQL `SELECT` statement without any conditions.

Returns:
PreparedStatement, the PreparedStatement created for execution
Throws:
SQLException, - throws the Exception if generated by the prepareStatement command in java.sql.Connection()
java.sql.SQLException
See Also:
Connection, PreparedStatement

setPreparedQuery

public void setPreparedQuery(java.lang.String preparedQuery)
set the SQL WHERE clause for this condition. Could be used in conjunction with placeholder character ? to later set parameters to.

A prepared query is a query containing only the query for a table, with or without the "WHERE" keyword.

Parameters:
preparedQuery - The preparedQuery to set

getPreparedQuery

public java.lang.String getPreparedQuery()
get the SQL WHERE clause

Returns:
String, the query String generated from supplied condtions and prepared queries.

addParameter

public void addParameter(int idx,
                         java.lang.Object o)
adds a value for the given placeholder position in the prepared statement.

Parameters:
idx - int, the placeholder position
o - Object, the value to set in the prepared statement.

addParameter

public void addParameter(int idx,
                         int i)
adds a integer value for the given placeholder position in the prepared statement.

Parameters:
idx - int, the placeholder position
i - int, The value to set in the prepared statement

addCondition

public void addCondition(java.lang.String field,
                         java.lang.Object value)
Implementation of addCondition which checks for null values and makes them absolute so the condition will have a condition FIELD IS NULL in the query.

The normal addCondition(String, Object) does not do this by default and implementations can differ from data storage to data storage

converts java.util.Date to java.sql.Timestamp which is appropriate for Oracle

Overrides:
addCondition in class Condition
Parameters:
field - String, the identifier
value - Object, the value
See Also:
addCondition(String, Object)

addOrderBy

public void addOrderBy(java.lang.String field,
                       boolean descending)
adds an Order By statement with the option to sort it descending

Parameters:
field - String, the field name as it occurs in the table
descending - boolean, true if you want to sort descending.
Since:
DataC 0.23