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


Java Invocation.getArgs方法代码示例

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


在下文中一共展示了Invocation.getArgs方法的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: onInterceptor

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

    Object[] objects = invocation.getArgs();
    MappedStatement ms = (MappedStatement) objects[0];
    //已指定强制使用
    if (DataSourceContextHolder.get().isForceUseMaster()) {
        logger.debug("Method[{}] force use Master..", ms.getId());
        return null;
    }

    //读方法
    if (ms.getSqlCommandType().equals(SqlCommandType.SELECT)) {
        //!selectKey 为自增id查询主键(SELECT LAST_INSERT_ID() )方法,使用主库
        if (!ms.getId().contains(SelectKeyGenerator.SELECT_KEY_SUFFIX)) {
            DataSourceContextHolder.get().useSlave(true);
            logger.debug("Method[{} use Slave Strategy..", ms.getId());
        }
    } else {
        logger.debug("Method[{}] use Master Strategy..", ms.getId());
        DataSourceContextHolder.get().useSlave(false);
    }

    return null;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:26,代码来源:RwRouteHandler.java

示例3: 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

示例4: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object intercept(Invocation invocation) throws Throwable {
	Object object=invocation.getArgs()[0];
	if(object instanceof MappedStatement){
		MappedStatement  statement=(MappedStatement) object;
		Configuration config = statement.getConfiguration();
		DataSource dataSource= config.getEnvironment().getDataSource();
		if(dataSource instanceof DynamicDataSource){
			DynamicDataSource dynamicDataSource=((DynamicDataSource)dataSource); 
			Dialect dialect= dynamicDataSource.getDialect();
			if(pageHelpers.containsKey(dialect)){
				log.debug("将使用{}的PageHelper....",dialect);
				return pageHelpers.get(dialect).intercept(invocation);
			}else{
				log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
			}
		}else{
			log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
		}
	}else{
		log.debug("将使用默认的PageHelper,dialect=({})的....",this.dialect);
	}
	return pageHelper.intercept(invocation);
}
 
开发者ID:halober,项目名称:spring-boot-starter-dao,代码行数:25,代码来源:CustomPageInterceptor.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 {
    /**
     * 处理 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

示例7: onInterceptor

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
@Override
public Object onInterceptor(Invocation invocation) throws Throwable {
	
	Object[] objects = invocation.getArgs();
	MappedStatement ms = (MappedStatement) objects[0];
	//已指定强制使用
	if(DataSourceContextHolder.get().isForceUseMaster()){
		logger.debug("Method[{}] force use Master..",ms.getId());
		return null;
	}
	
	//读方法
	if(ms.getSqlCommandType().equals(SqlCommandType.SELECT)){
		//!selectKey 为自增id查询主键(SELECT LAST_INSERT_ID() )方法,使用主库
		if(!ms.getId().contains(SelectKeyGenerator.SELECT_KEY_SUFFIX)){				
			DataSourceContextHolder.get().useSlave(true);
			logger.debug("Method[{} use Slave Strategy..",ms.getId());
		}
	}else{
		logger.debug("Method[{}] use Master Strategy..",ms.getId());
		DataSourceContextHolder.get().useSlave(false);
	}
	
	return null;
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:26,代码来源:RwRouteHandler.java

示例8: _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

示例9: 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

示例10: bindingLog

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
private void bindingLog(Invocation invocation) throws SQLException {

        Object[] args = invocation.getArgs();
        MappedStatement ms = (MappedStatement) args[0];
        Object parameterObject = args[1];
        StatementType statementType = ms.getStatementType();
        if (StatementType.PREPARED == statementType || StatementType.CALLABLE == statementType) {
            Log statementLog = ms.getStatementLog();
            if (isDebugEnable(statementLog)) {
                BoundSql boundSql = ms.getBoundSql(parameterObject);

                String sql = boundSql.getSql();
                List<String> parameterList = getParameters(ms, parameterObject, boundSql);
                debug(statementLog, "==> BindingLog: " + bindLogFormatter.format(sql, parameterList));
            }
        }
    }
 
开发者ID:naver,项目名称:pinpoint,代码行数:18,代码来源:BindingLogPlugin32.java

示例11: intercept

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

	MappedStatement ms = (MappedStatement) args[0];

	if (rowBound != null) {
		RowBounds rb = (RowBounds) rowBound;

		// without pagination
		if (rb.getOffset() == RowBounds.NO_ROW_OFFSET && rb.getLimit() == RowBounds.NO_ROW_LIMIT) {
			return invocation.proceed();
		} else {
			BoundSql boundSql = ms.getBoundSql(args);

			if (rowBound instanceof PageModel) {
				// physical pagination with PageModel
				PageModel pageModel = (PageModel) rowBound;
				Object count = queryCount(invocation, args, ms, boundSql);
				Object records = queryLimit(invocation, args, ms, boundSql, pageModel);

				pageModel.setRecordCount((Integer) ((List<?>) count).get(0));
				pageModel.setRecords((List<?>) records);

				return null;
			} else {
				// physical pagination with RowBounds
				return queryLimit(invocation, args, ms, boundSql, (RowBounds) rowBound);
			}
		}
	} else {
		// without pagination
		return invocation.proceed();
	}
}
 
开发者ID:dianping,项目名称:zebra,代码行数:37,代码来源:PageInterceptor.java

示例12: 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

示例13: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
/**
   * Physical Pagination Interceptor for all the queries with parameter {@link org.apache.ibatis.session.RowBounds}
   */
  public Object intercept(Invocation invocation) throws Throwable {
      StatementHandler statementHandler = (StatementHandler) PluginUtils.realTarget(invocation.getTarget());
      MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
      // 先判断是不是SELECT操作
      MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
      if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) {
          return invocation.proceed();
      }
      RowBounds rowBounds = (RowBounds) metaStatementHandler.getValue("delegate.rowBounds");
      /* 不需要分页的场合 */
      if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
          return invocation.proceed();
      }
      BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
      String originalSql = boundSql.getSql();
      Connection connection = (Connection) invocation.getArgs()[0];
      DBType dbType = JdbcUtils.getDbType(connection.getMetaData().getURL());
      if (rowBounds instanceof Pagination) {
          Pagination page = (Pagination) rowBounds;
          if (page.isSearchCount()) {
              this.queryTotal(JsqlParserUtils.jsqlparserCount(originalSql), mappedStatement, boundSql, page, connection);
              if (page.getTotal() <= 0) {
                  return invocation.proceed();
              }
          }
          originalSql = DialectFactory.buildPaginationSql(page, originalSql, dbType, null);
      } else {
          // support physical Pagination for RowBounds
          originalSql = DialectFactory.buildPaginationSql(rowBounds, originalSql, dbType, null);
      }

