com.xiaoleilu.hutool.db
类 SqlConnRunner

java.lang.Object
  继承者 com.xiaoleilu.hutool.db.SqlExecutor
      继承者 com.xiaoleilu.hutool.db.SqlConnRunner
直接已知子类:
SqlRunner

public class SqlConnRunner
extends SqlExecutor

SQL执行类
此执行类只接受方言参数,不需要数据源,只有在执行方法时需要数据库连接对象
此对象存在的意义在于,可以由使用者自定义数据库连接对象,并执行多个方法,方便事务的统一控制或减少连接对象的创建关闭

作者:
Luxiaolei

构造方法摘要
SqlConnRunner(Dialect dialect)
          构造
SqlConnRunner(String driverClassName)
          构造
 
方法摘要
 int count(Connection conn, Entity where)
          结果的条目数
 int del(Connection conn, Entity where)
          删除数据
此方法不会关闭Connection
<T> T
find(Connection conn, Collection<String> fields, Entity where, RsHandler<T> rsh)
          查询
此方法不会关闭Connection
 Long insert(Connection conn, Entity record)
          插入数据
此方法不会关闭Connection
<T> T
page(Connection conn, Collection<String> fields, Entity where, int page, int numPerPage, RsHandler<T> rsh)
          分页查询
此方法不会关闭Connection
 int update(Connection conn, Entity record, Entity where)
          更新数据
此方法不会关闭Connection
 
从类 com.xiaoleilu.hutool.db.SqlExecutor 继承的方法
execute, executeBatch, executeForGeneratedKey, query
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

SqlConnRunner

public SqlConnRunner(Dialect dialect)
构造

参数:
dialect - 方言

SqlConnRunner

public SqlConnRunner(String driverClassName)
构造

参数:
driverClassName - 驱动类名,,用于识别方言
方法详细信息

insert

public Long insert(Connection conn,
                   Entity record)
            throws SQLException
插入数据
此方法不会关闭Connection

参数:
conn - 数据库连接
record - 记录
返回:
主键
抛出:
SQLException

del

public int del(Connection conn,
               Entity where)
        throws SQLException
删除数据
此方法不会关闭Connection

参数:
conn - 数据库连接
where - 条件
返回:
影响行数
抛出:
SQLException

update

public int update(Connection conn,
                  Entity record,
                  Entity where)
           throws SQLException
更新数据
此方法不会关闭Connection

参数:
conn - 数据库连接
record - 记录
返回:
影响行数
抛出:
SQLException

find

public <T> T find(Connection conn,
                  Collection<String> fields,
                  Entity where,
                  RsHandler<T> rsh)
       throws SQLException
查询
此方法不会关闭Connection

参数:
conn - 数据库连接对象
fields - 返回的字段列表,null则返回所有字段
where - 条件实体类(包含表名)
rsh - 结果集处理对象
返回:
结果对象
抛出:
SQLException

page

public <T> T page(Connection conn,
                  Collection<String> fields,
                  Entity where,
                  int page,
                  int numPerPage,
                  RsHandler<T> rsh)
       throws SQLException
分页查询
此方法不会关闭Connection

参数:
conn - 数据库连接对象
fields - 返回的字段列表,null则返回所有字段
where - 条件实体类(包含表名)
page - 页码
numPerPage - 每页条目数
rsh - 结果集处理对象
返回:
结果对象
抛出:
SQLException

count

public int count(Connection conn,
                 Entity where)
          throws SQLException
结果的条目数

参数:
conn - 数据库连接对象
where - 查询条件
返回:
复合条件的结果数
抛出:
SQLException


Copyright © 2014. All rights reserved.