mybatis源码之PreparedStatementHandler
2016-01-07 20:11
381 查看
/** * @author Clinton Begin */ public class PreparedStatementHandler extends BaseStatementHandler { public PreparedStatementHandler(Executor executor, MappedStatement mappedStatement, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { super(executor, mappedStatement, parameter, rowBounds, resultHandler, boundSql); } public int update(Statement statement) throws SQLException { PreparedStatement ps = (PreparedStatement) statement; ps.execute(); int rows = ps.getUpdateCount(); Object parameterObject = boundSql.getParameterObject(); KeyGenerator keyGenerator = mappedStatement.getKeyGenerator(); keyGenerator.processAfter(executor, mappedStatement, ps, parameterObject); return rows; } public void batch(Statement statement) throws SQLException { PreparedStatement ps = (PreparedStatement) statement; ps.addBatch(); } public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException { PreparedStatement ps = (PreparedStatement) statement; ps.execute(); return resultSetHandler.<E> handleResultSets(ps); } protected Statement instantiateStatement(Connection connection) throws SQLException { String sql = boundSql.getSql(); if (mappedStatement.getKeyGenerator() instanceof Jdbc3KeyGenerator) { String[] keyColumnNames = mappedStatement.getKeyColumns(); if (keyColumnNames == null) { return connection.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS); } else { return connection.prepareStatement(sql, keyColumnNames); } } else if (mappedStatement.getResultSetType() != null) { return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY); } else { return connection.prepareStatement(sql); } } public void parameterize(Statement statement) throws SQLException { parameterHandler.setParameters((PreparedStatement) statement); } }
相关文章推荐
- linux静默安装oracle数据库
- 开发板 nfs : server xxx.xxx.xxx.xxx not responding,still trying问题解决方法
- 怎么关闭新版福昕阅读器广告的方法
- mybatis源码之PreparedStatementHandler
- 实现一个简单的aufs文件系统
- java模板和回调机制学习总结
- Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom
- JQ属性选取attr、prop、data的区别
- c++ 优秀文章
- tcp http socket
- 接下来要做的事情
- 新出台的治理iMessage垃圾短信的规则
- 编写高质量代码--改善python程序的建议(六)
- 数字颠倒
- Mybatis源码之CallableStatementHandler
- Mybatis源码之CallableStatementHandler
- Mybatis源码之CallableStatementHandler
- Android 获取手机总内存和可用内存等信息
- 微信公众平台PHP开发
- jenkins的构建项目配置