net.sf.jasperreports.engine.query
Class JRSqlBetweenClause

java.lang.Object
  extended by net.sf.jasperreports.engine.query.JRSqlBetweenClause
All Implemented Interfaces:
JRClauseFunction

public class JRSqlBetweenClause
extends java.lang.Object
implements JRClauseFunction

Base BETWEEN clause function for SQL queries.

The purpose of this clause function is to find that a given value can be found in a given A...B interval.

The first token in the $X{...} syntax is the function ID token. Possible values for the BETWEEN clause function ID token are:

Version:
$Id: JRSqlBetweenClause.java 5180 2012-03-29 13:23:12Z teodord $
Author:
sanda zaharia (shertage@users.sourceforge.net)

Field Summary
protected static java.lang.String CLAUSE_TRUISM
           
protected static int POSITION_CLAUSE_ID
           
protected static int POSITION_DB_COLUMN
           
protected static int POSITION_LEFT_PARAMETER
           
protected static int POSITION_RIGHT_PARAMETER
           
protected static JRSqlBetweenClause singleton
           
 
Constructor Summary
JRSqlBetweenClause()
           
 
Method Summary
 void apply(JRClauseTokens clauseTokens, JRQueryClauseContext queryContext)
          Creates a BETWEEN-like SQL clause, depending on the clause ID.
protected  java.lang.String getGreaterOperator(java.lang.String clauseId)
           
protected  java.lang.String getLessOperator(java.lang.String clauseId)
           
protected  void handleGreaterClause(java.lang.StringBuffer sbuffer, java.lang.String clauseId, java.lang.String col, java.lang.String leftParam, JRQueryClauseContext queryContext)
          Generates either a 'column > ?
protected  void handleLessClause(java.lang.StringBuffer sbuffer, java.lang.String clauseId, java.lang.String col, java.lang.String rightParam, JRQueryClauseContext queryContext)
          Generates either a 'column < ?
static JRSqlBetweenClause instance()
          Returns the singleton function instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSITION_CLAUSE_ID

protected static final int POSITION_CLAUSE_ID
See Also:
Constant Field Values

POSITION_DB_COLUMN

protected static final int POSITION_DB_COLUMN
See Also:
Constant Field Values

POSITION_LEFT_PARAMETER

protected static final int POSITION_LEFT_PARAMETER
See Also:
Constant Field Values

POSITION_RIGHT_PARAMETER

protected static final int POSITION_RIGHT_PARAMETER
See Also:
Constant Field Values

CLAUSE_TRUISM

protected static final java.lang.String CLAUSE_TRUISM
See Also:
Constant Field Values

singleton

protected static final JRSqlBetweenClause singleton
Constructor Detail

JRSqlBetweenClause

public JRSqlBetweenClause()
Method Detail

instance

public static JRSqlBetweenClause instance()
Returns the singleton function instance.

Returns:
the singleton function instance

apply

public void apply(JRClauseTokens clauseTokens,
                  JRQueryClauseContext queryContext)
Creates a BETWEEN-like SQL clause, depending on the clause ID.

The method expects three clause tokens (after the ID token):

The method constructs one of the following clauses:

If the left member value is null, one of the following clauses will be generated: If the right member value is null, one of the following clauses will be generated: If the both left and right member values are null, the method generates a SQL clause that will always evaluate to true (e.g. 0 = 0).

Specified by:
apply in interface JRClauseFunction
Parameters:
clauseTokens -
queryContext -

getGreaterOperator

protected java.lang.String getGreaterOperator(java.lang.String clauseId)
Parameters:
clauseId - the clause ID
Returns:
the '>' or '>=' sign

getLessOperator

protected java.lang.String getLessOperator(java.lang.String clauseId)
Parameters:
clauseId - the clause ID
Returns:
the '<' or '<=' sign

handleGreaterClause

protected void handleGreaterClause(java.lang.StringBuffer sbuffer,
                                   java.lang.String clauseId,
                                   java.lang.String col,
                                   java.lang.String leftParam,
                                   JRQueryClauseContext queryContext)
Generates either a 'column > ?' or a 'column >= ?' clause

Parameters:
sbuffer - the StringBuffer that contains the generated query
clauseId - the clause ID
col - the name of the column, or a column names combination
leftParam - the name of the parameter that contains the left member value
queryContext - the query context

handleLessClause

protected void handleLessClause(java.lang.StringBuffer sbuffer,
                                java.lang.String clauseId,
                                java.lang.String col,
                                java.lang.String rightParam,
                                JRQueryClauseContext queryContext)
Generates either a 'column < ?' or a 'column <= ?' clause

Parameters:
sbuffer - the StringBuffer that contains the generated query
clauseId - the clause ID
col - the name of the column, or a column names combination
rightParam - the name of the parameter that contains the right member value
queryContext - the query context


© 2001-2010 Jaspersoft Corporation www.jaspersoft.com