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


Java Invocation.getTarget方法代碼示例

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


在下文中一共展示了Invocation.getTarget方法的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包/類
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

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

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

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

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

示例11: intercept

import org.apache.ibatis.plugin.Invocation; //導入方法依賴的package包/類
public Object intercept(Invocation invocation) throws Throwable {
	if (invocation.getTarget() instanceof DefaultParameterHandler) {
		DefaultParameterHandler parameterHandler = (DefaultParameterHandler) invocation
				.getTarget();

		Object paramObj = ReflectHelper
				.getValueByFieldName(parameterHandler, "parameterObject");
		if (paramObj instanceof BatchParameter) {
			// 不綁定參數,在執行階段才綁定
			return null;
		}
	}

	return invocation.proceed();
}
 
開發者ID:wen866595,項目名稱:MyBatis-batch,代碼行數:16,代碼來源:BatchParameterHandler.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) Reflections.getFieldValue(statementHandler, DELEGATE);
            final MappedStatement mappedStatement = (MappedStatement) Reflections.getFieldValue(delegate, MAPPED_STATEMENT);

//            //攔截需要分頁的SQL
////            if (mappedStatement.getId().matches(_SQL_PATTERN)) { 
//            if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) {
                BoundSql boundSql = delegate.getBoundSql();
                //分頁SQL<select>中parameterType屬性對應的實體參數,即Mapper接口中執行分頁方法的參數,該參數不得為空
                Object parameterObject = boundSql.getParameterObject();
                if (parameterObject == null) {
                    log.error("參數未實例化");
                    throw new NullPointerException("parameterObject尚未實例化!");
                } else {
                    final Connection connection = (Connection) ivk.getArgs()[0];
                    final String sql = boundSql.getSql();
                    //記錄統計
                    final int count = SQLHelper.getCount(sql, connection, mappedStatement, parameterObject, boundSql, log);
                    Page<Object> page = null;
                    page = convertParameter(parameterObject, page);
                    page.setCount(count);
                    String pagingSql = SQLHelper.generatePageSql(sql, page, DIALECT);
                    if (log.isDebugEnabled()) {
                        log.debug("PAGE SQL:" + pagingSql);
                    }
                    //將分頁sql語句反射回BoundSql.
                    Reflections.setFieldValue(boundSql, "sql", pagingSql);
                }
                
                if (boundSql.getSql() == null || "".equals(boundSql.getSql())){
                    return null;
                }
                
            }
//        }
        return ivk.proceed();
    }
 
開發者ID:EleTeam,項目名稱:Shop-for-JavaWeb,代碼行數:41,代碼來源: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}
 */
@Override
public Object intercept(Invocation invocation) throws Throwable {

    Object target = invocation.getTarget();
    if (target instanceof StatementHandler) {
        return super.intercept(invocation);
    } else {
        RowBounds rowBounds = (RowBounds) invocation.getArgs()[2];
        if (rowBounds == null || rowBounds == RowBounds.DEFAULT) {
            return invocation.proceed();
        }
        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
        Executor executor = (Executor) invocation.getTarget();
        Connection connection = executor.getTransaction().getConnection();
        Object parameterObject = invocation.getArgs()[1];
        BoundSql boundSql = mappedStatement.getBoundSql(parameterObject);
        String originalSql = boundSql.getSql();
        if (rowBounds instanceof Pagination) {
            Pagination page = (Pagination) rowBounds;
            if (page.isSearchCount()) {
                SqlInfo sqlInfo = SqlUtils.getCountOptimize(sqlParser, originalSql);
                super.queryTotal(overflowCurrent, sqlInfo.getSql(), mappedStatement, boundSql, page, connection);
                if (page.getTotal() <= 0) {
                    return invocation.proceed();
                }
            }
        }
    }
    return invocation.proceed();
}
 
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:35,代碼來源:CachePaginationInterceptor.java

示例14: intercept

import org.apache.ibatis.plugin.Invocation; //導入方法依賴的package包/類
public Object intercept(Invocation invocation) throws Throwable {
	if (invocation.getTarget() instanceof RoutingStatementHandler) {
		RoutingStatementHandler routingStatementHandler = (RoutingStatementHandler) invocation
				.getTarget();

		StatementHandler delegate = (StatementHandler) ReflectHelper
				.getValueByFieldName(routingStatementHandler, "delegate");
		if (delegate instanceof PreparedStatementHandler) {

			PreparedStatementHandler preparedStatementHandler = (PreparedStatementHandler) delegate;
			MappedStatement mappedStatement = (MappedStatement) ReflectHelper
					.getValueByFieldName(preparedStatementHandler,
							"mappedStatement");

			BoundSql boundSql = (BoundSql) ReflectHelper
					.getValueByFieldName(preparedStatementHandler,
							"boundSql");

			Object parameterObject = boundSql.getParameterObject();
			if (parameterObject instanceof BatchInsertParameter) {
				PreparedStatement ps = (PreparedStatement) invocation
						.getArgs()[0];
				int rows = ps.getUpdateCount();
				Executor executor = (Executor) ReflectHelper
						.getValueByFieldName(preparedStatementHandler,
								"executor");

				KeyGenerator keyGenerator = mappedStatement
						.getKeyGenerator();

				keyGenerator.processAfter(executor, mappedStatement, ps,
						parameterObject);
				return rows;
			}
		}
	}

	return invocation.proceed();
}
 
開發者ID:wen866595,項目名稱:mybatis-batchinsert-plugin,代碼行數:40,代碼來源:BatchInsertStatementHandler.java

示例15: getPaginationParamter

import org.apache.ibatis.plugin.Invocation; //導入方法依賴的package包/類
/**
 * 獲取Mapper方法的Pagination參數
 * 
 * @author songkun
 * @create 2014年7月5日 下午2:59:48
 * @since
 * @param invocation
 * @return
 */
@SuppressWarnings("rawtypes")
private Pagination getPaginationParamter(Invocation invocation) {
	if (invocation == null || invocation.getTarget() == null) {
		return null;
	}
	RoutingStatementHandler handler = (RoutingStatementHandler) invocation.getTarget();
	if (handler == null || handler.getParameterHandler() == null) {
		return null;
	}
	Object parameters = handler.getParameterHandler().getParameterObject();
	if (parameters == null) {
		return null;
	}
	// 如果mapper方法隻有pagination參數,則直接返回
	if (parameters instanceof Pagination) {
		return (Pagination) parameters;
	}
	// 如果是多個參數,則判斷有沒有pagination參數
	if (parameters instanceof Map) {
		Map tmp = (Map) parameters;
		for (Iterator iterator = tmp.values().iterator(); iterator.hasNext();) {
			Object next = iterator.next();
			if (next instanceof Pagination) {
				return (Pagination) next;
			}
		}
	}
	return null;
}
 
開發者ID:songkun,項目名稱:spring-mybatis-jquery-2,代碼行數:39,代碼來源:PaginationIntercepter.java


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