public class DialectRunner extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected boolean |
caseInsensitive
是否大小写不敏感(默认大小写不敏感)
|
Constructor and Description |
---|
DialectRunner(Dialect dialect)
构造
|
DialectRunner(String driverClassName)
构造
|
Modifier and Type | Method and Description |
---|---|
long |
count(Connection conn,
Entity where)
获取结果总数,生成类似于select count(1) from XXX wher XXX=?
|
long |
count(Connection conn,
SqlBuilder sqlBuilder)
获取查询结果总数,生成类似于 SELECT count(1) from (sql) hutool_alias_count_
此方法会重新构建 SqlBuilder ,并去除末尾的order by子句 |
int |
del(Connection conn,
Entity where)
删除数据
此方法不会关闭Connection |
<T> T |
find(Connection conn,
Query query,
RsHandler<T> rsh)
查询
此方法不会关闭Connection |
Dialect |
getDialect() |
int[] |
insert(Connection conn,
Entity... records)
批量插入数据
批量插入必须严格保持Entity的结构一致,不一致会导致插入数据出现不可预知的结果 此方法不会关闭Connection |
<T> T |
insert(Connection conn,
Entity record,
RsHandler<T> generatedKeysHandler)
插入数据
此方法不会关闭Connection |
int |
insertOrUpdate(Connection conn,
Entity record,
String... keys)
插入或更新数据
此方法不会关闭Connection |
<T> T |
page(Connection conn,
Query query,
RsHandler<T> rsh)
分页查询
此方法不会关闭Connection |
<T> T |
page(Connection conn,
SqlBuilder sqlBuilder,
Page page,
RsHandler<T> rsh)
分页查询
此方法不会关闭Connection |
void |
setCaseInsensitive(boolean caseInsensitive)
设置是否在结果中忽略大小写
如果忽略,则在Entity中调用getXXX时,字段值忽略大小写,默认忽略 |
void |
setDialect(Dialect dialect)
设置SQL方言
|
void |
setWrapper(Character wrapperChar)
设置包装器,包装器用于对表名、字段名进行符号包装(例如双引号),防止关键字与这些表名或字段冲突
|
void |
setWrapper(Wrapper wrapper)
设置包装器,包装器用于对表名、字段名进行符号包装(例如双引号),防止关键字与这些表名或字段冲突
|
int |
update(Connection conn,
Entity record,
Entity where)
更新数据
此方法不会关闭Connection |
int |
upsert(Connection conn,
Entity record,
String... keys)
更新或插入数据
此方法不会关闭Connection 如果方言未实现此方法则内部自动使用insertOrUpdate来替代功能 |
public DialectRunner(Dialect dialect)
dialect
- 方言public DialectRunner(String driverClassName)
driverClassName
- 驱动类名,用于识别方言public int[] insert(Connection conn, Entity... records) throws SQLException
conn
- 数据库连接records
- 记录列表,记录KV必须严格一致SQLException
- SQL执行异常public int upsert(Connection conn, Entity record, String... keys) throws SQLException
conn
- 数据库连接record
- 记录keys
- 需要检查唯一性的字段SQLException
- SQL执行异常public int insertOrUpdate(Connection conn, Entity record, String... keys) throws SQLException
conn
- 数据库连接record
- 记录keys
- 需要检查唯一性的字段SQLException
- SQL执行异常public <T> T insert(Connection conn, Entity record, RsHandler<T> generatedKeysHandler) throws SQLException
T
- 主键类型,可能为数字或对象列表conn
- 数据库连接record
- 记录generatedKeysHandler
- 自增主键处理器,用于定义返回自增主键的范围和类型SQLException
- SQL执行异常public int del(Connection conn, Entity where) throws SQLException
conn
- 数据库连接where
- 条件SQLException
- SQL执行异常public int update(Connection conn, Entity record, Entity where) throws SQLException
conn
- 数据库连接record
- 记录where
- 条件SQLException
- SQL执行异常public <T> T find(Connection conn, Query query, RsHandler<T> rsh) throws SQLException
T
- 结果对象类型conn
- 数据库连接对象query
- Query
rsh
- 结果集处理对象SQLException
- SQL执行异常public long count(Connection conn, Entity where) throws SQLException
conn
- 数据库连接对象where
- 查询条件SQLException
- SQL执行异常public long count(Connection conn, SqlBuilder sqlBuilder) throws SQLException
SqlBuilder
,并去除末尾的order by子句conn
- 数据库连接对象sqlBuilder
- 查询语句SQLException
- SQL执行异常public <T> T page(Connection conn, Query query, RsHandler<T> rsh) throws SQLException
T
- 结果对象类型conn
- 数据库连接对象query
- 查询条件(包含表名)rsh
- 结果集处理对象SQLException
- SQL执行异常public <T> T page(Connection conn, SqlBuilder sqlBuilder, Page page, RsHandler<T> rsh) throws SQLException
T
- 结果对象类型conn
- 数据库连接对象sqlBuilder
- SQL构建器,可以使用SqlBuilder.of(CharSequence)
包装普通SQLpage
- 分页对象rsh
- 结果集处理对象SQLException
- SQL执行异常public void setCaseInsensitive(boolean caseInsensitive)
caseInsensitive
- 否在结果中忽略大小写public Dialect getDialect()
public void setDialect(Dialect dialect)
dialect
- 方言public void setWrapper(Character wrapperChar)
wrapperChar
- 包装字符,字符会在SQL生成时位于表名和字段名两边,null时表示取消包装public void setWrapper(Wrapper wrapper)
wrapper
- 包装器,null表示取消包装Copyright © 2024. All rights reserved.