Hi, we need to port some old functionality from Ibatis into Mybatis, in which some logic is inserted before and after the execution of a query. We want to assess what would be a better approach from this two (or any other?):
a) Using a Mybatis plugin such as:
@Intercepts( {
@Signature(type = Executor.class
, method = "query"
, args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class})
public class MyNewQueryInterceptor implements Interceptor {
b) Extending SqlSession such as:
public class MyNewSqlMapClientTemplate extends SqlSessionTemplate { <-- We are using Spring Mybatis
To give some context, on the old Ibatis, the code used to look like:
@Override
public Object queryForObject(String statementName, Object parameterObject)
throws DataAccessException {
return execute(new ScopedSqlMapClientCallback(statementName, parameterObject,
new ExtendedSqlMapClientCallback() {
@Override
public Object callback(SqlMapExecutor executor, String statementName, Object params)
throws SQLException {
return executor.queryForObject(statementName, params);
}
}));
}
Thanks,
Francisco