• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DefaultParameterHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



DefaultParameterHandler类属于org.apache.ibatis.scripting.defaults包,在下文中一共展示了DefaultParameterHandler类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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();

		Object paramObj = ReflectHelper
				.getValueByFieldName(parameterHandler, "parameterObject");
		if (paramObj instanceof BatchParameter) {
			// 不绑定参数,在执行阶段才绑定
			return null;
		}
	}

	return invocation.proceed();
}
 
开发者ID:wen866595,项目名称:MyBatis-batch,代码行数:16,代码来源:BatchParameterHandler.java


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


示例5: getTotalCount

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
/**
 * 获取总记录数
 *
 * @param sql      原始sql语句
 * @param conn
 * @param ms
 * @param boundSql
 * @return
 * @throws SQLException
 */
private int getTotalCount(String sql, Connection conn, MappedStatement ms, BoundSql boundSql) throws SQLException {
  int start = sql.indexOf("from");
  if (start == -1) {
    throw new RuntimeException("statement has no 'from' keyword");
  }
  int stop = sql.indexOf("order by");
  if (stop == -1) {
    stop = sql.length();
  }

  String countSql = "select count(0) " + sql.substring(start, stop);
  BoundSql countBoundSql = new BoundSql(ms.getConfiguration(), countSql, boundSql.getParameterMappings(), boundSql.getParameterObject());
  ParameterHandler parameterHandler = new DefaultParameterHandler(ms, boundSql.getParameterObject(), countBoundSql);
  PreparedStatement stmt = null;
  ResultSet rs = null;
  int count = 0;
  try {
    stmt = conn.prepareStatement(countSql);
    // 通过parameterHandler给PreparedStatement对象设置参数
    parameterHandler.setParameters(stmt);
    rs = stmt.executeQuery();
    if (rs.next()) {
      count = rs.getInt(1);
    }
  } finally {
    CloseableUtil.closeQuietly(rs);
    CloseableUtil.closeQuietly(stmt);
  }
  return count;
}
 
开发者ID:colin-lee,项目名称:mybatis-spring-support,代码行数:41,代码来源:PaginationAutoMapInterceptor.java


示例6: getParameters

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
private List<String> getParameters(MappedStatement ms, Object parameterObject, BoundSql boundSql) throws SQLException {
    // DefaultParameterHandler is the only implementation of parameterHandler interface currently. it may be changed later.
    // need additional codes to find a appropriate implementation in that case.
    ParameterHandler parameterHandler = new DefaultParameterHandler(ms, parameterObject, boundSql);
    PreparedStatementParameterLogger parameterLogger = new PreparedStatementParameterLogger();
    parameterHandler.setParameters(parameterLogger);
    return parameterLogger.getParameters();
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:9,代码来源:BindingLogPlugin32.java


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


示例8: createParameterHandler

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
  return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
开发者ID:yuexiahandao,项目名称:MybatisCode,代码行数:5,代码来源:XMLLanguageDriver.java


示例9: createParameterHandler

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
    return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
开发者ID:hatunet,项目名称:mybatis-beetl-scripting,代码行数:5,代码来源:Driver.java


示例10: createParameterHandler

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
@Override
 public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
   //返回默认的参数处理器
return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
 }
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:6,代码来源:XMLLanguageDriver.java


示例11: createParameterHandler

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
  return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
开发者ID:shurun19851206,项目名称:mybaties,代码行数:4,代码来源:VelocityLanguageDriver.java


示例12: setParameters

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
private void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql,
        Object parameterObject) throws SQLException {
    ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
    parameterHandler.setParameters(ps);
}
 
开发者ID:shuli495,项目名称:fastjava,代码行数:6,代码来源:PageInterceptor.java


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


示例14: createParameterHandler

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
/**
 * Creates a {@link ParameterHandler} that passes the actual parameters
 * to the the JDBC statement.
 *
 * @see DefaultParameterHandler
 * @param mappedStatement The mapped statement that is being executed
 * @param parameterObject The input parameter object (can be null)
 * @param boundSql The resulting SQL once the dynamic language has been executed.
 */
@Override
public ParameterHandler createParameterHandler(MappedStatement mappedStatement, Object parameterObject,
    BoundSql boundSql) {
  // As default XMLLanguageDriver
  return new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
}
 
开发者ID:mybatis,项目名称:freemarker-scripting,代码行数:16,代码来源:FreeMarkerLanguageDriver.java


示例15: setParameters

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
/**
 * 代入参数值
 * 
 * @param ps
 * @param mappedStatement
 * @param boundSql
 * @param parameterObject
 * @throws SQLException
 */
private void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql,
		Object parameterObject) throws SQLException {
	ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
	parameterHandler.setParameters(ps);
}
 
开发者ID:butter-fly,项目名称:belling-admin,代码行数:15,代码来源:PaginationInterceptor.java


示例16: setParameters

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
/**
 * 对SQL参数(?)设值
 *
 * @param ps
 * @param mappedStatement
 * @param boundSql
 * @param parameterObject
 * @throws SQLException
 */
private static void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql, Object parameterObject) throws SQLException {
    ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
    parameterHandler.setParameters(ps);
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:14,代码来源:PaginationHelper.java


示例17: setParameters

import org.apache.ibatis.scripting.defaults.DefaultParameterHandler; //导入依赖的package包/类
/**
 * 对SQL参数(?)设值
 * 
 * @param ps
 * @param mappedStatement
 * @param boundSql
 * @param parameterObject
 * @throws SQLException
 */
private void setParameters(PreparedStatement ps, MappedStatement mappedStatement, BoundSql boundSql,
        Object parameterObject) throws SQLException {
    ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, parameterObject, boundSql);
    parameterHandler.setParameters(ps);
}
 
开发者ID:buzheng,项目名称:mybatis-pageable,代码行数:15,代码来源:MybatisPageableInterceptor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java APDU类代码示例发布时间:2022-05-21
下一篇:
Java PeProvisioner类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap