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


Java DefaultParameterHandler.setParameters方法代码示例

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


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

示例1: queryTotal

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

示例2: getCount

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
public static int getCount(final MappedStatement ms, final Connection connection,
                           final Object parameterObject, Dialect dialect) throws SQLException {
    BoundSql boundSql = ms.getBoundSql(parameterObject);
    String countSql = dialect.getCountString(boundSql.getSql());

    logger.debug("Total count SQL [{}]", countSql);
    logger.debug("Parameters: {} ", parameterObject);

    PreparedStatement stmt = null;
    ResultSet rs;
    try{
        stmt = connection.prepareStatement(countSql);
        DefaultParameterHandler handler = new DefaultParameterHandler(ms, parameterObject, boundSql);
        handler.setParameters(stmt);
        rs = stmt.executeQuery();

        int count = 0;
        if(rs.next()){
            count = rs.getInt(1);
        }

        return count;
    }finally {
        closeStatement(stmt);
    }
}
 
开发者ID:loafer,项目名称:mybatis-paging,代码行数:27,代码来源:SqlHelper.java

示例3: executeBatch

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
protected int executeBatch(MappedStatement mappedStatement,
		BatchParameter<Object> paramObj,
		PreparedStatement ps, BoundSql boundSql,
		KeyGeneratorType keyGeneratorType) throws SQLException,
				SecurityException, NoSuchFieldException,
				IllegalArgumentException, IllegalAccessException {

	int batchSize = paramObj.getBatchSize();
	List<Object> parameterObject = paramObj.getData();
	List<Object> batchParams = new ArrayList<Object>(batchSize);

	for (Object pobject : parameterObject) {
		DefaultParameterHandler handler = new DefaultParameterHandler(
				mappedStatement, pobject, boundSql);
		handler.setParameters(ps);
		ps.addBatch();

		batchParams.add(pobject);
		if (batchParams.size() == batchSize) {
			executeBatch(mappedStatement, ps, paramObj, keyGeneratorType,
					batchParams);
			batchParams.clear();
		}
	}
	if (parameterObject.size() % batchSize != 0) {
		executeBatch(mappedStatement, ps, paramObj, keyGeneratorType,
				batchParams);
	}
	return 0;
}
 
开发者ID:wen866595,项目名称:MyBatis-batch,代码行数:31,代码来源:BatchStatementHandler.java

示例4: getCount

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
/**
 * 获取查询对象的总行数
 * @param sql  获取总行数的SQL
 * @param statementHandler
 * @param configuration
 * @param boundSql
 * @param connection
 * @throws Throwable
 */
public static void getCount(String sql, PreparedStatementHandler statementHandler,
                     Configuration configuration, BoundSql boundSql,
                     Connection connection)
        throws Throwable{
    Object parameterObject = statementHandler.getParameterHandler().getParameterObject();
    if (logger.isDebugEnabled()) {
        logger.debug("Total count SQL [{}] ", sql);
        logger.debug("Total count Parameters: {} ", parameterObject);
    }


    PreparedStatement countStmt = null;
    ResultSet rs = null;
    try {
        countStmt = connection.prepareStatement(sql);
        final BoundSql countBS = new BoundSql(configuration, sql,
                boundSql.getParameterMappings(), parameterObject);

        MappedStatement mappedStatement = (MappedStatement) FieldUtils.readField(statementHandler, MAPPED_STATEMENT, true);

        DefaultParameterHandler handler =
                new DefaultParameterHandler(mappedStatement, parameterObject, countBS);
        handler.setParameters(countStmt);

        rs = countStmt.executeQuery();
        int count = 0;
        if (rs.next()) {
            count = rs.getInt(1);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Total count: {}", count);
        }
        totalRowCountHolder.set(count);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
        } finally {
            if (countStmt != null) {
                countStmt.close();
            }
        }
    }
}
 
开发者ID:zjtx2017,项目名称:ocmall,代码行数:55,代码来源:CountHelper.java

示例5: intercept

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入方法依赖的package包/类
public Object intercept(Invocation invocation) throws Throwable {
	if (invocation.getTarget() instanceof DefaultParameterHandler) {
		DefaultParameterHandler parameterHandler = (DefaultParameterHandler) invocation
				.getTarget();

		MappedStatement mappedStatement = (MappedStatement) ReflectHelper
				.getValueByFieldName(parameterHandler, "mappedStatement");

		Object paramObj = ReflectHelper.getValueByFieldName(
				parameterHandler, "parameterObject");
		if (paramObj instanceof BatchInsertParameter) {

			PreparedStatement ps = (PreparedStatement) invocation.getArgs()[0];
			BoundSql boundSql = (BoundSql) ReflectHelper
					.getValueByFieldName(parameterHandler, "boundSql");

			@SuppressWarnings({ "unchecked", "rawtypes" })
			List<Object> parameterObject = (List) ((BatchInsertParameter) paramObj)
					.getData();

			ps.clearBatch();
			ps.clearParameters();

			@SuppressWarnings("rawtypes")
			int batchSize = ((BatchInsertParameter) paramObj)
					.getBatchSize();
			int i = 0;
			for (Object pobject : parameterObject) {
				DefaultParameterHandler handler = new DefaultParameterHandler(
						mappedStatement, pobject, boundSql);
				handler.setParameters(ps);
				ps.addBatch();
				i += 1;
				if (i % batchSize == 0) {
					ps.executeBatch();
				}
			}
			if (parameterObject.size() % batchSize != 0) {
				ps.executeBatch();
			}

			return i;
		}
	}

	return invocation.proceed();
}
 
开发者ID:wen866595,项目名称:mybatis-batchinsert-plugin,代码行数:48,代码来源:BatchInsertParameterHandler.java


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