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 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 Details

    • EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_DB_COLUMN_TOKEN_MISSING

      public static final String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_DB_COLUMN_TOKEN_MISSING
      See Also:
    • EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_LEFT_PARAMETER_TOKEN_MISSING

      public static final String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_LEFT_PARAMETER_TOKEN_MISSING
      See Also:
    • EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_NAME_TOKEN_MISSING

      public static final String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_NAME_TOKEN_MISSING
      See Also:
    • EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_RIGHT_PARAMETER_TOKEN_MISSING

      public static final String EXCEPTION_MESSAGE_KEY_QUERY_BETWEEN_CLAUSE_RIGHT_PARAMETER_TOKEN_MISSING
      See Also:
    • POSITION_CLAUSE_ID

      protected static final int POSITION_CLAUSE_ID
      See Also:
    • POSITION_DB_COLUMN

      protected static final int POSITION_DB_COLUMN
      See Also:
    • POSITION_LEFT_PARAMETER

      protected static final int POSITION_LEFT_PARAMETER
      See Also:
    • POSITION_RIGHT_PARAMETER

      protected static final int POSITION_RIGHT_PARAMETER
      See Also:
  • Constructor Details

    • SQLBetweenBaseClause

      public SQLBetweenBaseClause()
  • Method Details

    • 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 is BETWEEN
      • (column >= ? AND column < ?) if the clause ID is [BETWEEN
      • (column > ? AND column <= ?) if the clause ID is BETWEEN]
      • (column >= ? AND column <= ?) if the clause ID is [BETWEEN]
      If the left member value is null, one of the following clauses will be generated:
      • column < ? if the clause ID is BETWEEN or BETWEEN
      • column <= ? if the clause ID is BETWEEN] or [BETWEEN]
      If the right member value is null, one of the following clauses will be generated:
      • column > ? if the clause ID is BETWEEN or BETWEEN]
      • column >= ? if the clause ID is [BETWEEN or [BETWEEN]
      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 -
    • createParameterHandler

      protected abstract ClauseFunctionParameterHandler createParameterHandler(JRQueryClauseContext queryContext, String clauseId, String parameterName, boolean left)
    • getGreaterOperator

      protected String getGreaterOperator(String clauseId)
      Parameters:
      clauseId - the clause ID
      Returns:
      the '>' or '>=' sign
    • isLeftClosed

      protected boolean isLeftClosed(String clauseId)
    • getLessOperator

      protected String getLessOperator(String clauseId)
      Parameters:
      clauseId - the clause ID
      Returns:
      the '<' or '<=' sign
    • isRightClosed

      protected boolean isRightClosed(String clauseId)
    • handleGreaterClause

      protected void handleGreaterClause(StringBuffer sbuffer, String clauseId, String col, ClauseFunctionParameterHandler leftParamHandler, 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
      leftParamHandler - the parameter handler that contains the left member value
      queryContext - the query context
    • handleLessClause

      protected void handleLessClause(StringBuffer sbuffer, String clauseId, String col, ClauseFunctionParameterHandler rightParamHandler, 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
      rightParamHandler -
      queryContext - the query context