当前位置: 首页>>代码示例>>Java>>正文


Java Invocation.proceed方法代码示例

本文整理汇总了Java中org.apache.ibatis.plugin.Invocation.proceed方法的典型用法代码示例。如果您正苦于以下问题:Java Invocation.proceed方法的具体用法?Java Invocation.proceed怎么用?Java Invocation.proceed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.ibatis.plugin.Invocation的用法示例。


在下文中一共展示了Invocation.proceed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
    /**
     * 处理 DELETE UPDATE 语句
     */
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
        Executor executor = (Executor) invocation.getTarget();
        Configuration configuration = ms.getConfiguration();
        Object parameter = invocation.getArgs()[1];
        BoundSql boundSql = ms.getBoundSql(parameter);
        Connection connection = executor.getTransaction().getConnection();
        String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
        if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
                && VersionUtils.compare(minMySQLVersion, databaseVersion)) {
            logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
            return invocation.proceed();
        }
        /**
         * 执行 SQL 分析
         */
        sqlExplain(configuration, ms, boundSql, connection, parameter);
    }
    return invocation.proceed();
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:25,代码来源:SqlExplainInterceptor.java

示例2: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
	StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");
	BoundSql boundSql = delegate.getBoundSql();
	Object obj = boundSql.getParameterObject();
	Page page = seekPage(obj);
	if (page != null) {
		MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");
		Connection connection = (Connection) invocation.getArgs()[0];
		String sql = boundSql.getSql();
		this.setTotalRecord(page, mappedStatement, connection);
		String pageSql = this.getPageSql(page, sql);
		ReflectUtil.setFieldValue(boundSql, "sql", pageSql);
	}
	return invocation.proceed();
}
 
开发者ID:lemon-china,项目名称:lemon-mybatis-plus,代码行数:18,代码来源:PageInterceptor.java

示例3: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	// TODO Auto-generated method stub
	if (invocation.getTarget() instanceof RoutingStatementHandler) {
		StatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
		MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
		MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
		String mapperId = mappedStatement.getId();
		String mapperClassName = mapperId.substring(0, mapperId.lastIndexOf("."));
		Class<?> mapperClass = Class.forName(mapperClassName);
		if (isDaoMapper(mapperClass)&&mapperId.endsWith(".insertUseReturnGeneratedKeys")) {
			BaseStatementHandler baseStatementHandler = (BaseStatementHandler) metaStatementHandler.getValue("delegate");
			if ("query".equals(invocation.getMethod().getName())) {
				return handPreparedStatementHandlerQuery(invocation, baseStatementHandler);
			} else if ("prepare".equals(invocation.getMethod().getName())) {
				return handPreparedStatementHandlerPrepare(invocation, baseStatementHandler);
			}
		}
	}
	return invocation.proceed();
}
 
开发者ID:wulizhong,项目名称:mybatis-dao,代码行数:22,代码来源:DaoPlugin.java

示例4: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
/**
 * 拦截后要执行的方法
 */
@Override
public Object intercept(Invocation invocation) throws Throwable {
    Page<?> page = PageThreadLocal.getThreadLocalPage();
    if (page == null) {
        return invocation.proceed();
    }
    PageThreadLocal.removeThreadLocalPage();
    RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
    // 通过反射获取到当前RoutingStatementHandler对象的delegate属性
    StatementHandler delegate = (StatementHandler) ReflectUtil.getFieldValue(handler, "delegate");
    BoundSql boundSql = delegate.getBoundSql();
    MappedStatement mappedStatement = (MappedStatement) ReflectUtil.getFieldValue(delegate, "mappedStatement");
    // 获取当前要执行的Sql语句,也就是我们直接在Mapper映射语句中写的Sql语句
    String sql = boundSql.getSql();
    // 是否查询总页数和总数据 默认为TRUE
    if (page.getTotalFlag()) {
        // 给当前的page参数对象设置总记录数
        this.setTotalRecord(page, mappedStatement, boundSql, sql);
    }

    String pageSql = this.getPageSql(sql, page);
    // 利用反射设置当前BoundSql对应的sql属性为我们建立好的分页Sql语句
    ReflectUtil.setFieldValue(boundSql, "sql", pageSql);
    return invocation.proceed();
}
 
