Module bus.pager

Class ConditionHandler

java.lang.Object
org.miaixz.bus.mapper.handler.AbstractSqlHandler
org.miaixz.bus.pager.handler.SqlParserHandler
org.miaixz.bus.pager.handler.ConditionHandler
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Handler, org.miaixz.bus.mapper.handler.MapperHandler
Direct Known Subclasses:
PermissionHandler, TenantHandler

public abstract class ConditionHandler extends SqlParserHandler implements org.miaixz.bus.mapper.handler.MapperHandler
Base class for handling multi-table conditions. Provides methods for processing SELECT, UPDATE, and DELETE statements and appending conditions based on table metadata.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Summary

    Fields inherited from class org.miaixz.bus.mapper.handler.AbstractSqlHandler

    DEFAULT_REFLECTOR_FACTORY, DELEGATE_BOUNDSQL, DELEGATE_BOUNDSQL_SQL, DELEGATE_MAPPEDSTATEMENT, MAPPEDSTATEMENT
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected net.sf.jsqlparser.expression.Expression
    andExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String whereSegment)
    Handles the WHERE conditions for DELETE and UPDATE statements.
    protected net.sf.jsqlparser.expression.Expression
    appendExpression(net.sf.jsqlparser.expression.Expression expression, net.sf.jsqlparser.expression.Expression injectExpression)
    Appends a conditional expression.
    protected net.sf.jsqlparser.expression.Expression
    builderExpression(net.sf.jsqlparser.expression.Expression expression, List<net.sf.jsqlparser.schema.Table> tables, String segment)
    Builds and processes a conditional expression.
    abstract net.sf.jsqlparser.expression.Expression
    buildTableExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String segment)
    Builds the query condition for a database table.
    protected void
    processFunction(net.sf.jsqlparser.expression.Function function, String whereSegment)
    Processes a function, supporting `select fun(args..)` and nested functions `select fun1(fun2(args..),args..)`.
    protected void
    processOtherFromItem(net.sf.jsqlparser.statement.select.FromItem fromItem, String whereSegment)
    Processes other FROM items (e.g., subqueries).
    protected void
    processPlainSelect(net.sf.jsqlparser.statement.select.PlainSelect plainSelect, String whereSegment)
    Processes a PlainSelect statement, including its SELECT items, FROM item, and JOINs.
    protected void
    processSelectBody(net.sf.jsqlparser.statement.select.Select selectBody, String whereSegment)
    Processes the body of a SELECT statement, applying the specified condition segment.
    protected void
    processSelectItem(net.sf.jsqlparser.statement.select.SelectItem selectItem, String whereSegment)
    Processes subqueries or functions in a SELECT item.
    protected void
    processWhereSubSelect(net.sf.jsqlparser.expression.Expression where, String whereSegment)
    Processes subqueries in the WHERE clause, supporting IN, =, >, <, >=, <=, <>, EXISTS, NOT EXISTS.

    Methods inherited from class org.miaixz.bus.mapper.handler.AbstractSqlHandler

    getMappedStatement, getMappedStatement, getMetaObject, getSqlParserInfo, mapperBoundSql, mapperStatementHandler, realTarget, setAdditionalParameter

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.miaixz.bus.core.Handler

    after, before, setProperties

    Methods inherited from interface org.miaixz.bus.mapper.handler.MapperHandler

    getBoundSql, isQuery, isUpdate, prepare, query, update
  • Constructor Details

    • ConditionHandler

      public ConditionHandler()
  • Method Details

    • processSelectBody

      protected void processSelectBody(net.sf.jsqlparser.statement.select.Select selectBody, String whereSegment)
      Processes the body of a SELECT statement, applying the specified condition segment.
      Parameters:
      selectBody - the body of the SELECT statement
      whereSegment - the full Mapper path, used for applying conditions
    • andExpression

      protected net.sf.jsqlparser.expression.Expression andExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String whereSegment)
      Handles the WHERE conditions for DELETE and UPDATE statements.
      Parameters:
      table - the Table object
      where - the current WHERE condition
      whereSegment - the full Mapper path
      Returns:
      the appended WHERE expression
    • processPlainSelect

      protected void processPlainSelect(net.sf.jsqlparser.statement.select.PlainSelect plainSelect, String whereSegment)
      Processes a PlainSelect statement, including its SELECT items, FROM item, and JOINs.
      Parameters:
      plainSelect - the PlainSelect object
      whereSegment - the full Mapper path
    • processWhereSubSelect

      protected void processWhereSubSelect(net.sf.jsqlparser.expression.Expression where, String whereSegment)
      Processes subqueries in the WHERE clause, supporting IN, =, >, <, >=, <=, <>, EXISTS, NOT EXISTS. Prerequisite: Subqueries must be in parentheses and usually on the right side of a comparison operator.
      Parameters:
      where - the WHERE condition
      whereSegment - the full Mapper path
    • processSelectItem

      protected void processSelectItem(net.sf.jsqlparser.statement.select.SelectItem selectItem, String whereSegment)
      Processes subqueries or functions in a SELECT item.
      Parameters:
      selectItem - the SELECT item
      whereSegment - the full Mapper path
    • processFunction

      protected void processFunction(net.sf.jsqlparser.expression.Function function, String whereSegment)
      Processes a function, supporting `select fun(args..)` and nested functions `select fun1(fun2(args..),args..)`.
      Parameters:
      function - the function expression
      whereSegment - the full Mapper path
    • processOtherFromItem

      protected void processOtherFromItem(net.sf.jsqlparser.statement.select.FromItem fromItem, String whereSegment)
      Processes other FROM items (e.g., subqueries).
      Parameters:
      fromItem - the item in the FROM clause
      whereSegment - the full Mapper path
    • builderExpression

      protected net.sf.jsqlparser.expression.Expression builderExpression(net.sf.jsqlparser.expression.Expression expression, List<net.sf.jsqlparser.schema.Table> tables, String segment)
      Builds and processes a conditional expression.
      Parameters:
      expression - the current conditional expression
      tables - the list of tables
      segment - the full Mapper path
      Returns:
      the constructed conditional expression
    • appendExpression

      protected net.sf.jsqlparser.expression.Expression appendExpression(net.sf.jsqlparser.expression.Expression expression, net.sf.jsqlparser.expression.Expression injectExpression)
      Appends a conditional expression. By default, it appends to the end, but the position can be configured via `appendMode`.
      Parameters:
      expression - the original SQL conditional expression
      injectExpression - the conditional expression to be injected
      Returns:
      the complete appended expression (for WHERE or ON clauses)
    • buildTableExpression

      public abstract net.sf.jsqlparser.expression.Expression buildTableExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String segment)
      Builds the query condition for a database table.
      Parameters:
      table - the Table object
      where - the current WHERE condition
      segment - the full Mapper path
      Returns:
      the new query condition to be added (does not overwrite the original WHERE, only appends). Returns null if no new condition is added.