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 You received this message because you are subscribed to the Google Groups "mybatis-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/18227fa5-3400-4c84-b327-5ee0969343d9%40googlegroups.com. |
You don't mention which DBMS you are using, or what kind of logic you need to apply. One approach I've used with Oracle was to employ an anonymous procedure block within the mapper SQL. This approach is of course limited to the capabilities of the stored procedure implementation, but for simple needs works well and is simple to implement.
--
Guy Rouillier On 5/21/2020 3:19:10 PM, "Francisco Herrera" <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "mybatis-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/emd878a6c4-def0-478b-9e95-13af2e531944%40asus. |
Hi Guy, We use Oracle, and the ad-hoc logic is as follows. For all SQL/queries the system needs to: 1) Find if the SQL/query has variables with a special format $variable_X$ 2) If so, run a special SQL/query that will establish some context on the DB side, and will return values to be passed for those $variable_X$ variables 3) Then, run the original SQL with the values fetched above for the $variable_X$ variables 4) And finally, run a final SQL/query to clean the context on DB side The Mybatis plugin seems to be doing the job, but we are not sure if a plugin has any cons for this kind of logic described. Any ideas ? Francisco
You received this message because you are subscribed to the Google Groups "mybatis-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/32e1dc11-f9ac-4853-bc2a-a8a4d2fb6bd4%40googlegroups.com. |
Free forum by Nabble | Edit this page |