/*
       * <p> 禁用内存分页 </p> <p> 内存分页会查询所有结果出来处理(这个很吓人的),如果结果变化频繁这个数据还会不准。</p>
 */
      metaStatementHandler.setValue("delegate.boundSql.sql", originalSql);
      metaStatementHandler.setValue("delegate.rowBounds.offset", RowBounds.NO_ROW_OFFSET);
      metaStatementHandler.setValue("delegate.rowBounds.limit", RowBounds.NO_ROW_LIMIT);
      return invocation.proceed();
  }
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:43,代码来源:PaginationInterceptor.java

示例14: intercept

import org.apache.ibatis.plugin.Invocation; //导入方法依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
    MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
    Object parameter = null;
    if (invocation.getArgs().length > 1) {
        parameter = invocation.getArgs()[1];
    }
    String sqlId = mappedStatement.getId();
    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    Configuration configuration = mappedStatement.getConfiguration();
    Object returnValue = null;
    long start = System.currentTimeMillis();
    String sql = getSql(configuration, boundSql, sqlId);
    System.err.println("========================================================");
    System.err.println("https://hpit-bat.github.io/hpit-BAT-home"+"[隐无为]");
    System.err.println("========================================================");
    System.err.println("执行XML方法:"+sqlId);
    System.err.println("执行的完整的sql语句-------------------mysad");
    System.err.println(sql);
   
    returnValue = invocation.proceed();
    long end = System.currentTimeMillis();
    long time = (end - start);
    if (time > 1) {
        System.err.println("执行的sql语句的时间:"+time+"ms");
    }
    return returnValue;
}
 
开发者ID:hpit-BAT,项目名称:mybatis-tool-box,代码行数:28,代码来源:MybatisAutoSql.java

示例15: 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 mappedStatement = (MappedStatement) objects[0];
        String mappedStatementId = mappedStatement.getId();

        String dynamicDataSourceGlobal = cacheMap.get(mappedStatementId);
        if (dynamicDataSourceGlobal == null) {
            //读方法
            if (mappedStatement.getSqlCommandType().equals(SqlCommandType.SELECT)) {
                if (mappedStatementId.contains(SelectKeyGenerator.SELECT_KEY_SUFFIX)) {
                    dynamicDataSourceGlobal = MultipleDataSourceHolder.READ;
                } else {
                    BoundSql boundSql = mappedStatement.getSqlSource().getBoundSql(objects[1]);
                    String sql = boundSql.getSql().toLowerCase(Locale.CHINA).replaceAll("[\\t\\n\\r]", " ");
                    if (sql.matches(REGEX)) {
                        dynamicDataSourceGlobal = MultipleDataSourceHolder.WRITE;
                    } else {
                        dynamicDataSourceGlobal = MultipleDataSourceHolder.READ;
                    }
                }
            } else {
                dynamicDataSourceGlobal = MultipleDataSourceHolder.WRITE;
            }
            logger.warn("设置方法[{}] use [{}] Strategy, SqlCommandType [{}]..", mappedStatementId, dynamicDataSourceGlobal, mappedStatement.getSqlCommandType().name());
            cacheMap.put(mappedStatementId, dynamicDataSourceGlobal);
        }
        MultipleDataSourceHolder.setDataSource(dynamicDataSourceGlobal);
    }

    return invocation.proceed();
}
 
开发者ID:mumucommon,项目名称:mumu-core,代码行数:35,代码来源:MultipleMybatisInteInterceptor.java


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