public class Session extends Object implements Closeable
| 构造器和说明 |
|---|
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() |
<T> T |
find(Collection<String> fields,
Entity where,
RsHandler<T> rsh)
查询
|
Connection |
getConn() |
SqlConnRunner |
getRunner() |
Long |
insert(Entity record)
插入数据
|
<T> T |
page(Collection<String> fields,
Entity where,
int page,
int numPerPage,
RsHandler<T> rsh)
分页查询
|
<T> T |
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)
更新数据
|
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
SQLExceptionpublic void commit()
throws SQLException
SQLExceptionpublic void rollback()
throws SQLException
public void quietRollback()
SQLExceptionpublic void rollback(Savepoint savepoint) throws SQLException
savepoint - 保存点SQLExceptionpublic void quietRollback(Savepoint savepoint) throws SQLException
savepoint - 保存点SQLExceptionpublic Savepoint setSavepoint() throws SQLException
SQLExceptionpublic Savepoint setSavepoint(String name) throws SQLException
name - 保存点的名称SQLExceptionpublic void setTransactionIsolation(int level)
throws SQLException
level - 隔离级别SQLExceptionpublic <T> T query(String sql, RsHandler<T> rsh, Object... params) throws SQLException
sql - 查询语句rsh - 结果集处理对象params - 参数SQLExceptionpublic int execute(String sql, Object... params) throws SQLException
sql - SQLparams - 参数SQLExceptionpublic Long executeForGeneratedKey(String sql, Object... params) throws SQLException
sql - SQLparams - 参数SQLExceptionpublic int[] executeBatch(String sql, Object[]... paramsBatch) throws SQLException
sql - SQLparamsBatch - 批量的参数SQLExceptionpublic Long insert(Entity record) throws SQLException
record - 记录SQLExceptionpublic int del(Entity where) throws SQLException
where - 条件SQLExceptionpublic int update(Entity record, Entity where) throws SQLException
record - 记录SQLExceptionpublic <T> T find(Collection<String> fields, Entity where, RsHandler<T> rsh) throws SQLException
fields - 返回的字段列表,null则返回所有字段where - 条件实体类(包含表名)rsh - 结果集处理对象SQLExceptionpublic <T> T page(Collection<String> fields, Entity where, int page, int numPerPage, RsHandler<T> rsh) throws SQLException
fields - 返回的字段列表,null则返回所有字段where - 条件实体类(包含表名)page - 页码numPerPage - 每页条目数rsh - 结果集处理对象SQLExceptionpublic int count(Entity where) throws SQLException
where - 查询条件SQLExceptionpublic void close()
close 在接口中 Closeableclose 在接口中 AutoCloseableCopyright © 2015. All rights reserved.