Module bus.pager

Class OperationHandler<T>

java.lang.Object
org.miaixz.bus.mapper.handler.AbstractSqlHandler
org.miaixz.bus.pager.handler.SqlParserHandler
org.miaixz.bus.pager.handler.OperationHandler<T>
Type Parameters:
T - the generic type parameter
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Handler<T>, org.miaixz.bus.mapper.handler.MapperHandler<T>

public class OperationHandler<T> extends SqlParserHandler implements org.miaixz.bus.mapper.handler.MapperHandler<T>
Operation handler to prevent full table updates and deletes. This handler intercepts UPDATE and DELETE statements to ensure they have a valid WHERE clause, preventing accidental modification or deletion of all records in a table.
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 void
    checkWhere(String tableName, net.sf.jsqlparser.expression.Expression where, String ex)
    Checks if the WHERE clause is valid to prevent full table operations.
    void
    prepare(org.apache.ibatis.executor.statement.StatementHandler statementHandler)
    Prepares the SQL statement, checking UPDATE and DELETE statements for a WHERE clause to prevent full table operations.
    protected void
    processDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object obj)
    Processes a DELETE statement, checking if it includes a WHERE clause.
    protected void
    processUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object obj)
    Processes an UPDATE statement, checking if it includes a WHERE clause.

    Methods inherited from class org.miaixz.bus.pager.handler.SqlParserHandler

    parse, parserMulti, parserSingle, parseStatements, processInsert, processParser, processSelect, validateSql

    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, query, update
  • Constructor Details

    • OperationHandler

      public OperationHandler()
  • Method Details

    • prepare

      public void prepare(org.apache.ibatis.executor.statement.StatementHandler statementHandler)
      Prepares the SQL statement, checking UPDATE and DELETE statements for a WHERE clause to prevent full table operations.
      Specified by:
      prepare in interface org.miaixz.bus.mapper.handler.MapperHandler<T>
      Parameters:
      statementHandler - the MyBatis StatementHandler
    • processDelete

      protected void processDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object obj)
      Processes a DELETE statement, checking if it includes a WHERE clause.
      Overrides:
      processDelete in class SqlParserHandler
      Parameters:
      delete - the DELETE statement object
      index - the index of the statement
      sql - the original SQL statement
      obj - additional object
    • processUpdate

      protected void processUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object obj)
      Processes an UPDATE statement, checking if it includes a WHERE clause.
      Overrides:
      processUpdate in class SqlParserHandler
      Parameters:
      update - the UPDATE statement object
      index - the index of the statement
      sql - the original SQL statement
      obj - additional object
    • checkWhere

      protected void checkWhere(String tableName, net.sf.jsqlparser.expression.Expression where, String ex)
      Checks if the WHERE clause is valid to prevent full table operations.
      Parameters:
      tableName - the name of the table
      where - the WHERE clause expression
      ex - the exception message to throw if the check fails
      Throws:
      IllegalArgumentException - if the WHERE clause is invalid