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 -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckWhere(String tableName, net.sf.jsqlparser.expression.Expression where, String ex) Checks if the WHERE clause is valid to prevent full table operations.voidprepare(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 voidprocessDelete(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 voidprocessUpdate(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, validateSqlMethods inherited from class org.miaixz.bus.mapper.handler.AbstractSqlHandler
getMappedStatement, getMappedStatement, getMetaObject, getSqlParserInfo, mapperBoundSql, mapperStatementHandler, realTarget, setAdditionalParameterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.core.Handler
after, before, setPropertiesMethods 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:
preparein interfaceorg.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:
processDeletein classSqlParserHandler- Parameters:
delete- the DELETE statement objectindex- the index of the statementsql- the original SQL statementobj- 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:
processUpdatein classSqlParserHandler- Parameters:
update- the UPDATE statement objectindex- the index of the statementsql- the original SQL statementobj- 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 tablewhere- the WHERE clause expressionex- the exception message to throw if the check fails- Throws:
IllegalArgumentException- if the WHERE clause is invalid
-