org.apache.ibatis.executor.parameter.ParameterHandler Java Examples

The following examples show how to use org.apache.ibatis.executor.parameter.ParameterHandler. 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 vote down vote up
/**
 * 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: DynamicTableLanguageDriver.java    From tutorial with MIT License 5 votes vote down vote up
@Override
    public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object o, BoundSql boundSql) {
        logger.trace("createParameterHandler({}, Object: {}, BoundSql:{}", mappedStatement, o, boundSql.getSql());
        logger.trace("Object: class:{}, isMap:{}", o.getClass().getName(), o instanceof Map);
//        logger.trace("")
        logger.trace("boundSql: class: {}, sql: {}, getParameterMappings: {}, getParameterObject:{}",
                boundSql.getClass().getName(), boundSql.getSql(), boundSql.getParameterMappings(), boundSql.getParameterObject());
        return super.createParameterHandler(mappedStatement, o, boundSql);
    }
 
Example #3
Source File: DefaultResultSetHandler.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql,
    RowBounds rowBounds) {
  this.executor = executor;
  this.configuration = mappedStatement.getConfiguration();
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;
  this.parameterHandler = parameterHandler;
  this.boundSql = boundSql;
  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();
  this.resultHandler = resultHandler;
}
 
Example #4
Source File: DefaultResultSetHandler.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public DefaultResultSetHandler(Executor executor, MappedStatement mappedStatement, ParameterHandler parameterHandler, ResultHandler resultHandler, BoundSql boundSql,
    RowBounds rowBounds) {
  this.executor = executor;
  this.configuration = mappedStatement.getConfiguration();
  this.mappedStatement = mappedStatement;
  this.rowBounds = rowBounds;
  this.parameterHandler = parameterHandler;
  this.boundSql = boundSql;
  this.typeHandlerRegistry = configuration.getTypeHandlerRegistry();
  this.objectFactory = configuration.getObjectFactory();
  this.resultHandler = resultHandler;
}
 
Example #5
Source File: BindingLogPlugin32.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private List<String> getParameters(MappedStatement ms, Object parameterObject, BoundSql boundSql) throws SQLException {
    // DefaultParameterHandler is the only implementation of parameterHandler interface currently. it may be changed later.
    // need additional codes to find a appropriate implementation in that case.
    ParameterHandler parameterHandler = new DefaultParameterHandler(ms, parameterObject, boundSql);
    PreparedStatementParameterLogger parameterLogger = new PreparedStatementParameterLogger();
    parameterHandler.setParameters(parameterLogger);
    return parameterLogger.getParameters();
}
 
Example #6
Source File: VelocityLanguageDriver.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
  return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
Example #7
Source File: DefaultResultSetHandlerTest.java    From mybatis with Apache License 2.0 4 votes vote down vote up
/**
 * Contrary to the spec, some drivers require case-sensitive column names when getting result.
 * 
 * @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a>
 */
@Test
public void shouldRetainColumnNameCase() throws Exception {

  final Configuration config = new Configuration();
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final MappedStatement ms = new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps(
      new ArrayList<ResultMap>() {
        {
          add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() {
            {
              add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build());
            }
          }).build());
        }
      }).build();

  final Executor executor = null;
  final ParameterHandler parameterHandler = null;
  final ResultHandler resultHandler = null;
  final BoundSql boundSql = null;
  final RowBounds rowBounds = new RowBounds(0, 100);
  final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);

  when(stmt.getResultSet()).thenReturn(rs);
  when(rs.getMetaData()).thenReturn(rsmd);
  when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY);
  when(rs.next()).thenReturn(true).thenReturn(false);
  when(rs.getInt("CoLuMn1")).thenReturn(100);
  when(rs.wasNull()).thenReturn(false);
  when(rsmd.getColumnCount()).thenReturn(1);
  when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1");
  when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
  when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
  when(stmt.getConnection()).thenReturn(conn);
  when(conn.getMetaData()).thenReturn(dbmd);
  when(dbmd.supportsMultipleResultSets()).thenReturn(false); // for simplicity.

  final List<Object> results = fastResultSetHandler.handleResultSets(stmt);
  assertEquals(1, results.size());
  assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1"));
}
 
Example #8
Source File: VelocityLanguageDriver.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
  return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
Example #9
Source File: BaseStatementHandler.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public ParameterHandler getParameterHandler() {
  return parameterHandler;
}
 
