This commit is contained in:
Looly 2023-03-17 02:04:13 +08:00
parent 5623081278
commit a8a8c09ae8
5 changed files with 57 additions and 9 deletions

40
hutool-db/README.md Normal file
View File

@ -0,0 +1,40 @@
<p align="center">
<a href="https://hutool.cn/"><img src="https://plus.hutool.cn/images/hutool.svg" width="45%"></a>
</p>
<p align="center">
<strong>🍬A set of tools that keep Java sweet.</strong>
</p>
<p align="center">
👉 <a href="https://hutool.cn">https://hutool.cn/</a> 👈
</p>
## 📚Hutool-db 模块介绍
`Hutool-db`是一个在JDBC基础上封装的数据库操作工具类。通过包装使用ActiveRecord思想操作数据库。
在Hutool-db中使用Entity本质上是个Map代替Bean来使数据库操作更加灵活同时提供Bean和Entity的转换提供传统ORM的兼容支持。
-------------------------------------------------------------------------------
## 🛠️包含内容
### 数据库方言dialect
通过抽象CRUD方法针对不同数据库封装对应的查询、分页等SQL转换功能入口为`DialectFactory`
### 数据源ds
提供常用数据库连接池的门面支持,支持顺序为:
- Hikari > Druid > Tomcat > BeeCP > Dbcp > C3p0 > Hutool Pooled
### SQL相关工具sql
提供SQL相关功能包括SQL变量替换NamedSql通过对象完成SQL构建SqlBuilder等。
`SqlSqlExecutor`提供SQL执行的静态方法。
### 数据库元信息meta
通过`MetaUtil`提供数据库表、字段等信息的读取操作。
### 增删改查Db、Session
提供增删改查的汇总方法类。
### 结果转换handler
通过封装`RsHandler`提供将ResultSet转换为需要的对象的功能。

View File

@ -498,13 +498,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
* @throws DbRuntimeException SQL执行异常 * @throws DbRuntimeException SQL执行异常
*/ */
public <T> T find(final Collection<String> fields, final Entity where, final RsHandler<T> rsh) throws DbRuntimeException { public <T> T find(final Collection<String> fields, final Entity where, final RsHandler<T> rsh) throws DbRuntimeException {
Connection conn = null; return find(Query.of(where).setFields(fields), rsh);
try {
conn = this.getConnection();
return runner.find(conn, Query.of(where).setFields(fields), rsh);
} finally {
this.closeConnection(conn);
}
} }
/** /**

View File

@ -13,7 +13,12 @@ public class DefaultConnectionHolder implements ConnectionHolder {
protected final DataSource ds; protected final DataSource ds;
public DefaultConnectionHolder(DataSource ds) { /**
* 构造
*
* @param ds {@link DataSource}
*/
public DefaultConnectionHolder(final DataSource ds) {
this.ds = ds; this.ds = ds;
} }

View File

@ -118,7 +118,7 @@ public class StatementUtil {
* *
* @param conn 数据库连接 * @param conn 数据库连接
* @param sql SQL语句使用"?"做为占位符 * @param sql SQL语句使用"?"做为占位符
* @param params "?"对应参数列表 * @param params "?"对应参数列表或者Map表示命名参数
* @return {@link PreparedStatement} * @return {@link PreparedStatement}
* @throws SQLException SQL异常 * @throws SQLException SQL异常
* @since 3.2.3 * @since 3.2.3

View File

@ -115,9 +115,18 @@ public class SqlBuilder implements Builder<String> {
private QuoteWrapper quoteWrapper; private QuoteWrapper quoteWrapper;
// --------------------------------------------------------------- Constructor start // --------------------------------------------------------------- Constructor start
/**
* 构造
*/
public SqlBuilder() { public SqlBuilder() {
} }
/**
* 构造
*
* @param quoteWrapper 包装器
*/
public SqlBuilder(final QuoteWrapper quoteWrapper) { public SqlBuilder(final QuoteWrapper quoteWrapper) {
this.quoteWrapper = quoteWrapper; this.quoteWrapper = quoteWrapper;
} }