org.apache.ibatis.executor.resultset.DefaultResultSetHandler Java Examples
The following examples show how to use
org.apache.ibatis.executor.resultset.DefaultResultSetHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapInterceptor.java From scaffold-cloud with MIT License | 5 votes |
/** * TODO: * @param invocation * @return * @throws Throwable * @author zjh * @date 2017-2-15 */ @Override public Object intercept(Invocation invocation) throws Throwable { //通过invocation获取代理的目标对象 Object target = invocation.getTarget(); //暂时ResultSetHandler只有FastResultSetHandler这一种实现 if (target instanceof DefaultResultSetHandler) { DefaultResultSetHandler resultSetHandler = (DefaultResultSetHandler) target; //利用反射获取到FastResultSetHandler的ParameterHandler属性,从而获取到ParameterObject; ParameterHandler parameterHandler = (ParameterHandler) ReflectUtil.getFieldValue(resultSetHandler, "parameterHandler"); Object parameterObj = parameterHandler.getParameterObject(); //判断ParameterObj是否是我们定义的MapParam,如果是则进行自己的处理逻辑 if (parameterObj instanceof MapParam) {//拦截到了 MapParam mapParam = (MapParam) parameterObj; //获取到当前的Statement Statement stmt = (Statement) invocation.getArgs()[0]; //通过Statement获取到当前的结果集,对其进行处理,并返回对应的处理结果 return handleResultSet(stmt.getResultSet(), mapParam); } } //如果没有进行拦截处理,则执行默认逻辑 return invocation.proceed(); }
Example #2
Source File: ResultTypePlugin.java From mybatis-jpa with Apache License 2.0 | 4 votes |
@Override public Object intercept(Invocation invocation) throws Throwable { if (invocation.getTarget() instanceof DefaultResultSetHandler) { DefaultResultSetHandler resultSetHandler = (DefaultResultSetHandler) invocation.getTarget(); Object[] args = invocation.getArgs(); Statement stmt = (Statement) args[0]; MappedStatement mappedStatement = (MappedStatement) FieldReflectUtil .getFieldValue(resultSetHandler, "mappedStatement"); List<ResultMap> resultMaps = mappedStatement.getResultMaps(); if (resultMaps != null && !resultMaps.isEmpty()) { ResultMap resultMap = resultMaps.get(0); if (resultMap.getResultMappings() == null || resultMap.getResultMappings().isEmpty()) { if (resultMap.getType().isAnnotationPresent(Entity.class) || resultMap.getType() .isAnnotationPresent(Table.class)) { ResultMapParser parser = ResultMapParserHolder .getInstance(mappedStatement.getConfiguration()); ResultMap newResultMap = parser .reloadResultMap(mappedStatement.getResource(), resultMap.getId(), resultMap.getType()); List<ResultMap> newResultMaps = new ArrayList<>(); newResultMaps.add(newResultMap); FieldReflectUtil.setFieldValue(mappedStatement, "resultMaps", newResultMaps); // modify the resultMaps FieldReflectUtil.setFieldValue(resultSetHandler, "mappedStatement", mappedStatement); } } } // return resultSetHandler.handleResultSets(stmt); } return invocation.proceed(); }