开发者ID:tonyruiyu,项目名称:dubbo-mock,代码行数:29,代码来源:PageInterceptor.java

示例5: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {

    boolean synchronizationActive = TransactionSynchronizationManager.isSynchronizationActive();
    //如果没有事务
    if (!synchronizationActive) {
        Object[] objects = invocation.getArgs();
        MappedStatement ms = (MappedStatement) objects[0];

        DynamicDataSourceGlobal dynamicDataSourceGlobal;

        if ((dynamicDataSourceGlobal = CACHE_MAP.get(ms.getId())) == null) {
            dynamicDataSourceGlobal = getDynamicDataSource(ms, objects[1]);
            LOGGER.warn("设置方法[{}] use [{}] Strategy, SqlCommandType [{}]..", ms.getId(), dynamicDataSourceGlobal.name(), ms.getSqlCommandType().name());
            CACHE_MAP.put(ms.getId(), dynamicDataSourceGlobal);
        }
        DynamicDataSourceHolder.putDataSource(dynamicDataSourceGlobal);
    }

    return invocation.proceed();
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:22,代码来源:DynamicPlugin.java

示例6: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	StatementHandler statementHandler = (StatementHandler) invocation.getTarget(); 
	if(statementHandler instanceof RoutingStatementHandler){
		RoutingStatementHandler routeStatementHandler = (RoutingStatementHandler)statementHandler;
		MetaObject metaObject = SystemMetaObject.forObject(routeStatementHandler);
		int offset = Integer.valueOf(String.valueOf(metaObject.getValue("delegate.rowBounds.offset")));
		int limit = Integer.valueOf(String.valueOf(metaObject.getValue("delegate.rowBounds.limit")));
		if(offset == RowBounds.NO_ROW_OFFSET && limit == RowBounds.NO_ROW_LIMIT){
			return invocation.proceed();
		}
		String sql = String.valueOf(metaObject.getValue("delegate.boundSql.sql")).trim();
		if(StringUtils.isBlank(sql) || !sql.toLowerCase().startsWith("select")){
			return invocation.proceed();
		}
		String pagedSql = this.buildPagedSql(sql, offset, limit);
		metaObject.setValue("delegate.boundSql.sql", pagedSql);
		metaObject.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
		metaObject.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
	}else{
		return invocation.proceed(); 
	}
	return invocation.proceed();
}
 
开发者ID:ls960972314,项目名称:report,代码行数:25,代码来源:MybatisPagedInterceptor.java

示例7: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
	StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
	MappedStatement mappedStatement = null;
	if (statementHandler instanceof RoutingStatementHandler) {
		StatementHandler delegate = (StatementHandler) ReflectionUtils.getFieldValue(statementHandler, "delegate");
		mappedStatement = (MappedStatement) ReflectionUtils.getFieldValue(delegate, "mappedStatement");
	} else {
		mappedStatement = (MappedStatement) ReflectionUtils.getFieldValue(statementHandler, "mappedStatement");
	}
	Object parm = statementHandler.getParameterHandler().getParameterObject();
	String sql = statementHandler.getBoundSql().getSql();
	String mapperId = mappedStatement.getId();
	if (ShardHolder.getInstance().hasShard(mapperId)) {
		ShardObject shardObject = ShardHolder.getInstance().getShardObject(mapperId);
		String targetSql = ShardParser.getInstance().parse(sql, parm, shardObject);
		if (!sql.equals(targetSql)) {
			ReflectionUtils.setFieldValue(statementHandler.getBoundSql(), "sql", targetSql);
		}
	}
	return invocation.proceed();
}
 
开发者ID:PowerBin,项目名称:sharding-mybatis,代码行数:22,代码来源:ShardPlugin.java

