當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。