Class SQLBetweenBaseClause
- java.lang.Object
-
- net.sf.jasperreports.engine.query.SQLBetweenBaseClause
-
- All Implemented Interfaces:
JRClauseFunction
- Direct Known Subclasses:
DateRangeSQLBetweenClause,JRSqlBetweenClause
public abstract class SQLBetweenBaseClause 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:
BETWEEN- in this case the A...B interval will be considered open: (A,B)[BETWEEN- in this case the A...B interval will be considered right-open: [A,B)BETWEEN]- in this case the A...B interval will be considered left-open: (A,B][BETWEEN]- in this case the A...B interval will be considered closed: [A,B]
- Author:
- Sanda Zaharia (shertage@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCLAUSE_TRUISMstatic java.lang.StringEXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_DB_COLUMN_TOKEN_MISSINGstatic java.lang.StringEXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_LEFT_PARAMETER_TOKEN_MISSINGstatic java.lang.StringEXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_NAME_TOKEN_MISSINGstatic java.lang.StringEXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_RIGHT_PARAMETER_TOKEN_MISSINGprotected static intPOSITION_CLAUSE_IDprotected static intPOSITION_DB_COLUMNprotected static intPOSITION_LEFT_PARAMETERprotected static intPOSITION_RIGHT_PARAMETER
-
Constructor Summary
Constructors Constructor Description SQLBetweenBaseClause()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidapply(JRClauseTokens clauseTokens, JRQueryClauseContext queryContext)Creates a BETWEEN-like SQL clause, depending on the clause ID.protected abstract ClauseFunctionParameterHandlercreateParameterHandler(JRQueryClauseContext queryContext, java.lang.String clauseId, java.lang.String parameterName, boolean left)protected java.lang.StringgetGreaterOperator(java.lang.String clauseId)protected java.lang.StringgetLessOperator(java.lang.String clauseId)protected voidhandleGreaterClause(java.lang.StringBuffer sbuffer, java.lang.String clauseId, java.lang.String col, ClauseFunctionParameterHandler leftParamHandler, JRQueryClauseContext queryContext)Generates either a 'column > ?' or a 'column >= ?' clauseprotected voidhandleLessClause(java.lang.StringBuffer sbuffer, java.lang.String clauseId, java.lang.String col, ClauseFunctionParameterHandler rightParamHandler, JRQueryClauseContext queryContext)Generates either a 'column < ?' or a 'column <= ?' clauseprotected booleanisLeftClosed(java.lang.String clauseId)protected booleanisRightClosed(java.lang.String clauseId)
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_DB_COLUMN_TOKEN_MISSING
public static final java.lang.String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_DB_COLUMN_TOKEN_MISSING
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_LEFT_PARAMETER_TOKEN_MISSING
public static final java.lang.String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_LEFT_PARAMETER_TOKEN_MISSING
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_NAME_TOKEN_MISSING
public static final java.lang.String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_NAME_TOKEN_MISSING
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_RIGHT_PARAMETER_TOKEN_MISSING
public static final java.lang.String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_RIGHT_PARAMETER_TOKEN_MISSING
- See Also:
- Constant Field Values
-
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
-
-
Method Detail
-
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 first token is the SQL column (or column combination) to be used in the clause.
- The second token is the name of the parameter that contains the left member value.
- The second token is the name of the parameter that contains the right member value.
The method constructs one of the following clauses:
(column > ? AND column < ?)if the clause ID isBETWEEN(column >= ? AND column < ?)if the clause ID is[BETWEEN(column > ? AND column <= ?)if the clause ID isBETWEEN](column >= ? AND column <= ?)if the clause ID is[BETWEEN]
column < ?if the clause ID isBETWEENorBETWEENcolumn <= ?if the clause ID isBETWEEN]or[BETWEEN]
column > ?if the clause ID isBETWEENorBETWEEN]column >= ?if the clause ID is[BETWEENor[BETWEEN]
0 = 0).- Specified by:
applyin interfaceJRClauseFunction- Parameters:
clauseTokens-queryContext-
-
createParameterHandler
protected abstract ClauseFunctionParameterHandler createParameterHandler(JRQueryClauseContext queryContext, java.lang.String clauseId, java.lang.String parameterName, boolean left)
-
getGreaterOperator
protected java.lang.String getGreaterOperator(java.lang.String clauseId)
- Parameters:
clauseId- the clause ID- Returns:
- the '
>' or '>=' sign
-
isLeftClosed
protected boolean isLeftClosed(java.lang.String clauseId)
-
getLessOperator
protected java.lang.String getLessOperator(java.lang.String clauseId)
- Parameters:
clauseId- the clause ID- Returns:
- the '
<' or '<=' sign
-
isRightClosed
protected boolean isRightClosed(java.lang.String clauseId)
-
handleGreaterClause
protected void handleGreaterClause(java.lang.StringBuffer sbuffer, java.lang.String clauseId, java.lang.String col, ClauseFunctionParameterHandler leftParamHandler, JRQueryClauseContext queryContext)Generates either a 'column > ?' or a 'column >= ?' clause- Parameters:
sbuffer- the StringBuffer that contains the generated queryclauseId- the clause IDcol- the name of the column, or a column names combinationleftParamHandler- the parameter handler that contains the left member valuequeryContext- the query context
-
handleLessClause
protected void handleLessClause(java.lang.StringBuffer sbuffer, java.lang.String clauseId, java.lang.String col, ClauseFunctionParameterHandler rightParamHandler, JRQueryClauseContext queryContext)Generates either a 'column < ?' or a 'column <= ?' clause- Parameters:
sbuffer- the StringBuffer that contains the generated queryclauseId- the clause IDcol- the name of the column, or a column names combinationrightParamHandler-queryContext- the query context
-
-