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


Java BoundSql.getParameterObject方法代码示例

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


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

示例1: intercept

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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

示例2: findMasterValue

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private Object findMasterValue(ISqlParser iSqlParser, BoundSql boundSql, TableConfig tableConfig) throws SqlParseException {
    if (iSqlParser.getType() == SqlType.INSERT) {
        /** Insert */
        List<ColumnValue> columnValues = iSqlParser.getColumns();
        for (int i = 0; i < columnValues.size(); i++) {
            if (columnValues.get(i).column.equals(tableConfig.getMasterColumn())) {
                try {
                    return ReflectionUtils.getFieldValue(boundSql.getParameterObject(), boundSql.getParameterMappings().get(i).getProperty());
                } catch (Exception e) {
                    throw new SqlParseException("failed to parse property:" + boundSql.getParameterMappings().get(i).getProperty());
                }
            }
        }
    } else {
        /** Select/Update/Delete -> columns from "where" clause */
        if (boundSql.getParameterObject() instanceof MapperMethod.ParamMap) {
            return getColumnValue(tableConfig.getMasterColumn(), iSqlParser, boundSql);
        }
    }
    return null;
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:22,代码来源:ShardInterceptor.java

示例3: findColumnValue

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
@Deprecated
private static Object findColumnValue(ISqlParser iSqlParser, BoundSql boundSql, TableConfig tableConfig) {
    /** Select/Update/Delete -> columns from "where" clause */
    if (boundSql.getParameterObject() instanceof MapperMethod.ParamMap) {
        return getColumnValue(tableConfig.getMasterColumn(), iSqlParser, boundSql);
    } else {
        /** parameter is object */
        List<ColumnValue> columnValues = iSqlParser.getColumns();
        for (int i = 0; i < columnValues.size(); i++) {
            if (columnValues.get(i).column.equals(tableConfig.getMasterColumn())) {
                try {
                    return ReflectionUtils.getFieldValue(boundSql.getParameterObject(), boundSql.getParameterMappings().get(i).getProperty());
                } catch (Exception e) {
                    throw new SqlParseException("failed to parse property:" + boundSql.getParameterMappings().get(i).getProperty());
                }
            }
        }
    }
    return null;
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:21,代码来源:ExtendedSqlSource.java

示例4: getColumnValue

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
public static Object getColumnValue(String columnName, ISqlParser iSqlParser, BoundSql boundSql) {
    MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) boundSql.getParameterObject();
    List<ColumnValue> cols = iSqlParser.getColumns();
    for (int i = 0; i < cols.size(); i++) {
        if (Objects.equals(cols.get(i).column, columnName)) {
            //                if (cols.get(i).value.equals("?")) //TODO
            List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
            String property = parameterMappings.get(i).getProperty();
            if (!property.startsWith("_"))
                return paramMap.get("param" + (i + 1)); //index start from 1
            return parameterMappings.stream()
                    .filter(p -> p.getProperty().startsWith("__frch_" + columnName))
                    .map(parameterMapping -> boundSql.getAdditionalParameter(parameterMapping.getProperty()))
                    .collect(Collectors.toList());
        }
    }
    return null;
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:19,代码来源:ExtendedSqlSource.java

示例5: queryTotal

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
/**
 * 查询总记录条数
 *
 * @param sql
 * @param mappedStatement
 * @param boundSql
 * @param page
 */
protected void queryTotal(boolean overflowCurrent, String sql, MappedStatement mappedStatement, BoundSql boundSql, Pagination page, Connection connection) {
    try (PreparedStatement statement = connection.prepareStatement(sql)) {
        DefaultParameterHandler parameterHandler = new MybatisDefaultParameterHandler(mappedStatement, boundSql.getParameterObject(), boundSql);
        parameterHandler.setParameters(statement);
        int total = 0;
        try (ResultSet resultSet = statement.executeQuery()) {
            if (resultSet.next()) {
                total = resultSet.getInt(1);
            }
        }
        page.setTotal(total);
        /*
         * 溢出总页数,设置第一页
*/
        int pages = page.getPages();
        if (overflowCurrent && (page.getCurrent() > pages)) {
            // 设置为第一条
            page.setCurrent(1);
        }
    } catch (Exception e) {
        logger.error("Error: Method queryTotal execution error !", e);
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:32,代码来源:PaginationInterceptor.java

示例6: queryCount

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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

示例7: intercept

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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

示例8: processIntercept

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
void processIntercept(final Object[] queryArgs) {
	MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX];
	Object parameter = queryArgs[PARAMETER_INDEX];
	final RowBounds rowBounds = (RowBounds) queryArgs[ROWBOUNDS_INDEX];
	int offset = rowBounds.getOffset();
	int limit = rowBounds.getLimit();
	if (dialect.supportsLimit() && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) {
		BoundSql boundSql = ms.getBoundSql(parameter);
		String sql = boundSql.getSql().trim();
		if (dialect.supportsLimitOffset()) {
			sql = dialect.getLimitString(sql, offset, limit);
			offset = RowBounds.NO_ROW_OFFSET;
		} else {
			sql = dialect.getLimitString(sql, 0, limit);
		}
		limit = RowBounds.NO_ROW_LIMIT;
		queryArgs[ROWBOUNDS_INDEX] = new RowBounds(offset, limit);
		BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(),
				boundSql.getParameterObject());
		for (ParameterMapping mapping : boundSql.getParameterMappings()) {
			String prop = mapping.getProperty();
			if (boundSql.hasAdditionalParameter(prop)) {
				newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
			}
		}
		MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql));
		queryArgs[MAPPED_STATEMENT_INDEX] = newMs;
	}
}
 
