Closed qiaomengnan16 closed 6 months ago
Hello @qiaomengnan16 ,
If you do weird things in a plugin, unexpected things happen. I don't think this is something we need to fix.
Hello @harawata ,
In my business scenario, some data processing (such as encryption, data masking) is uniformly handled within the plugin, and then put it back into the parameters.
However, this led to a logging issue where old and new parameter values appeared together in the logs. If one does not carefully observe the new parameters that follow in the log, it might give the impression that the processing operation did not take effect, which could also potentially cause confusion for others.
Object getParameterObject = statementHandler.getStatementHandler().getParameterHandler().getParameterObject();
String password = ReflectUtils.getFieldValue("password", parameterObject);
password = Util.encryption(password);
ReflectUtils.setFieldValue("password", parameterObject, password);
statementHandler.getParameterHandler().setParameters((PreparedStatement) invocation.getArgs()[0]);
You can do whatever you want in your plugin, but you need to understand it is done at your own risk. We do not modify internal implementation just to make it compatible with your plugin.
I may not fully understand your requirements, but if you want to rewrite parameter properties, StatementHandler#query
probably is not the right place to do it.
If you post a question to the mailing list or stack overflow with the details about the requirements, someone might propose a better solution.
Closing as won't fix.
Hello @harawata ,
I've identified a more appropriate point for intercepting. The root cause of the issue stemmed from the repeated invocation of the StatementHandler.getParameterHandler().setParameters method.
To address this, I've adjusted the intercept point to modify parameters during the execution of the StatementHandler.parameterize method.
thank you.
MyBatis version
3.5.15
Database vendor and version
MYSQL 5.7.36
Test case or example project
This is the project link: https://github.com/qiaomengnan16/mybatis-log-bug
Steps to reproduce
I reset the parameter values in the ParameterIntercepts Plugin.
statementHandler.getParameterHandler().setParameters((PreparedStatement) invocation.getArgs()[0]);
However the parameter logging included both the old and new parameter values, which is the issue.
Expected result
Actual result