|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectcom.xiaoleilu.hutool.db.Session
public class Session
数据库SQL执行会话
一个会话只维护一个连接,推荐在执行完后关闭Session,避免重用
本对象并不是线程安全的,多个线程共用一个Session将会导致不可预知的问题
| 构造方法摘要 | |
|---|---|
Session(Connection conn)
构造 |
|
Session(DataSource ds)
构造 |
|
| 方法摘要 | ||
|---|---|---|
void |
beginTransaction()
开始事务 |
|
void |
close()
|
|
void |
commit()
提交事务 |
|
int |
count(Entity where)
结果的条目数 |
|
static Session |
create(Connection conn)
创建会话 |
|
static Session |
create(DataSource ds)
创建会话 |
|
int |
del(Entity where)
删除数据 |
|
int |
execute(String sql,
Object... params)
执行非查询语句 语句包括 插入、更新、删除 |
|
int[] |
executeBatch(String sql,
Object[]... paramsBatch)
批量执行非查询语句 |
|
Long |
executeForGeneratedKey(String sql,
Object... params)
执行非查询语句 语句包括 插入、更新、删除 |
|
protected void |
finalize()
|
|
|
find(Collection<String> fields,
Entity where,
RsHandler<T> rsh)
查询 |
|
Connection |
getConn()
|
|
SqlConnRunner |
getRunner()
|
|
Long |
insert(Entity record)
插入数据 |
|
|
page(Collection<String> fields,
Entity where,
int page,
int numPerPage,
RsHandler<T> rsh)
分页查询 |
|
|
query(String sql,
RsHandler<T> rsh,
Object... params)
查询 |
|
void |
quietRollback()
静默回滚事务 回滚事务 |
|
void |
quietRollback(Savepoint savepoint)
静默回滚到某个保存点,保存点的设置请使用setSavepoint方法 |
|
void |
rollback()
回滚事务 |
|
void |
rollback(Savepoint savepoint)
回滚到某个保存点,保存点的设置请使用setSavepoint方法 |
|
void |
setConn(Connection conn)
|
|
void |
setRunner(SqlConnRunner runner)
|
|
Savepoint |
setSavepoint()
设置保存点 |
|
Savepoint |
setSavepoint(String name)
设置保存点 |
|
void |
setTransactionIsolation(int level)
设置事务的隔离级别 Connection.TRANSACTION_NONE 驱动不支持事务 Connection.TRANSACTION_READ_UNCOMMITTED 允许脏读、不可重复读和幻读 Connection.TRANSACTION_READ_COMMITTED 禁止脏读,但允许不可重复读和幻读 Connection.TRANSACTION_REPEATABLE_READ 禁止脏读和不可重复读,单运行幻读 Connection.TRANSACTION_SERIALIZABLE 禁止脏读、不可重复读和幻读 |
|
int |
update(Entity record,
Entity where)
更新数据 |
|
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public Session(DataSource ds)
ds - 数据源public Session(Connection conn)
conn - 数据库连接对象| 方法详细信息 |
|---|
public static Session create(DataSource ds)
ds - 数据源public static Session create(Connection conn)
conn - 数据库连接对象public Connection getConn()
public void setConn(Connection conn)
public SqlConnRunner getRunner()
public void setRunner(SqlConnRunner runner)
public void beginTransaction()
throws SQLException
SQLException
public void commit()
throws SQLException
SQLException
public void rollback()
throws SQLException
Exception
SQLExceptionpublic void quietRollback()
SQLException
public void rollback(Savepoint savepoint)
throws SQLException
savepoint - 保存点
SQLException
public void quietRollback(Savepoint savepoint)
throws SQLException
savepoint - 保存点
SQLException
public Savepoint setSavepoint()
throws SQLException
SQLException
public Savepoint setSavepoint(String name)
throws SQLException
name - 保存点的名称
SQLException
public void setTransactionIsolation(int level)
throws SQLException
level - 隔离级别
SQLException
public <T> T query(String sql,
RsHandler<T> rsh,
Object... params)
throws SQLException
sql - 查询语句rsh - 结果集处理对象params - 参数
SQLException
public int execute(String sql,
Object... params)
throws SQLException
sql - SQLparams - 参数
SQLException
public Long executeForGeneratedKey(String sql,
Object... params)
throws SQLException
sql - SQLparams - 参数
SQLException
public int[] executeBatch(String sql,
Object[]... paramsBatch)
throws SQLException
sql - SQLparamsBatch - 批量的参数
SQLException
public Long insert(Entity record)
throws SQLException
record - 记录
SQLException
public int del(Entity where)
throws SQLException
where - 条件
SQLException
public int update(Entity record,
Entity where)
throws SQLException
record - 记录
SQLException
public <T> T find(Collection<String> fields,
Entity where,
RsHandler<T> rsh)
throws SQLException
fields - 返回的字段列表,null则返回所有字段where - 条件实体类(包含表名)rsh - 结果集处理对象
SQLException
public <T> T page(Collection<String> fields,
Entity where,
int page,
int numPerPage,
RsHandler<T> rsh)
throws SQLException
fields - 返回的字段列表,null则返回所有字段where - 条件实体类(包含表名)page - 页码numPerPage - 每页条目数rsh - 结果集处理对象
SQLException
public int count(Entity where)
throws SQLException
where - 查询条件
SQLExceptionpublic void close()
Closeable 中的 close
protected void finalize()
throws Throwable
Object 中的 finalizeThrowable
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||