开发者ID:yi-jun,项目名称:aaden-pay,代码行数:30,代码来源:PagePluging.java

示例9: copyFromBoundSql

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private static BoundSql copyFromBoundSql(MappedStatement ms, BoundSql boundSql, String sql) {
    BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject());
    for (ParameterMapping mapping : boundSql.getParameterMappings()) {
        String prop = mapping.getProperty();
        if (boundSql.hasAdditionalParameter(prop)) {
            newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
        }
    }
    return newBoundSql;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:11,代码来源:PaginationHelper.java

示例10: copyFromBoundSql

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private BoundSql copyFromBoundSql(MappedStatement ms, BoundSql boundSql,
		String sql) {
	BoundSql newBoundSql = new BoundSql(ms.getConfiguration(),sql, boundSql.getParameterMappings(), boundSql.getParameterObject());
	for (ParameterMapping mapping : boundSql.getParameterMappings()) {
	    String prop = mapping.getProperty();
	    if (boundSql.hasAdditionalParameter(prop)) {
	        newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop));
	    }
	}
	return newBoundSql;
}
 
开发者ID:codeWatching,项目名称:codePay,代码行数:12,代码来源:OffsetLimitInterceptor.java

示例11: getColumnValue

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private Object getColumnValue(String columnName, ISqlParser iSqlParser, BoundSql boundSql) {
    MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) boundSql.getParameterObject();
    List<ColumnValue> cols = iSqlParser.getColumns();
    for (int i = 0; i < cols.size(); i++) {
        if (Objects.equals(cols.get(i).column, columnName)) {
            //                if (cols.get(i).value.equals("?")) //TODO
            return paramMap.get(boundSql.getParameterMappings().get(i).getProperty());
        }
    }
    return null;
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:12,代码来源:ShardInterceptor.java

