Module bus.pager

Class PermissionHandler

java.lang.Object
org.miaixz.bus.mapper.handler.AbstractSqlHandler
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Handler, org.miaixz.bus.mapper.handler.MapperHandler

public class PermissionHandler extends ConditionHandler implements org.miaixz.bus.mapper.handler.MapperHandler
Data permission handler for processing data permission controls in SQL statements. This handler dynamically adds permission conditions to SQL queries.
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
    net.sf.jsqlparser.expression.Expression
    buildTableExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String whereSegment)
    Builds a table-level permission expression.
    Retrieves the data permission provider.
    protected net.sf.jsqlparser.expression.Expression
    getUpdateOrDeleteExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String whereSegment)
    Retrieves the permission expression for an UPDATE or DELETE statement.
    void
    prepare(org.apache.ibatis.executor.statement.StatementHandler statementHandler)
    Pre-processes SQL statements, dynamically adding permission conditions to UPDATE and DELETE statements.
    protected void
    processDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object obj)
    Processes a DELETE statement, adding permission conditions.
    protected void
    processSelect(net.sf.jsqlparser.statement.select.Select select, int index, String sql, Object obj)
    Processes a SELECT statement, adding permission conditions.
    protected void
    processUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object obj)
    Processes an UPDATE statement, adding permission conditions.
    void
    query(Object result, org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement mappedStatement, Object parameter, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.session.ResultHandler resultHandler, org.apache.ibatis.mapping.BoundSql boundSql)
    Handles query processing, dynamically adding permission conditions to SELECT statements.
    void
    Sets the data permission provider.

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

    parse, parserMulti, parserSingle, parseStatements, processInsert, processParser, 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, update
  • Constructor Details

    • PermissionHandler

      public PermissionHandler()
  • Method Details

    • prepare

      public void prepare(org.apache.ibatis.executor.statement.StatementHandler statementHandler)
      Pre-processes SQL statements, dynamically adding permission conditions to UPDATE and DELETE statements.
      Specified by:
      prepare in interface org.miaixz.bus.mapper.handler.MapperHandler
      Parameters:
      statementHandler - the MyBatis StatementHandler
    • query

      public void query(Object result, org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement mappedStatement, Object parameter, org.apache.ibatis.session.RowBounds rowBounds, org.apache.ibatis.session.ResultHandler resultHandler, org.apache.ibatis.mapping.BoundSql boundSql)
      Handles query processing, dynamically adding permission conditions to SELECT statements.
      Specified by:
      query in interface org.miaixz.bus.mapper.handler.MapperHandler
      Parameters:
      result - the query result
      executor - the MyBatis executor
      mappedStatement - the MappedStatement
      parameter - the query parameters
      rowBounds - the pagination parameters
      resultHandler - the result handler
      boundSql - the bound SQL
    • processUpdate

      protected void processUpdate(net.sf.jsqlparser.statement.update.Update update, int index, String sql, Object obj)
      Processes an UPDATE statement, adding permission conditions.
      Overrides:
      processUpdate in class SqlParserHandler
      Parameters:
      update - the UPDATE statement object
      index - the SQL index
      sql - the original SQL
      obj - additional parameters (usually the mapping ID)
    • processDelete

      protected void processDelete(net.sf.jsqlparser.statement.delete.Delete delete, int index, String sql, Object obj)
      Processes a DELETE statement, adding permission conditions.
      Overrides:
      processDelete in class SqlParserHandler
      Parameters:
      delete - the DELETE statement object
      index - the SQL index
      sql - the original SQL
      obj - additional parameters (usually the mapping ID)
    • processSelect

      protected void processSelect(net.sf.jsqlparser.statement.select.Select select, int index, String sql, Object obj)
      Processes a SELECT statement, adding permission conditions.
      Overrides:
      processSelect in class SqlParserHandler
      Parameters:
      select - the SELECT statement object
      index - the SQL index
      sql - the original SQL
      obj - additional parameters (usually the mapping ID)
    • buildTableExpression

      public net.sf.jsqlparser.expression.Expression buildTableExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String whereSegment)
      Builds a table-level permission expression.
      Specified by:
      buildTableExpression in class ConditionHandler
      Parameters:
      table - the table object
      where - the original WHERE condition
      whereSegment - the permission condition segment
      Returns:
      the combined permission expression
    • getProvider

      public PermissionProvider getProvider()
      Retrieves the data permission provider.
      Returns:
      the data permission provider
    • setProvider

      public void setProvider(PermissionProvider provider)
      Sets the data permission provider.
      Parameters:
      provider - the data permission provider
    • getUpdateOrDeleteExpression

      protected net.sf.jsqlparser.expression.Expression getUpdateOrDeleteExpression(net.sf.jsqlparser.schema.Table table, net.sf.jsqlparser.expression.Expression where, String whereSegment)
      Retrieves the permission expression for an UPDATE or DELETE statement.
      Parameters:
      table - the table object
      where - the original WHERE condition
      whereSegment - the permission condition segment
      Returns:
      the combined permission expression