Example #10
Source File: RoutingStatementHandler.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public ParameterHandler getParameterHandler() {
  return delegate.getParameterHandler();
}
 
Example #11
Source File: XMLLanguageDriver.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
 public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
   //返回默认的参数处理器
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
 }
 
Example #12
Source File: DefaultResultSetHandlerTest.java    From mybaties with Apache License 2.0 4 votes vote down vote up
/**
 * Contrary to the spec, some drivers require case-sensitive column names when getting result.
 * 
 * @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a>
 */
@Test
public void shouldRetainColumnNameCase() throws Exception {

  final Configuration config = new Configuration();
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final MappedStatement ms = new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps(
      new ArrayList<ResultMap>() {
        {
          add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() {
            {
              add(new ResultMapping.Builder(config, "cOlUmN1", "CoLuMn1", registry.getTypeHandler(Integer.class)).build());
            }
          }).build());
        }
      }).build();

  final Executor executor = null;
  final ParameterHandler parameterHandler = null;
  final ResultHandler resultHandler = null;
  final BoundSql boundSql = null;
  final RowBounds rowBounds = new RowBounds(0, 100);
  final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);

  when(stmt.getResultSet()).thenReturn(rs);
  when(rs.getMetaData()).thenReturn(rsmd);
  when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY);
  when(rs.next()).thenReturn(true).thenReturn(false);
  when(rs.getInt("CoLuMn1")).thenReturn(100);
  when(rs.wasNull()).thenReturn(false);
  when(rsmd.getColumnCount()).thenReturn(1);
  when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1");
  when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
  when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
  when(stmt.getConnection()).thenReturn(conn);
  when(conn.getMetaData()).thenReturn(dbmd);
  when(dbmd.supportsMultipleResultSets()).thenReturn(false); // for simplicity.

  final List<Object> results = fastResultSetHandler.handleResultSets(stmt);
  assertEquals(1, results.size());
  assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1"));
}
 
Example #13
Source File: CustomMybatisPlusScriptLanguageDriver.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
    return new CustomMybatisPlusParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
Example #14
Source File: BaseStatementHandler.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public ParameterHandler getParameterHandler() {
  return parameterHandler;
}
 
Example #15
Source File: RoutingStatementHandler.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public ParameterHandler getParameterHandler() {
  return delegate.getParameterHandler();
}
 
Example #16
Source File: XMLLanguageDriver.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
 public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
   //返回默认的参数处理器
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
 }
 
Example #17
Source File: CustomScriptLanguageDriver.java    From sqlhelper with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ParameterHandler createParameterHandler(final MappedStatement mappedStatement, final Object parameterObject, final BoundSql boundSql) {
    return new CustomMybatisParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
Example #18
Source File: LanguageDriver.java    From mybatis with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link ParameterHandler} that passes the actual parameters to the the JDBC statement.
 * 
 * @author Frank D. Martinez [mnesarco]
 * @see DefaultParameterHandler
 * @param mappedStatement The mapped statement that is being executed
 * @param parameterObject The input parameter object (can be null) 
 * @param boundSql The resulting SQL once the dynamic language has been executed.
 * @return
 */
//创建参数处理器
ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql);
 
Example #19
Source File: LanguageDriver.java    From mybaties with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link ParameterHandler} that passes the actual parameters to the the JDBC statement.
 * 
 * @author Frank D. Martinez [mnesarco]
 * @see DefaultParameterHandler
 * @param mappedStatement The mapped statement that is being executed
 * @param parameterObject The input parameter object (can be null) 
 * @param boundSql The resulting SQL once the dynamic language has been executed.
 * @return
 */
//创建参数处理器
ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql);
 
Example #20
Source File: PaginationInterceptor.java    From belling-admin with Apache License 2.0 2 votes vote down vote up
/**
 * 代入参数值
 * 
 * @param ps
 * @param mappedStatement
 * @param boundSql
 * @param parameterObject
 * @throws SQLException
 */
private void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql,
		Object parameterObject) throws SQLException {
	ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
	parameterHandler.setParameters(ps);
}
 
Example #21
Source File: StatementHandler.java    From mybaties with Apache License 2.0 votes vote down vote up
ParameterHandler getParameterHandler(); 
Example #22
Source File: StatementHandler.java    From mybatis with Apache License 2.0 votes vote down vote up
ParameterHandler getParameterHandler();