示例12: interceptQuery

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
public Object interceptQuery(Invocation invocation) throws Throwable {
    /** statement is new Object with different memory address */
    StatementHandler statementHandler = (StatementHandler) invocation.getTarget();
    BoundSql boundSql = statementHandler.getBoundSql();
    String sql = boundSql.getSql();
    System.out.println(statementHandler.getClass());
    System.out.println("sql->" + sql);
    ISqlParser iSqlParser = new DruidSqlParser();
    iSqlParser.init(sql);
    iSqlParser.setTableName("fuck");

    String masterColumn = "id";
    if (boundSql.getParameterObject() instanceof MapperMethod.ParamMap) {
        MapperMethod.ParamMap paramMap = (MapperMethod.ParamMap) boundSql.getParameterObject();
        Object masterValue = paramMap.get(masterColumn);
        System.out.println("param-> " + masterValue);
    }

    String sqlResult = iSqlParser.toSql();
    System.out.println("sqlResult->" + sqlResult);

    Statement statement = (Statement) invocation.getArgs()[0];
    ReflectionUtils.setDeclaredFieldValue(boundSql, "sql", sqlResult);

    Object h = ReflectionUtils.getFieldValue(statement, "h");
    if (h instanceof PreparedStatementLogger) {
        PreparedStatementLogger preparedStatementLogger = (PreparedStatementLogger) h;
        PreparedStatement preparedStatement = preparedStatementLogger.getPreparedStatement();
    }
    System.out.println(statement.getClass().getName());
    System.out.println("sta-> " + statementHandler);
    return invocation.proceed();
}
 
开发者ID:maniaclee,项目名称:shardy,代码行数:34,代码来源:ShardInterceptor.java

示例13: intercept

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的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

示例14: onInterceptor

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

	Object[] objects = invocation.getArgs();
	MappedStatement ms = (MappedStatement) objects[0];
	Object parameterObject = objects[1];

	// TypeHandlerRegistry typeHandlerRegistry =
	// ms.getConfiguration().getTypeHandlerRegistry();
	
	if(ignoreMappedStatementIds.contains(ms.getId())){
		return null;
	}
	String namespace = ms.getId().substring(0, ms.getId().lastIndexOf(SPIT_POINT));
	//策略配置忽略
	if(ignoreTablesMapperNameSpace.contains(namespace)){
		return null;
	}

	BoundSql boundSql = ms.getBoundSql(parameterObject);
	
	Object parameterObject2 = boundSql.getParameterObject();
	System.out.println(parameterObject2);

	//是否需要分库
	boolean requiredShard = isRequiredShard(boundSql.getSql(), ms.getSqlCommandType(), namespace);
	
	if(requiredShard){
		//先检查是否已经设置
		Object shardFieldValue = getShardFieldValue(ms.getId(),parameterObject);
		if(shardFieldValue == null){
			logger.error("方法{}无法获取分库字段{}的值",ms.getId(),shardStrategy.shardEntityField());
		}else{				
			int dbIndex = shardStrategy.assigned(shardFieldValue);
			//指定数据库分库序列
			DataSourceContextHolder.get().setDbIndex(dbIndex);
		}
	}
	return null;
}
 
开发者ID:vakinge,项目名称:jeesuite-libs,代码行数:41,代码来源:DatabaseRouteHandler.java

示例15: queryLimit

import org.apache.ibatis.mapping.BoundSql; //导入方法依赖的package包/类
private Object queryLimit(Invocation invocation, Object[] args, MappedStatement ms, BoundSql boundSql, RowBounds rb)
		throws InvocationTargetException, IllegalAccessException {
	String limitSql = dialect.getLimitSql(boundSql.getSql(), rb.getOffset(), rb.getLimit());
	BoundSql newBoundSql = new BoundSql(ms.getConfiguration(), limitSql, boundSql.getParameterMappings(),
			boundSql.getParameterObject());
	MetaObject mo = (MetaObject) ReflectionUtils.getFieldValue(boundSql, "metaParameters");
	ReflectionUtils.setFieldValue(newBoundSql, "metaParameters", mo);

	args[0] = buildMappedStatement(ms, new SqlSourceWrapper(newBoundSql), ms.getId() + "_LIMIT",
			ms.getResultMaps());
	args[2] = new RowBounds();
	args[3] = null;

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


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