當前位置: 首頁>>代碼示例>>Java>>正文


Java Invocation類代碼示例

本文整理匯總了Java中org.apache.ibatis.plugin.Invocation的典型用法代碼示例。如果您正苦於以下問題:Java Invocation類的具體用法?Java Invocation怎麽用?Java Invocation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Invocation類屬於org.apache.ibatis.plugin包,在下文中一共展示了Invocation類的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 {
	// 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

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

示例5: processPage

import org.apache.ibatis.plugin.Invocation; //導入依賴的package包/類
/**
     * Mybatis攔截器方法
     *
     * @param invocation 攔截器入參
     * @return 返回執行結果
     * @throws Throwable 拋出異常
     */
    public Object processPage(Invocation invocation) throws Throwable {
        try {
            Object result = _processPage(invocation);
            clearLocalPage();
            //擴展當前分頁對象,使用spring的分頁對象
            if (result instanceof PageHelper) {
//            	MybatisPage page = (MybatisPage) result ;
//            	Page resultPage = new PageImpl(page , new PageRequest(page.getPageNum(), page.getPageSize()), page.getTotal()) ;
//            	return resultPage ;
                return new MybatisPageImpl((PageHelper) result);
            }
            return result;
        } finally {
            clearLocalPage();
        }
    }
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:24,代碼來源:SqlUtil.java

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

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

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

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

示例10: ShardContext

import org.apache.ibatis.plugin.Invocation; //導入依賴的package包/類
public ShardContext(MappedStatement mappedStatement, Object arg, Invocation invocation) {
    this.mappedStatement = mappedStatement;
    this.arg = arg;
    this.invocation = invocation;
    ExtendedSqlSource extendedSqlSource = (ExtendedSqlSource) mappedStatement.getSqlSource();
    this.boundSql = extendedSqlSource.buildBoundSql(arg);
    jdbcArgs = JdbcParameterHandler.getParameters(mappedStatement, arg, boundSql);
    this.iSqlParser = ExtendedSqlSource.createISqlParser(boundSql.getSql());

    /** if no table found , let go , maybe some wired but legal sql or mybatis sql like "select #{id}" in SelectKey */
    this.table = iSqlParser.getTableName();
    this.tableConfig = ShardConfig.getTableConfig(table);
}
 
開發者ID:maniaclee,項目名稱:shardy,代碼行數:14,代碼來源:ShardContext.java

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

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

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

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

示例15: processPage

import org.apache.ibatis.plugin.Invocation; //導入依賴的package包/類
/**
     * Mybatis攔截器方法
     *
     * @param invocation 攔截器入參
     * @return 返回執行結果
     * @throws Throwable 拋出異常
     */
    public Object processPage(Invocation invocation) throws Throwable {
        try{
            Object result = _processPage(invocation);
            clearLocalPage();
            //擴展當前分頁對象,使用spring的分頁對象
            if(result instanceof PageHelper){
//            	MybatisPage page = (MybatisPage) result ;
//            	Page resultPage = new PageImpl(page , new PageRequest(page.getPageNum(), page.getPageSize()), page.getTotal()) ;
//            	return resultPage ;
            	return new MybatisPageImpl((PageHelper) result) ;
            }
            return result;
        } finally {
            clearLocalPage();
        }
    }
 
開發者ID:lp895876294,項目名稱:genericdao,代碼行數:24,代碼來源:SqlUtil.java


注:本文中的org.apache.ibatis.plugin.Invocation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。