public class Session extends AbstractDb implements Closeable
caseInsensitive, ds, isSupportTransaction, runner
Constructor and Description |
---|
Session(DataSource ds)
构造,从DataSource中识别方言
|
Session(DataSource ds,
Dialect dialect)
构造
|
Session(DataSource ds,
String driverClassName)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
beginTransaction()
开始事务
|
void |
close() |
void |
closeConnection(Connection conn)
关闭连接
自定义关闭连接有利于自定义回收连接机制,或者不关闭 |
void |
commit()
提交事务
|
static Session |
create()
创建默认数据源会话
|
static Session |
create(DataSource ds)
创建会话
|
static Session |
create(String group)
创建会话
|
Session |
disableWrapper()
取消包装器
取消自动添加到字段名、表名上的包装符(例如双引号) |
Connection |
getConnection()
获得链接。
|
SqlConnRunner |
getRunner()
|
void |
quietRollback()
静默回滚事务
回滚事务 |
void |
quietRollback(Savepoint savepoint)
静默回滚到某个保存点,保存点的设置请使用setSavepoint方法
|
void |
rollback()
回滚事务
|
void |
rollback(Savepoint savepoint)
回滚到某个保存点,保存点的设置请使用setSavepoint方法
|
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 禁止脏读、不可重复读和幻读 |
Session |
setWrapper(Character wrapperChar)
设置包装器,包装器用于对表名、字段名进行符号包装(例如双引号),防止关键字与这些表名或字段冲突
|
Session |
setWrapper(Wrapper wrapper)
设置包装器,包装器用于对表名、字段名进行符号包装(例如双引号),防止关键字与这些表名或字段冲突
|
void |
tx(VoidFunc1<Session> func)
在事务中执行操作,通过实现
VoidFunc1 接口的call方法执行多条SQL语句从而完成事务 |
checkTransactionSupported, count, count, count, del, del, execute, executeBatch, executeBatch, executeBatch, executeBatch, executeForGeneratedKey, find, find, find, find, find, find, findAll, findAll, findAll, findBy, findBy, findLike, get, get, getDs, insert, insert, insertForGeneratedKey, insertForGeneratedKeys, insertOrUpdate, page, page, page, page, page, page, page, page, page, page, page, page, pageForEntityList, pageForEntityList, query, query, query, query, query, query, queryNumber, queryOne, queryString, setCaseInsensitive, setRunner, update, upsert
public Session(DataSource ds)
ds
- 数据源public Session(DataSource ds, String driverClassName)
ds
- 数据源driverClassName
- 数据库连接驱动类名,用于识别方言public Session(DataSource ds, Dialect dialect)
ds
- 数据源dialect
- 方言public static Session create()
public static Session create(String group)
group
- 分组public static Session create(DataSource ds)
ds
- 数据源public SqlConnRunner getRunner()
getRunner
in class AbstractDb
SqlConnRunner
public void beginTransaction() throws SQLException
SQLException
- SQL执行异常public void commit() throws SQLException
SQLException
- SQL执行异常public void rollback() throws SQLException
SQLException
- SQL执行异常public void quietRollback()
public void rollback(Savepoint savepoint) throws SQLException
savepoint
- 保存点SQLException
- SQL执行异常public void quietRollback(Savepoint savepoint)
savepoint
- 保存点public Savepoint setSavepoint() throws SQLException
SQLException
- SQL执行异常public Savepoint setSavepoint(String name) throws SQLException
name
- 保存点的名称SQLException
- SQL执行异常public void setTransactionIsolation(int level) throws SQLException
level
- 隔离级别SQLException
- SQL执行异常public void tx(VoidFunc1<Session> func) throws SQLException
VoidFunc1
接口的call方法执行多条SQL语句从而完成事务func
- 函数抽象,在函数中执行多个SQL操作,多个操作会被合并为同一事务SQLException
- SQL异常public Session setWrapper(Character wrapperChar)
AbstractDb
setWrapper
in class AbstractDb
wrapperChar
- 包装字符,字符会在SQL生成时位于表名和字段名两边,null时表示取消包装public Session setWrapper(Wrapper wrapper)
AbstractDb
setWrapper
in class AbstractDb
wrapper
- 包装器,null表示取消包装public Session disableWrapper()
AbstractDb
disableWrapper
in class AbstractDb
public Connection getConnection() throws SQLException
AbstractDb
getConnection
in class AbstractDb
Connection
SQLException
- 连接获取异常public void closeConnection(Connection conn)
AbstractDb
closeConnection
in class AbstractDb
conn
- 连接 Connection
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2024. All rights reserved.