示例8: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
    /**
     * 处理 DELETE UPDATE 语句
     */
    MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
    if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
        Executor executor = (Executor) invocation.getTarget();
        Configuration configuration = ms.getConfiguration();
        Object parameter = invocation.getArgs()[1];
        BoundSql boundSql = ms.getBoundSql(parameter);
        Connection connection = executor.getTransaction().getConnection();
        String databaseVersion = connection.getMetaData().getDatabaseProductVersion();
        if (GlobalConfigUtils.getDbType(configuration).equals(DBType.MYSQL)
                && VersionUtils.compare(minMySQLVersion, databaseVersion)) {
            logger.warn("Warn: Your mysql version needs to be greater than '5.6.3' to execute of Sql Explain!");
            return invocation.proceed();
        }
        /**
         * 执行 SQL 分析
         */
        sqlExplain(configuration, ms, boundSql, connection, parameter);
    }
    return invocation.proceed();
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:26,代码来源:SqlExplainInterceptor.java

示例9: queryCount

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
private Object queryCount(Invocation invocation, Object[] args, MappedStatement ms, BoundSql boundSql)
		throws InvocationTargetException, IllegalAccessException {
	MappedStatement countRowStatement = COUNT_MAPPED_STATS.get(ms.getId());

	if (countRowStatement == null) {
		String countSql = dialect.getCountSql(boundSql.getSql());
		BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(),
				boundSql.getParameterObject());
		MetaObject mo = (MetaObject) ReflectionUtils.getFieldValue(boundSql, "metaParameters");
		ReflectionUtils.setFieldValue(newBoundSql, "metaParameters", mo);
		List<ResultMap> resultMaps = new ArrayList<ResultMap>();
		ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), int.class,
				EMPTY_RESULTMAPPING).build();
		resultMaps.add(resultMap);
		countRowStatement = buildMappedStatement(ms, new SqlSourceWrapper(newBoundSql), ms.getId() + "_COUNT",
				resultMaps);
	}

	args[0] = countRowStatement;
	args[2] = new RowBounds();
	args[3] = null;

	return invocation.proceed();
}
 
开发者ID:dianping,项目名称:zebra,代码行数:25,代码来源:PageInterceptor.java

示例10: _processPage

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
/**
 * Mybatis拦截器方法
 *
 * @param invocation 拦截器入参
 * @return 返回执行结果
 * @throws Throwable 抛出异常
 */
private Object _processPage(Invocation invocation) throws Throwable {
    final Object[] args = invocation.getArgs();
    Page page = null;
    //支持方法参数时,会先尝试获取Page
    if (supportMethodsArguments) {
        page = getPage(args);
    }
    //分页信息
    RowBounds rowBounds = (RowBounds) args[2];
    //支持方法参数时,如果page == null就说明没有分页条件,不需要分页查询
    if ((supportMethodsArguments && page == null)
            //当不支持分页参数时,判断LocalPage和RowBounds判断是否需要分页
            || (!supportMethodsArguments && SqlUtil.getLocalPage() == null && rowBounds == RowBounds.DEFAULT)) {
        return invocation.proceed();
    } else {
        //不支持分页参数时,page==null,这里需要获取
        if (!supportMethodsArguments && page == null) {
            page = getPage(args);
        }
        return doProcessPage(invocation, page, args);
    }
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:30,代码来源:SqlUtil.java

示例11: doQueryOnly

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
/**
 * 只做查询
 *
 * @param page
 * @param invocation
 * @return
 * @throws Throwable
 */
private Page doQueryOnly(Page page, Invocation invocation) throws Throwable {
    page.setCountSignal(null);
    //执行正常(不分页)查询
    Object result = invocation.proceed();
    //得到处理结果
    page.addAll((List) result);
    //相当于查询第一页
    page.setPageNum(1);
    //这种情况相当于pageSize=total
    page.setPageSize(page.size());
    //仍然要设置total
    page.setTotal(page.size());
    //返回结果仍然为Page类型 - 便于后面对接收类型的统一处理
    return page;
}
 
开发者ID:xushaomin,项目名称:apple-orm,代码行数:24,代码来源:SqlUtil.java

示例12: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
	Pagination pagination = getPaginationParamter(invocation);
	if (pagination == null) {
		return invocation.proceed();
	}
	BoundSql boundSql = handler.getBoundSql();
	// 获取分页sql,从hibernate拷贝而来(mysql/oracle/db2/h2/sqlserver)
	String sql = dialect.getLimitString(boundSql.getSql(), pagination);
	try {
		Field sqlField = boundSql.getClass().getDeclaredField("sql");
		if (sqlField != null) {
			sqlField.setAccessible(true);
			sqlField.set(boundSql, sql);
		}
	} catch (Exception e) {
		logger.error(e);
	}
	return invocation.proceed();
}
 
开发者ID:songkun,项目名称:spring-mybatis-jquery-2,代码行数:22,代码来源:PaginationIntercepter.java

示例13: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
    StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
    MappedStatement mappedStatement = null;
    if (statementHandler instanceof RoutingStatementHandler) {
        StatementHandler delegate = (StatementHandler) ReflectionUtils.getFieldValue(statementHandler, "delegate");
        mappedStatement = (MappedStatement) ReflectionUtils.getFieldValue(delegate, "mappedStatement");
    } else {
        mappedStatement = (MappedStatement) ReflectionUtils.getFieldValue(statementHandler, "mappedStatement");
    }

    String mapperId = mappedStatement.getId();
    Object params = statementHandler.getBoundSql().getParameterObject();

    handleTableName(mapperId, statementHandler, params);
    handleDataSource(mapperId);

    try {
        return invocation.proceed();
    } finally {
        DataSourceContextHolder.clearDataSourceName();
    }
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:24,代码来源:Interceptor4DB.java

示例14: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	Object[] args = invocation.getArgs();
	
	// no paging
	if(!isPaging(args)){
		return invocation.proceed();
	}

	// process for paging
	InvocationContext context = getInvocationContext(invocation);
	InvocationContext newContext = processIntercept(context);

	swapParameter(newContext, args);
	Object result = invocation.proceed();
	
	if(result != null && result instanceof List){
		newContext.getPagination().setRecords((List<?>)result);
	}
	
	return result;
}
 
开发者ID:leopardoooo,项目名称:easyooo-framework,代码行数:23,代码来源:PaginationPlugin.java

示例15: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation ivk) throws Throwable {
	if (ivk.getTarget().getClass()
			.isAssignableFrom(RoutingStatementHandler.class)) {
		final RoutingStatementHandler statementHandler = (RoutingStatementHandler) ivk
				.getTarget();
		final BaseStatementHandler delegate = (BaseStatementHandler) Reflection
				.getFieldValue(statementHandler, DELEGATE);
		final MappedStatement mappedStatement = (MappedStatement) Reflection
				.getFieldValue(delegate, MAPPED_STATEMENT);

		if (mappedStatement.getId().matches(SQL_PATTERN)) {
			// 拦截需要分页的SQL
			BoundSql boundSql = delegate.getBoundSql();
			// 分页SQL<select>中parameterType属性对应的实体参数,即Mapper接口中执行分页方法的参数,该参数不得为空
			Object parameterObject = boundSql.getParameterObject();
			if (null == parameterObject) {
				throw new NullPointerException("parameterObject尚未实例化!");
			} else {
				final Connection connection = (Connection) ivk.getArgs()[0];
				final String sql = boundSql.getSql();
				// 记录统计
				final int count = BaseParameter
						.getCount(sql, connection, mappedStatement,
								parameterObject, boundSql, DIALECT);
				Page page = null;
				page = convertParameter(parameterObject, page);
				page.init(count, page.getSize(), page.getLimit());
				String pagingSql = BaseParameter.generatePageSql(sql, page,
						DIALECT);
				// 将分页sql语句反射回BoundSql.
				Reflection.setFieldValue(boundSql, "sql", pagingSql);
			}
		}
	}
	return ivk.proceed();
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:38,代码来源:PreparePaginationInterceptor.java


注:本文中的org.apache.ibatis.plugin.Invocation.proceed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。