1
mirror of https://github.com/CarmJos/EasySQL.git synced 2026-06-14 03:15:55 +08:00

Compare commits

..

50 Commits

Author SHA1 Message Date
carm 7a2d1841db [0.3.6] 枚举参数默认采用 name() 方法 2022-02-05 12:07:45 +08:00
carm f7d85ddf94 Merge pull request #26 from Ghost-chu/master
修正 README.md 中 Maven 中心库的错误的URL
2022-02-03 22:02:52 +08:00
Ghost_chu a438c0e7d0 Update README.md 2022-02-03 22:00:24 +08:00
carm bb4801b41c [0.3.5] 修复 ConditionalBuilder 对于参数未添加 AND 链接的问题 2022-01-29 21:20:07 +08:00
carm 7acc2849ae [0.3.4] 对参数判断是否已加引号或反引号 2022-01-29 17:26:08 +08:00
carm 5e7519dc7a [ci skip] Merge pull request #21 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-gpg-plugin-3.0.1
Bump maven-gpg-plugin from 1.6 to 3.0.1
2022-01-29 17:05:28 +08:00
carm 643841a98a [ci skip] Merge pull request #20 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.2.4
Bump maven-shade-plugin from 3.2.3 to 3.2.4
2022-01-29 17:05:20 +08:00
carm 8513324046 [ci skip] Merge pull request #19 from CarmJos/dependabot/maven/mysql-mysql-connector-java-8.0.28
Bump mysql-connector-java from 8.0.25 to 8.0.28
2022-01-29 17:05:11 +08:00
dependabot[bot] 6702a69f8d Bump maven-gpg-plugin from 1.6 to 3.0.1
Bumps [maven-gpg-plugin](https://github.com/apache/maven-gpg-plugin) from 1.6 to 3.0.1.
- [Release notes](https://github.com/apache/maven-gpg-plugin/releases)
- [Commits](https://github.com/apache/maven-gpg-plugin/compare/maven-gpg-plugin-1.6...maven-gpg-plugin-3.0.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-gpg-plugin
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:58:48 +00:00
dependabot[bot] 45cd4c326f Bump maven-shade-plugin from 3.2.3 to 3.2.4
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.3 to 3.2.4.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.3...maven-shade-plugin-3.2.4)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:58:43 +00:00
dependabot[bot] 7097ef518e Bump mysql-connector-java from 8.0.25 to 8.0.28
Bumps [mysql-connector-java](https://github.com/mysql/mysql-connector-j) from 8.0.25 to 8.0.28.
- [Release notes](https://github.com/mysql/mysql-connector-j/releases)
- [Changelog](https://github.com/mysql/mysql-connector-j/blob/release/8.0/CHANGES)
- [Commits](https://github.com/mysql/mysql-connector-j/compare/8.0.25...8.0.28)

---
updated-dependencies:
- dependency-name: mysql:mysql-connector-java
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:58:32 +00:00
carm 6a67be5b8d [ci skip] Merge pull request #15 from CarmJos/dependabot/maven/com.zaxxer-HikariCP-5.0.1
Bump HikariCP from 4.0.3 to 5.0.1
2022-01-29 16:56:52 +08:00
carm 73e6ebef1d [ci skip] Merge pull request #17 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-source-plugin-3.2.1
Bump maven-source-plugin from 3.2.0 to 3.2.1
2022-01-29 16:55:55 +08:00
carm 9cbfda954c [ci skip] Merge pull request #16 from CarmJos/dependabot/maven/org.jetbrains-annotations-23.0.0
Bump annotations from 22.0.0 to 23.0.0
2022-01-29 16:55:26 +08:00
carm a4036a359e [ci skip] Merge pull request #14 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-surefire-plugin-2.22.2
Bump maven-surefire-plugin from 2.22.1 to 2.22.2
2022-01-29 16:55:13 +08:00
carm e5f6d621e1 Merge pull request #18 from CarmJos/dependabot/maven/org.slf4j-slf4j-api-1.7.35
Bump slf4j-api from 1.7.29 to 1.7.35
2022-01-29 16:54:49 +08:00
dependabot[bot] 03afae635b Bump slf4j-api from 1.7.29 to 1.7.35
Bumps [slf4j-api](https://github.com/qos-ch/slf4j) from 1.7.29 to 1.7.35.
- [Release notes](https://github.com/qos-ch/slf4j/releases)
- [Commits](https://github.com/qos-ch/slf4j/compare/v_1.7.29...v_1.7.35)

---
updated-dependencies:
- dependency-name: org.slf4j:slf4j-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:54:07 +00:00
dependabot[bot] a55809d60e Bump maven-source-plugin from 3.2.0 to 3.2.1
Bumps [maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.2.0 to 3.2.1.
- [Release notes](https://github.com/apache/maven-source-plugin/releases)
- [Commits](https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.0...maven-source-plugin-3.2.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-source-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:54:03 +00:00
dependabot[bot] 45fafdf68a Bump annotations from 22.0.0 to 23.0.0
Bumps [annotations](https://github.com/JetBrains/java-annotations) from 22.0.0 to 23.0.0.
- [Release notes](https://github.com/JetBrains/java-annotations/releases)
- [Changelog](https://github.com/JetBrains/java-annotations/blob/master/CHANGELOG.md)
- [Commits](https://github.com/JetBrains/java-annotations/compare/22.0.0...23.0.0)

---
updated-dependencies:
- dependency-name: org.jetbrains:annotations
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:53:57 +00:00
dependabot[bot] e5c6fe1c92 Bump HikariCP from 4.0.3 to 5.0.1
Bumps [HikariCP](https://github.com/brettwooldridge/HikariCP) from 4.0.3 to 5.0.1.
- [Release notes](https://github.com/brettwooldridge/HikariCP/releases)
- [Changelog](https://github.com/brettwooldridge/HikariCP/blob/dev/CHANGES)
- [Commits](https://github.com/brettwooldridge/HikariCP/compare/HikariCP-4.0.3...HikariCP-5.0.1)

---
updated-dependencies:
- dependency-name: com.zaxxer:HikariCP
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:53:53 +00:00
dependabot[bot] a1d531f1cc Bump maven-surefire-plugin from 2.22.1 to 2.22.2
Bumps [maven-surefire-plugin](https://github.com/apache/maven-surefire) from 2.22.1 to 2.22.2.
- [Release notes](https://github.com/apache/maven-surefire/releases)
- [Commits](https://github.com/apache/maven-surefire/compare/surefire-2.22.1...surefire-2.22.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-surefire-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-29 08:53:47 +00:00
carm c1dfe8dfe0 Merge remote-tracking branch 'origin/master' 2022-01-29 16:44:53 +08:00
carm e8debf73f1 修改部分url地址 2022-01-29 16:44:37 +08:00
carm 7df308f8c6 Update bugs_report.md 2022-01-29 16:04:45 +08:00
carm 0b275d3633 Update feature_issues.md 2022-01-29 16:03:59 +08:00
carm 893511ac06 Merge remote-tracking branch 'origin/master' 2022-01-29 06:02:35 +08:00
carm 045dd9866e 添加中心库介绍 2022-01-29 06:02:25 +08:00
carm 086a6c8b31 Merge pull request #11 from Msyial/master
鉴于该库开发发布于Central,故添加 Maven Central库的相关介绍。
2022-01-29 05:58:16 +08:00
X1A 28464350ee Update README.md 2022-01-29 05:51:40 +08:00
carm 72259bef81 [0.3.3] 版本更新
- `[F]` 修复上个版本中 QueryAction 的 executeFunction 方法未重写 SQLAction 中同方法导致的链接未被自动关闭的问题。
- `[U]` 更新软件依赖于Maven相关插件的版本。
2022-01-29 04:57:29 +08:00
carm 8924258635 [0.3.3] 版本更新
- `[F]` 修复上个版本中 QueryAction 的 executeFunction 方法未重写 SQLAction 中同方法导致的链接未被自动关闭的问题。
- `[U]` 更新软件依赖于Maven相关插件的版本。
2022-01-29 04:49:30 +08:00
carm 6322689d39 Merge pull request #8 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-release-plugin-2.5.3
Bump maven-release-plugin from 2.5.1 to 2.5.3
2022-01-29 03:51:56 +08:00
carm 90fb21b72c Merge pull request #5 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.3.1
Bump maven-javadoc-plugin from 3.2.0 to 3.3.1
2022-01-29 03:51:44 +08:00
dependabot[bot] 47e588dd19 Bump maven-release-plugin from 2.5.1 to 2.5.3
Bumps maven-release-plugin from 2.5.1 to 2.5.3.

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-release-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-28 19:51:28 +00:00
carm c91375f438 Merge pull request #4 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-jar-plugin-3.2.2
Bump maven-jar-plugin from 3.2.0 to 3.2.2
2022-01-29 03:51:26 +08:00
carm b2d2626b31 Merge pull request #6 from CarmJos/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.9.0
Bump maven-compiler-plugin from 3.8.1 to 3.9.0
2022-01-29 03:51:21 +08:00
carm 139c1d743e Merge pull request #7 from CarmJos/dependabot/maven/com.github.chris2018998-beecp-3.3.1
Bump beecp from 3.3.0 to 3.3.1
2022-01-29 03:51:10 +08:00
dependabot[bot] 2aa52c9d7b Bump beecp from 3.3.0 to 3.3.1
Bumps [beecp](https://github.com/Chris2018998/BeeCP) from 3.3.0 to 3.3.1.
- [Release notes](https://github.com/Chris2018998/BeeCP/releases)
- [Commits](https://github.com/Chris2018998/BeeCP/compare/3.3.0...3.3.1)

---
updated-dependencies:
- dependency-name: com.github.chris2018998:beecp
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-28 19:50:27 +00:00
dependabot[bot] ebd1e54a8c Bump maven-compiler-plugin from 3.8.1 to 3.9.0
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.8.1 to 3.9.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.8.1...maven-compiler-plugin-3.9.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-compiler-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-28 19:49:47 +00:00
dependabot[bot] 9ba7afffc3 Bump maven-javadoc-plugin from 3.2.0 to 3.3.1
Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.2.0 to 3.3.1.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.2.0...maven-javadoc-plugin-3.3.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-28 19:49:33 +00:00
dependabot[bot] c4bbbd132e Bump maven-jar-plugin from 3.2.0 to 3.2.2
Bumps [maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.2.0 to 3.2.2.
- [Release notes](https://github.com/apache/maven-jar-plugin/releases)
- [Commits](https://github.com/apache/maven-jar-plugin/compare/maven-jar-plugin-3.2.0...maven-jar-plugin-3.2.2)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-jar-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-28 19:49:07 +00:00
carm 8652d4b824 Create dependabot.yml 2022-01-29 03:48:12 +08:00
carm e8f9b5532e 修改项目名 2022-01-29 03:28:50 +08:00
carm 3dd7702a26 删除名字中用于排序的数字 2022-01-29 03:28:22 +08:00
carm f5d04bb0bb [v0.3.2] 版本更新
- [A] 对于UPDATE类型的SQL操作采用 try-with-resources 形式获取链接与statement,避免中途报错而导致相关流未关闭。
- [U] 声明 setKeyIndex(int) 过时并移除 defaultKeyIndex() 方法,改为更明确的 setReturnGeneratedKeys(boolean) 与 returnGeneratedKeys() 方法,避免填入错误的index。
2022-01-29 03:01:10 +08:00
carm 7d11131b97 [v0.3.1] 修复一些小的规范问题 2022-01-26 22:20:53 +08:00
carm 0850194e82 [v0.3.1] 修复一些小的规范问题 2022-01-26 15:01:30 +08:00
carm ba4731c331 [v0.3.1] 修复一些小的规范问题 2022-01-26 15:00:05 +08:00
carm 36a23af450 [v0.3.1] 修复一些小的规范问题 2022-01-26 14:49:19 +08:00
carm 386093e58b [v0.3.1] 修复Javadoc内容不继承打包的问题 2022-01-26 04:14:01 +08:00
45 changed files with 745 additions and 420 deletions
+5 -2
View File
@@ -1,6 +1,9 @@
--- ---
name: 问题提交 about: 描述问题并提交,帮助我们对其进行检查与修复。 title: '' name: 问题提交
labels: bug assignees: '' about: 描述问题并提交,帮助我们对其进行检查与修复。
title: ''
labels: bug
assignees: ''
--- ---
+5 -3
View File
@@ -1,7 +1,9 @@
--- ---
name: 功能需求 about: 希望我们提供更多的功能。 title: '' name: 功能需求
labels: enhancement assignees: '' about: 希望我们提供更多的功能。
title: ''
labels: enhancement
assignees: ''
--- ---
### **功能简述** ### **功能简述**
+11
View File
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
+15 -3
View File
@@ -48,8 +48,16 @@
<project> <project>
<repositories> <repositories>
<repository> <repository>
<!--采用github依赖库,安全稳定,但需要配置 (推荐)--> <!--采用Maven中心库,安全稳定,但版本更新需要等待同步-->
<id>maven</id>
<name>Maven Central</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<!--采用github依赖库,实时更新,但需要配置 (推荐) -->
<id>EasySQL</id> <id>EasySQL</id>
<name>GitHub Packages</name> <name>GitHub Packages</name>
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url> <url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
@@ -130,7 +138,11 @@
```groovy ```groovy
repositories { repositories {
// 采用github依赖库,安全稳定,但需要配置 (推荐)
// 采用Maven中心库,安全稳定,但版本更新需要等待同步
mavenCentral()
// 采用github依赖库,实时更新,但需要配置 (推荐)
maven { url 'https://maven.pkg.github.com/CarmJos/EasySQL' } maven { url 'https://maven.pkg.github.com/CarmJos/EasySQL' }
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用 // 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
@@ -202,4 +214,4 @@ dependencies {
> MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。 > MIT 协议是所有开源许可中最宽松的一个,除了必须包含许可声明外,再无任何限制。
> >
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。* > *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
</details> </details>
+8 -8
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<version>0.3.0</version> <version>0.3.6</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -19,7 +19,7 @@
<artifactId>easysql-api</artifactId> <artifactId>easysql-api</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>00-EasySQL-API</name> <name>EasySQL-API</name>
<description>EasySQL的接口部分。用于打包到公共项目的API中,避免项目过大。</description> <description>EasySQL的接口部分。用于打包到公共项目的API中,避免项目过大。</description>
<url>https://github.com/CarmJos/EasySQL</url> <url>https://github.com/CarmJos/EasySQL</url>
@@ -44,20 +44,16 @@
<issueManagement> <issueManagement>
<system>GitHub Issues</system> <system>GitHub Issues</system>
<url>${project.url}/issues</url> <url>https://github.com/CarmJos/EasySQL/issues</url>
</issueManagement> </issueManagement>
<ciManagement> <ciManagement>
<system>GitHub Actions</system> <system>GitHub Actions</system>
<url>${project.url}/actions/workflows/maven.yml</url> <url>https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml</url>
</ciManagement> </ciManagement>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
@@ -70,6 +66,10 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@@ -98,7 +98,7 @@ public interface SQLAction<T> {
*/ */
@Nullable @Nullable
default <R> R execute(@NotNull SQLFunction<T, R> function, default <R> R execute(@NotNull SQLFunction<T, R> function,
@Nullable SQLExceptionHandler exceptionHandler) { @Nullable SQLExceptionHandler exceptionHandler) {
return execute(function, null, exceptionHandler); return execute(function, null, exceptionHandler);
} }
@@ -114,8 +114,8 @@ public interface SQLAction<T> {
@Nullable @Nullable
@Contract("_,!null,_ -> !null") @Contract("_,!null,_ -> !null")
default <R> R execute(@NotNull SQLFunction<T, R> function, default <R> R execute(@NotNull SQLFunction<T, R> function,
@Nullable R defaultResult, @Nullable R defaultResult,
@Nullable SQLExceptionHandler exceptionHandler) { @Nullable SQLExceptionHandler exceptionHandler) {
try { try {
return executeFunction(function, defaultResult); return executeFunction(function, defaultResult);
} catch (SQLException exception) { } catch (SQLException exception) {
@@ -133,7 +133,7 @@ public interface SQLAction<T> {
* @throws SQLException 当SQL操作出现问题时抛出 * @throws SQLException 当SQL操作出现问题时抛出
*/ */
@Nullable @Nullable
default <R> R executeFunction(@NotNull SQLFunction<T, R> function) throws SQLException { default <R> R executeFunction(@NotNull SQLFunction<@NotNull T, R> function) throws SQLException {
return executeFunction(function, null); return executeFunction(function, null);
} }
@@ -148,11 +148,10 @@ public interface SQLAction<T> {
*/ */
@Nullable @Nullable
@Contract("_,!null -> !null") @Contract("_,!null -> !null")
default <R> R executeFunction(@NotNull SQLFunction<T, R> function, default <R> R executeFunction(@NotNull SQLFunction<@NotNull T, R> function,
@Nullable R defaultResult) throws SQLException { @Nullable R defaultResult) throws SQLException {
try { try {
T value = execute(); R result = function.apply(execute());
R result = function.apply(value);
return result == null ? defaultResult : result; return result == null ? defaultResult : result;
} catch (SQLException exception) { } catch (SQLException exception) {
throw new SQLException(exception); throw new SQLException(exception);
@@ -182,7 +181,7 @@ public interface SQLAction<T> {
* @param failure 异常处理器 默认为 {@link SQLAction#defaultExceptionHandler()} * @param failure 异常处理器 默认为 {@link SQLAction#defaultExceptionHandler()}
*/ */
void executeAsync(@Nullable SQLHandler<T> success, void executeAsync(@Nullable SQLHandler<T> success,
@Nullable SQLExceptionHandler failure); @Nullable SQLExceptionHandler failure);
default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) { default void handleException(@Nullable SQLExceptionHandler handler, SQLException exception) {
if (handler == null) handler = defaultExceptionHandler(); if (handler == null) handler = defaultExceptionHandler();
@@ -11,11 +11,22 @@ import org.jetbrains.annotations.NotNull;
*/ */
public interface SQLBuilder { public interface SQLBuilder {
/** /**
* 得到承载该Builder的对应{@link SQLManager} * 得到承载该Builder的对应{@link SQLManager}
* *
* @return {@link SQLManager} * @return {@link SQLManager}
*/ */
@NotNull SQLManager getManager(); @NotNull SQLManager getManager();
static @NotNull String withBackQuote(@NotNull String str) {
str = str.trim();
return str.startsWith("`") && str.endsWith("`") ? str : "`" + str + "`";
}
static @NotNull String withQuote(@NotNull String str) {
str = str.trim();
return str.startsWith("'") && str.endsWith("'") ? str : "'" + str + "'";
}
} }
@@ -6,39 +6,50 @@ import java.util.List;
public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Integer>> { public interface PreparedSQLUpdateBatchAction extends SQLAction<List<Integer>> {
/** /**
* 设定多组SQL语句中所有 ? 对应的参数 * 设定多组SQL语句中所有 ? 对应的参数
* *
* @param allParams 所有参数内容 * @param allParams 所有参数内容
* @return {@link PreparedSQLUpdateBatchAction} * @return {@link PreparedSQLUpdateBatchAction}
*/ */
PreparedSQLUpdateBatchAction setAllParams(Iterable<Object[]> allParams); PreparedSQLUpdateBatchAction setAllParams(Iterable<Object[]> allParams);
/** /**
* 添加一组SQL语句中所有 ? 对应的参数 * 添加一组SQL语句中所有 ? 对应的参数
* *
* @param params 参数内容 * @param params 参数内容
* @return {@link PreparedSQLUpdateBatchAction} * @return {@link PreparedSQLUpdateBatchAction}
*/ */
PreparedSQLUpdateBatchAction addParamsBatch(Object... params); PreparedSQLUpdateBatchAction addParamsBatch(Object... params);
/** /**
* 设定自增主键的序列 * 设定自增主键的序列
* *
* @param keyColumnIndex 自增主键的序列 * @param keyColumnIndex 自增主键的序列
* <br>若该值 0,则 {@link #execute()} 返回自增主键数值 * <br>若该值 0,则 {@link #execute()} 返回自增主键数值
* <br>若该值 ≤ 0,则 {@link #execute()} 返回变更的行数 * <br>若该值 ≤ 0,则 {@link #execute()} 返回变更的行数
* @return {@link PreparedSQLUpdateBatchAction} * @return {@link PreparedSQLUpdateBatchAction}
*/ * @see #setReturnGeneratedKeys(boolean)
PreparedSQLUpdateBatchAction setKeyIndex(int keyColumnIndex); */
@Deprecated
default PreparedSQLUpdateBatchAction setKeyIndex(int keyColumnIndex) {
return setReturnGeneratedKeys(keyColumnIndex > 0);
}
/** /**
* 默认主键序列的数值为 -1 (≤0) ,即默认返回发生变更的行数 * 设定该操作返回自增键序列
* *
* @return 默认主键序列 * @return {@link PreparedSQLUpdateBatchAction}
*/ */
default PreparedSQLUpdateBatchAction defaultKeyIndex() { default PreparedSQLUpdateBatchAction returnGeneratedKeys() {
return setKeyIndex(-1); // will return changed lines number return setReturnGeneratedKeys(true);
} }
/**
* 设定该操作是否返回自增键序列。
*
* @return {@link PreparedSQLUpdateBatchAction}
*/
PreparedSQLUpdateBatchAction setReturnGeneratedKeys(boolean returnGeneratedKey);
} }
@@ -4,24 +4,34 @@ import cc.carm.lib.easysql.api.SQLAction;
public interface SQLUpdateAction extends SQLAction<Integer> { public interface SQLUpdateAction extends SQLAction<Integer> {
/** /**
* 设定自增主键的序列 * 设定自增主键的序列
* *
* @param keyColumnIndex 自增主键的序列 * @param keyColumnIndex 自增主键的序列
* <br>若该值 0,则 {@link #execute()} 返回自增主键数值 * <br>若该值 0,则 {@link #execute()} 返回自增主键数值
* <br>若该值 ≤ 0,则 {@link #execute()} 返回变更的行数 * <br>若该值 ≤ 0,则 {@link #execute()} 返回变更的行数
* @return {@link SQLUpdateAction} * @return {@link SQLUpdateAction}
*/ * @see #setReturnGeneratedKey(boolean)
SQLUpdateAction setKeyIndex(int keyColumnIndex); */
@Deprecated
default SQLUpdateAction setKeyIndex(int keyColumnIndex) {
return setReturnGeneratedKey(keyColumnIndex > 0);
}
/** /**
* 默认主键序列的数值为 -1 (≤0) ,即默认返回发生变更的行数 * 设定该操作返回自增键序列
* *
* @return 默认主键序列 * @return {@link SQLUpdateAction}
*/ */
default SQLUpdateAction defaultKeyIndex() { default SQLUpdateAction returnGeneratedKey() {
return setKeyIndex(-1); // will return changed lines number return setReturnGeneratedKey(true);
} }
/**
* 设定该操作是否返回自增键序列。
*
* @return {@link SQLUpdateAction}
*/
SQLUpdateAction setReturnGeneratedKey(boolean returnGeneratedKey);
} }
@@ -15,6 +15,7 @@ public interface SQLUpdateBatchAction extends SQLAction<List<Integer>> {
*/ */
SQLUpdateBatchAction addBatch(@NotNull String sql); SQLUpdateBatchAction addBatch(@NotNull String sql);
@Override
default @NotNull String getSQLContent() { default @NotNull String getSQLContent() {
return getSQLContents().get(0); return getSQLContents().get(0);
} }
@@ -32,20 +32,10 @@ import java.sql.SQLException;
*/ */
public interface QueryAction extends SQLAction<SQLQuery> { public interface QueryAction extends SQLAction<SQLQuery> {
/** @Override
* 执行语句并处理返回值 @Contract("_,!null -> !null")
* default <R> @Nullable R executeFunction(@NotNull SQLFunction<@NotNull SQLQuery, R> function,
* @param defaultResult 默认结果,若处理后的结果为null,则返回该值 @Nullable R defaultResult) throws SQLException {
* @param function 处理方法
* @param <R> 需要返回的内容
* @return 指定类型数据
* @throws SQLException 当SQL操作出现问题时抛出
*/
@Nullable
@Contract("!null, _ -> !null")
default <R> R executeFunction(@Nullable R defaultResult,
@NotNull SQLFunction<SQLQuery, R> function) throws SQLException {
try (SQLQuery value = execute()) { try (SQLQuery value = execute()) {
R result = function.apply(value); R result = function.apply(value);
return result == null ? defaultResult : result; return result == null ? defaultResult : result;
@@ -8,6 +8,10 @@ import cc.carm.lib.easysql.api.enums.NumberType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
import static cc.carm.lib.easysql.api.SQLBuilder.withQuote;
public interface TableCreateBuilder extends SQLBuilder { public interface TableCreateBuilder extends SQLBuilder {
/** /**
@@ -63,7 +67,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
default TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings) { default TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings) {
return addColumn("`" + columnName + "` " + settings); return addColumn(withBackQuote(columnName) + " " + settings);
} }
/** /**
@@ -76,7 +80,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
default TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings, @NotNull String comments) { default TableCreateBuilder addColumn(@NotNull String columnName, @NotNull String settings, @NotNull String comments) {
return addColumn(columnName, settings + " COMMENT '" + comments + "'"); return addColumn(columnName, settings + " COMMENT " + withQuote(comments));
} }
/** /**
@@ -91,7 +95,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType, TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
boolean asPrimaryKey, boolean unsigned); boolean asPrimaryKey, boolean unsigned);
/** /**
* 为该表添加一个INT类型的自增主键列 * 为该表添加一个INT类型的自增主键列
@@ -104,7 +108,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, default TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName,
boolean asPrimaryKey, boolean unsigned) { boolean asPrimaryKey, boolean unsigned) {
return addAutoIncrementColumn(columnName, NumberType.INT, asPrimaryKey, unsigned); return addAutoIncrementColumn(columnName, NumberType.INT, asPrimaryKey, unsigned);
} }
@@ -146,7 +150,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
default TableCreateBuilder setIndex(@NotNull String columnName, default TableCreateBuilder setIndex(@NotNull String columnName,
@NotNull IndexType type) { @NotNull IndexType type) {
return setIndex(type, null, columnName); return setIndex(type, null, columnName);
} }
@@ -164,7 +168,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName, TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName,
@NotNull String columnName, @NotNull String... moreColumns); @NotNull String columnName, @NotNull String... moreColumns);
/** /**
@@ -197,7 +201,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
default TableCreateBuilder addForeignKey(@NotNull String tableColumn, default TableCreateBuilder addForeignKey(@NotNull String tableColumn,
@NotNull String foreignTable, @NotNull String foreignColumn) { @NotNull String foreignTable, @NotNull String foreignColumn) {
return addForeignKey(tableColumn, null, foreignTable, foreignColumn); return addForeignKey(tableColumn, null, foreignTable, foreignColumn);
} }
@@ -217,7 +221,7 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
default TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName, default TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
@NotNull String foreignTable, @NotNull String foreignColumn) { @NotNull String foreignTable, @NotNull String foreignColumn) {
return addForeignKey(tableColumn, constraintName, foreignTable, foreignColumn, null, null); return addForeignKey(tableColumn, constraintName, foreignTable, foreignColumn, null, null);
} }
@@ -239,8 +243,8 @@ public interface TableCreateBuilder extends SQLBuilder {
* @return {@link TableCreateBuilder} * @return {@link TableCreateBuilder}
*/ */
TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName, TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
@NotNull String foreignTable, @NotNull String foreignColumn, @NotNull String foreignTable, @NotNull String foreignColumn,
@Nullable ForeignKeyRule updateRule, @Nullable ForeignKeyRule deleteRule); @Nullable ForeignKeyRule updateRule, @Nullable ForeignKeyRule deleteRule);
default String defaultTablesSettings() { default String defaultTablesSettings() {
return "ENGINE=InnoDB DEFAULT CHARSET=utf8"; return "ENGINE=InnoDB DEFAULT CHARSET=utf8";
@@ -28,7 +28,7 @@ public enum ForeignKeyRule {
*/ */
CASCADE("CASCADE"); CASCADE("CASCADE");
String ruleName; final String ruleName;
ForeignKeyRule(String ruleName) { ForeignKeyRule(String ruleName) {
this.ruleName = ruleName; this.ruleName = ruleName;
@@ -29,7 +29,7 @@ public enum IndexType {
FULLTEXT_INDEX("FULLTEXT"); FULLTEXT_INDEX("FULLTEXT");
String name; final String name;
IndexType(String name) { IndexType(String name) {
this.name = name; this.name = name;
+8 -4
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>0.3.0</version> <version>0.3.6</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -19,7 +19,7 @@
<artifactId>easysql-impl</artifactId> <artifactId>easysql-impl</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>01-EasySQL-Impl</name> <name>EasySQL-Impl</name>
<description>EasySQL的实现部分。</description> <description>EasySQL的实现部分。</description>
<url>https://github.com/CarmJos/EasySQL</url> <url>https://github.com/CarmJos/EasySQL</url>
@@ -44,12 +44,12 @@
<issueManagement> <issueManagement>
<system>GitHub Issues</system> <system>GitHub Issues</system>
<url>${project.url}/issues</url> <url>https://github.com/CarmJos/EasySQL/issues</url>
</issueManagement> </issueManagement>
<ciManagement> <ciManagement>
<system>GitHub Actions</system> <system>GitHub Actions</system>
<url>${project.url}/actions/workflows/maven.yml</url> <url>https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml</url>
</ciManagement> </ciManagement>
<dependencies> <dependencies>
@@ -77,6 +77,10 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
@@ -65,7 +65,7 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
} }
protected void outputDebugMessage() { protected void outputDebugMessage() {
getManager().debug("#" + getShortID() + " -> { " + getSQLContent() + " }"); getManager().debug("# " + getShortID() + " -> { " + getSQLContent() + " }");
} }
@Override @Override
@@ -15,63 +15,60 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class PreparedSQLBatchUpdateActionImpl public class PreparedSQLBatchUpdateActionImpl
extends AbstractSQLAction<List<Integer>> extends AbstractSQLAction<List<Integer>>
implements PreparedSQLUpdateBatchAction { implements PreparedSQLUpdateBatchAction {
int keyIndex = -1; boolean returnKeys = false;
List<Object[]> allParams; List<Object[]> allParams;
public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) { public PreparedSQLBatchUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql); super(manager, sql);
this.allParams = new ArrayList<>(); this.allParams = new ArrayList<>();
} }
@Override @Override
public PreparedSQLUpdateBatchAction setAllParams(Iterable<Object[]> allParams) { public PreparedSQLUpdateBatchAction setAllParams(Iterable<Object[]> allParams) {
List<Object[]> paramsList = new ArrayList<>(); List<Object[]> paramsList = new ArrayList<>();
allParams.forEach(paramsList::add); allParams.forEach(paramsList::add);
this.allParams = paramsList; this.allParams = paramsList;
return this; return this;
} }
@Override @Override
public PreparedSQLUpdateBatchAction addParamsBatch(Object[] params) { public PreparedSQLUpdateBatchAction addParamsBatch(Object... params) {
this.allParams.add(params); this.allParams.add(params);
return this; return this;
} }
@Override @Override
public PreparedSQLUpdateBatchAction setKeyIndex(int keyColumnIndex) { public PreparedSQLUpdateBatchAction setReturnGeneratedKeys(boolean returnGeneratedKey) {
this.keyIndex = keyColumnIndex; this.returnKeys = returnGeneratedKey;
return this; return this;
} }
@Override @Override
public @NotNull List<Integer> execute() throws SQLException { public @NotNull List<Integer> execute() throws SQLException {
List<Integer> returnedValues; try (Connection connection = getManager().getConnection()) {
Connection connection = getManager().getConnection(); try (PreparedStatement statement = StatementUtil.createPrepareStatementBatch(
PreparedStatement statement = StatementUtil.createPrepareStatementBatch( connection, getSQLContent(), allParams, returnKeys
connection, getSQLContent(), allParams, keyIndex > 0 )) {
);
outputDebugMessage();
if (keyIndex > 0) {
statement.executeBatch();
List<Integer> generatedKeys = new ArrayList<>();
ResultSet resultSet = statement.getGeneratedKeys();
if (resultSet != null) {
while (resultSet.next()) generatedKeys.add(resultSet.getInt(keyIndex));
resultSet.close();
}
returnedValues = generatedKeys;
} else {
int[] executed = statement.executeBatch();
returnedValues = Arrays.stream(executed).boxed().collect(Collectors.toList());
}
statement.close(); outputDebugMessage();
connection.close(); int[] executed = statement.executeBatch();
return returnedValues; if (!returnKeys) return Arrays.stream(executed).boxed().collect(Collectors.toList());
} else {
try (ResultSet resultSet = statement.getGeneratedKeys()) {
List<Integer> generatedKeys = new ArrayList<>();
while (resultSet.next()) {
generatedKeys.add(resultSet.getInt(1));
}
return generatedKeys;
}
}
}
}
}
} }
@@ -24,18 +24,18 @@ public class PreparedSQLUpdateActionImpl
} }
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql, public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
@Nullable List<Object> params) { @Nullable List<Object> params) {
this(manager, sql, params == null ? null : params.toArray()); this(manager, sql, params == null ? null : params.toArray());
} }
public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql, public PreparedSQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql,
@Nullable Object[] params) { @Nullable Object[] params) {
super(manager, sql); super(manager, sql);
this.params = params; this.params = params;
} }
@Override @Override
public PreparedSQLUpdateActionImpl setParams(Object[] params) { public PreparedSQLUpdateActionImpl setParams(Object... params) {
this.params = params; this.params = params;
return this; return this;
} }
@@ -53,28 +53,25 @@ public class PreparedSQLUpdateActionImpl
@Override @Override
public @NotNull Integer execute() throws SQLException { public @NotNull Integer execute() throws SQLException {
int value = -1; try (Connection connection = getManager().getConnection()) {
try (PreparedStatement statement = StatementUtil.createPrepareStatement(
connection, getSQLContent(), params, returnGeneratedKeys
)) {
outputDebugMessage();
int changes = statement.executeUpdate();
if (!returnGeneratedKeys) return changes;
else {
try (ResultSet resultSet = statement.getGeneratedKeys()) {
return resultSet.next() ? resultSet.getInt(1) : -1;
}
}
Connection connection = getManager().getConnection();
PreparedStatement statement = StatementUtil.createPrepareStatement(
connection, getSQLContent(), params, keyIndex > 0
);
outputDebugMessage();
if (keyIndex > 0) {
statement.executeUpdate();
ResultSet resultSet = statement.getGeneratedKeys();
if (resultSet != null) {
if (resultSet.next()) value = resultSet.getInt(keyIndex);
resultSet.close();
} }
} else {
value = statement.executeUpdate();
} }
statement.close();
connection.close();
return value;
} }
} }
@@ -13,42 +13,36 @@ public class SQLUpdateActionImpl
extends AbstractSQLAction<Integer> extends AbstractSQLAction<Integer>
implements SQLUpdateAction { implements SQLUpdateAction {
int keyIndex = -1; boolean returnGeneratedKeys = false;
public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) { public SQLUpdateActionImpl(@NotNull SQLManagerImpl manager, @NotNull String sql) {
super(manager, sql); super(manager, sql);
} }
@Override @Override
public @NotNull Integer execute() throws SQLException { public @NotNull Integer execute() throws SQLException {
int returnedValue = -1; try (Connection connection = getManager().getConnection()) {
Connection connection = getManager().getConnection(); try (Statement statement = connection.createStatement()) {
Statement statement = connection.createStatement(); outputDebugMessage();
outputDebugMessage();
if (keyIndex > 0) {
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
ResultSet resultSet = statement.getGeneratedKeys();
if (resultSet != null) {
if (resultSet.next()) {
returnedValue = resultSet.getInt(keyIndex);
}
resultSet.close();
}
} else {
returnedValue = statement.executeUpdate(getSQLContent());
}
statement.close(); if (!returnGeneratedKeys) {
connection.close(); return statement.executeUpdate(getSQLContent());
} else {
statement.executeUpdate(getSQLContent(), Statement.RETURN_GENERATED_KEYS);
return returnedValue; try (ResultSet resultSet = statement.getGeneratedKeys()) {
} return resultSet.next() ? resultSet.getInt(1) : -1;
}
}
}
}
}
@Override @Override
public SQLUpdateActionImpl setKeyIndex(int keyIndex) { public SQLUpdateAction setReturnGeneratedKey(boolean returnGeneratedKey) {
this.keyIndex = keyIndex; this.returnGeneratedKeys = returnGeneratedKey;
return this; return this;
} }
} }
@@ -36,27 +36,28 @@ public class SQLUpdateBatchActionImpl
@Override @Override
public @NotNull List<Integer> execute() throws SQLException { public @NotNull List<Integer> execute() throws SQLException {
Connection connection = getManager().getConnection(); try (Connection connection = getManager().getConnection()) {
Statement statement = connection.createStatement();
outputDebugMessage(); try (Statement statement = connection.createStatement()) {
outputDebugMessage();
for (String content : this.sqlContents) {
statement.addBatch(content);
}
int[] executed = statement.executeBatch();
return Arrays.stream(executed).boxed().collect(Collectors.toList());
}
for (String content : this.sqlContents) {
statement.addBatch(content);
} }
int[] executed = statement.executeBatch();
List<Integer> returnedValues = Arrays.stream(executed).boxed().collect(Collectors.toList());
statement.close();
connection.close();
return returnedValues;
} }
@Override @Override
protected void outputDebugMessage() { protected void outputDebugMessage() {
getManager().debug("#" + getShortID() + " -> {"); getManager().debug("# " + getShortID() + " -> [");
for (String content : getSQLContents()) getManager().debug(" " + content); for (String content : getSQLContents()) getManager().debug(" { " + content + " }");
getManager().debug("}"); getManager().debug("]");
} }
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -25,7 +24,7 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
} }
@Override @Override
public PreparedQueryActionImpl setParams(@Nullable Object[] params) { public PreparedQueryActionImpl setParams(@Nullable Object... params) {
this.params = params; this.params = params;
return this; return this;
} }
@@ -54,21 +53,34 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
Connection connection = getManager().getConnection(); Connection connection = getManager().getConnection();
PreparedStatement preparedStatement; PreparedStatement preparedStatement;
if (handler == null) { try {
preparedStatement = StatementUtil.createPrepareStatement(connection, getSQLContent(), this.params); if (handler == null) {
} else { preparedStatement = StatementUtil.createPrepareStatement(connection, getSQLContent(), this.params);
preparedStatement = connection.prepareStatement(getSQLContent()); } else {
handler.accept(preparedStatement); preparedStatement = connection.prepareStatement(getSQLContent());
handler.accept(preparedStatement);
}
} catch (SQLException exception) {
connection.close();
throw exception;
} }
long executeTime = System.currentTimeMillis(); try {
ResultSet resultSet = preparedStatement.executeQuery(); long executeTime = System.currentTimeMillis();
SQLQueryImpl query = new SQLQueryImpl(
getManager(), this,
connection, preparedStatement,
preparedStatement.executeQuery(),
executeTime
);
getManager().getActiveQuery().put(getActionUUID(), query);
return new SQLQueryImpl( return query;
getManager(), this, } catch (SQLException exception) {
connection, preparedStatement, resultSet, preparedStatement.close();
executeTime connection.close();
); throw exception;
}
} }
} }
@@ -10,7 +10,6 @@ import cc.carm.lib.easysql.query.SQLQueryImpl;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
@@ -24,21 +23,32 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
public @NotNull SQLQueryImpl execute() throws SQLException { public @NotNull SQLQueryImpl execute() throws SQLException {
Connection connection = getManager().getConnection(); Connection connection = getManager().getConnection();
Statement statement = connection.createStatement(); Statement statement;
try {
statement = connection.createStatement();
} catch (SQLException ex) {
connection.close();
throw ex;
}
outputDebugMessage(); outputDebugMessage();
try {
long executeTime = System.currentTimeMillis();
SQLQueryImpl query = new SQLQueryImpl(
getManager(), this,
connection, statement,
statement.executeQuery(getSQLContent()),
executeTime
);
getManager().getActiveQuery().put(getActionUUID(), query);
long executeTime = System.currentTimeMillis(); return query;
ResultSet resultSet = statement.executeQuery(getSQLContent()); } catch (SQLException exception) {
SQLQueryImpl query = new SQLQueryImpl( statement.close();
getManager(), this, connection.close();
connection, statement, resultSet, throw exception;
executeTime }
);
getManager().getActiveQuery().put(getActionUUID(), query);
return query;
} }
@@ -14,6 +14,8 @@ import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B, T>, T extends SQLAction<?>> public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B, T>, T extends SQLAction<?>>
extends AbstractSQLBuilder implements ConditionalBuilder<B, T> { extends AbstractSQLBuilder implements ConditionalBuilder<B, T> {
@@ -53,7 +55,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
public B addCondition( public B addCondition(
@NotNull String queryName, @NotNull String operator, @Nullable Object queryValue @NotNull String queryName, @NotNull String operator, @Nullable Object queryValue
) { ) {
addCondition("`" + queryName + "` " + operator + " ?"); addCondition(withBackQuote(queryName) + " " + operator + " ?");
this.conditionParams.add(queryValue); this.conditionParams.add(queryValue);
return getThis(); return getThis();
} }
@@ -62,7 +64,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
public B addCondition( public B addCondition(
@NotNull String[] queryNames, @Nullable Object[] queryValues @NotNull String[] queryNames, @Nullable Object[] queryValues
) { ) {
if (queryNames.length != queryValues.length) { if (queryValues == null || queryNames.length != queryValues.length) {
throw new RuntimeException("queryNames are not match with queryValues"); throw new RuntimeException("queryNames are not match with queryValues");
} }
for (int i = 0; i < queryNames.length; i++) { for (int i = 0; i < queryNames.length; i++) {
@@ -74,7 +76,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
@Override @Override
public B addNotNullCondition(@NotNull String queryName) { public B addNotNullCondition(@NotNull String queryName) {
return addCondition("`" + queryName + "` IS NOT NULL"); return addCondition(withBackQuote(queryName) + " IS NOT NULL");
} }
@@ -84,7 +86,7 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
) { ) {
if (startDate == null && endDate == null) return getThis(); // 都不限定时间,不用判断了 if (startDate == null && endDate == null) return getThis(); // 都不限定时间,不用判断了
if (startDate != null) { if (startDate != null) {
addCondition("`" + queryName + "` BETWEEN ? AND ?"); addCondition(withBackQuote(queryName) + " BETWEEN ? AND ?");
this.conditionParams.add(startDate); this.conditionParams.add(startDate);
if (endDate != null) { if (endDate != null) {
this.conditionParams.add(endDate); this.conditionParams.add(endDate);
@@ -118,9 +120,9 @@ public abstract class AbstractConditionalBuilder<B extends ConditionalBuilder<B,
Iterator<String> iterator = conditionSQLs.iterator(); Iterator<String> iterator = conditionSQLs.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
conditionBuilder.append(iterator.next()); conditionBuilder.append(iterator.next());
if (iterator.hasNext()) conditionBuilder.append(" "); if (iterator.hasNext()) conditionBuilder.append(" AND ");
} }
return conditionBuilder.toString(); return conditionBuilder.toString().trim();
} else { } else {
return null; return null;
} }
@@ -7,6 +7,8 @@ import cc.carm.lib.easysql.api.builder.DeleteBuilder;
import cc.carm.lib.easysql.manager.SQLManagerImpl; import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public class DeleteBuilderImpl public class DeleteBuilderImpl
extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Integer>> extends AbstractConditionalBuilder<DeleteBuilder, SQLAction<Integer>>
implements DeleteBuilder { implements DeleteBuilder {
@@ -23,7 +25,7 @@ public class DeleteBuilderImpl
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("DELETE FROM `").append(getTableName()).append("`"); sqlBuilder.append("DELETE FROM ").append(withBackQuote(getTableName()));
if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL()); if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL());
if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL()); if (limit > 0) sqlBuilder.append(" ").append(buildLimitSQL());
@@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public abstract class InsertBuilderImpl<T extends SQLAction<?>> public abstract class InsertBuilderImpl<T extends SQLAction<?>>
extends AbstractSQLBuilder implements InsertBuilder<T> { extends AbstractSQLBuilder implements InsertBuilder<T> {
@@ -23,10 +25,10 @@ public abstract class InsertBuilderImpl<T extends SQLAction<?>>
int valueLength = columnNames.size(); int valueLength = columnNames.size();
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("INSERT IGNORE INTO `").append(tableName).append("`("); sqlBuilder.append("INSERT IGNORE INTO ").append(withBackQuote(tableName)).append("(");
Iterator<String> iterator = columnNames.iterator(); Iterator<String> iterator = columnNames.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
sqlBuilder.append("`").append(iterator.next()).append("`"); sqlBuilder.append(withBackQuote(iterator.next()));
if (iterator.hasNext()) sqlBuilder.append(", "); if (iterator.hasNext()) sqlBuilder.append(", ");
} }
@@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public abstract class ReplaceBuilderImpl<T extends SQLAction<?>> public abstract class ReplaceBuilderImpl<T extends SQLAction<?>>
extends AbstractSQLBuilder implements ReplaceBuilder<T> { extends AbstractSQLBuilder implements ReplaceBuilder<T> {
@@ -23,10 +25,10 @@ public abstract class ReplaceBuilderImpl<T extends SQLAction<?>>
int valueLength = columnNames.size(); int valueLength = columnNames.size();
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("REPLACE INTO `").append(tableName).append("`("); sqlBuilder.append("REPLACE INTO ").append(withBackQuote(tableName)).append("(");
Iterator<String> iterator = columnNames.iterator(); Iterator<String> iterator = columnNames.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
sqlBuilder.append("`").append(iterator.next()).append("`"); sqlBuilder.append(withBackQuote(iterator.next()));
if (iterator.hasNext()) sqlBuilder.append(", "); if (iterator.hasNext()) sqlBuilder.append(", ");
} }
@@ -9,6 +9,9 @@ import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
import static cc.carm.lib.easysql.api.SQLBuilder.withQuote;
public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAlterBuilder { public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAlterBuilder {
protected final @NotNull String tableName; protected final @NotNull String tableName;
@@ -25,28 +28,28 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
@Override @Override
public SQLAction<Integer> renameTo(@NotNull String newTableName) { public SQLAction<Integer> renameTo(@NotNull String newTableName) {
return new SQLUpdateActionImpl(getManager(), return new SQLUpdateActionImpl(getManager(),
"ALTER TABLE `" + getTableName() + "` RENAME TO `" + newTableName + "`" "ALTER TABLE " + withBackQuote(getTableName()) + " RENAME TO " + withBackQuote(newTableName) + ""
); );
} }
@Override @Override
public SQLAction<Integer> changeComment(@NotNull String newTableComment) { public SQLAction<Integer> changeComment(@NotNull String newTableComment) {
return new SQLUpdateActionImpl(getManager(), return new SQLUpdateActionImpl(getManager(),
"ALTER TABLE `" + getTableName() + "` COMMENT '" + newTableComment + "'" "ALTER TABLE " + withBackQuote(getTableName()) + " COMMENT " + withQuote(newTableComment)
); );
} }
@Override @Override
public SQLAction<Integer> setAutoIncrementIndex(int index) { public SQLAction<Integer> setAutoIncrementIndex(int index) {
return new SQLUpdateActionImpl(getManager(), return new SQLUpdateActionImpl(getManager(),
"ALTER TABLE `" + getTableName() + "` AUTO_INCREMENT=" + index "ALTER TABLE " + withBackQuote(getTableName()) + " AUTO_INCREMENT=" + index
); );
} }
@Override @Override
public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @NotNull String indexName, @NotNull String columnName, @NotNull String... moreColumns) { public SQLAction<Integer> addIndex(@NotNull IndexType indexType, @NotNull String indexName, @NotNull String columnName, @NotNull String... moreColumns) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` ADD " "ALTER TABLE " + withBackQuote(getTableName()) + " ADD "
+ TableCreateBuilderImpl.buildIndexSettings(indexType, indexName, columnName, moreColumns) + TableCreateBuilderImpl.buildIndexSettings(indexType, indexName, columnName, moreColumns)
); );
} }
@@ -54,21 +57,21 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
@Override @Override
public SQLAction<Integer> dropIndex(@NotNull String indexName) { public SQLAction<Integer> dropIndex(@NotNull String indexName) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` DROP INDEX `" + indexName + "`" "ALTER TABLE " + withBackQuote(getTableName()) + " DROP INDEX " + withBackQuote(indexName)
); );
} }
@Override @Override
public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) { public SQLAction<Integer> dropForeignKey(@NotNull String keySymbol) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` DROP FOREIGN KEY `" + keySymbol + "`" "ALTER TABLE " + withBackQuote(getTableName()) + " DROP FOREIGN KEY " + withBackQuote(keySymbol)
); );
} }
@Override @Override
public SQLAction<Integer> dropPrimaryKey() { public SQLAction<Integer> dropPrimaryKey() {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` DROP PRIMARY KEY" "ALTER TABLE " + withBackQuote(getTableName()) + " DROP PRIMARY KEY"
); );
} }
@@ -77,14 +80,14 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
String orderSettings = null; String orderSettings = null;
if (afterColumn != null) { if (afterColumn != null) {
if (afterColumn.length() > 0) { if (afterColumn.length() > 0) {
orderSettings = "AFTER `" + afterColumn + "`"; orderSettings = "AFTER " + withBackQuote(afterColumn);
} else { } else {
orderSettings = "FIRST"; orderSettings = "FIRST";
} }
} }
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` ADD `" + columnName + "` " + settings "ALTER TABLE " + withBackQuote(getTableName()) + " ADD " + withBackQuote(columnName) + " " + settings
+ (orderSettings != null ? " " + orderSettings : "") + (orderSettings != null ? " " + orderSettings : "")
); );
} }
@@ -92,35 +95,35 @@ public class TableAlterBuilderImpl extends AbstractSQLBuilder implements TableAl
@Override @Override
public SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName) { public SQLAction<Integer> renameColumn(@NotNull String columnName, @NotNull String newName) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` RENAME COLUMN `" + columnName + "` TO `" + newName + "`" "ALTER TABLE " + withBackQuote(getTableName()) + " RENAME COLUMN " + withBackQuote(columnName) + " TO " + withBackQuote(newName)
); );
} }
@Override @Override
public SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings) { public SQLAction<Integer> modifyColumn(@NotNull String columnName, @NotNull String settings) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` MODIFY COLUMN `" + columnName + "` " + settings "ALTER TABLE " + withBackQuote(getTableName()) + " MODIFY COLUMN " + withBackQuote(columnName) + " " + settings
); );
} }
@Override @Override
public SQLAction<Integer> removeColumn(@NotNull String columnName) { public SQLAction<Integer> removeColumn(@NotNull String columnName) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` DROP `" + columnName + "`" "ALTER TABLE " + withBackQuote(getTableName()) + " DROP " + withBackQuote(columnName)
); );
} }
@Override @Override
public SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) { public SQLAction<Integer> setColumnDefault(@NotNull String columnName, @NotNull String defaultValue) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` ALTER `" + columnName + "` SET DEFAULT " + defaultValue "ALTER TABLE " + withBackQuote(getTableName()) + " ALTER " + withBackQuote(columnName) + " SET DEFAULT " + defaultValue
); );
} }
@Override @Override
public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) { public SQLAction<Integer> removeColumnDefault(@NotNull String columnName) {
return createAction( return createAction(
"ALTER TABLE `" + getTableName() + "` ALTER `" + columnName + "` DROP DEFAULT" "ALTER TABLE " + withBackQuote(getTableName()) + " ALTER " + withBackQuote(columnName) + " DROP DEFAULT"
); );
} }
@@ -15,6 +15,9 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
import static cc.carm.lib.easysql.api.SQLBuilder.withQuote;
public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableCreateBuilder { public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableCreateBuilder {
protected final @NotNull String tableName; protected final @NotNull String tableName;
@@ -44,7 +47,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
@Override @Override
public SQLUpdateAction build() { public SQLUpdateAction build() {
StringBuilder createSQL = new StringBuilder(); StringBuilder createSQL = new StringBuilder();
createSQL.append("CREATE TABLE IF NOT EXISTS `").append(tableName).append("`"); createSQL.append("CREATE TABLE IF NOT EXISTS ").append(withBackQuote(tableName));
createSQL.append("("); createSQL.append("(");
createSQL.append(String.join(", ", columns)); createSQL.append(String.join(", ", columns));
if (indexes.size() > 0) { if (indexes.size() > 0) {
@@ -58,7 +61,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
createSQL.append(") ").append(getTableSettings()); createSQL.append(") ").append(getTableSettings());
if (tableComment != null) { if (tableComment != null) {
createSQL.append(" COMMENT '").append(tableComment).append("'"); createSQL.append(" COMMENT ").append(withQuote(tableComment));
} }
return new SQLUpdateActionImpl(getManager(), createSQL.toString()); return new SQLUpdateActionImpl(getManager(), createSQL.toString());
@@ -72,7 +75,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
@Override @Override
public TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType, public TableCreateBuilder addAutoIncrementColumn(@NotNull String columnName, @Nullable NumberType numberType,
boolean asPrimaryKey, boolean unsigned) { boolean asPrimaryKey, boolean unsigned) {
return addColumn(columnName, return addColumn(columnName,
(numberType == null ? NumberType.INT : numberType).name() (numberType == null ? NumberType.INT : numberType).name()
+ (unsigned ? " UNSIGNED " : " ") + (unsigned ? " UNSIGNED " : " ")
@@ -82,26 +85,26 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
@Override @Override
public TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName, public TableCreateBuilder setIndex(@NotNull IndexType type, @Nullable String indexName,
@NotNull String columnName, @NotNull String... moreColumns) { @NotNull String columnName, @NotNull String... moreColumns) {
this.indexes.add(buildIndexSettings(type, indexName, columnName, moreColumns)); this.indexes.add(buildIndexSettings(type, indexName, columnName, moreColumns));
return this; return this;
} }
@Override @Override
public TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName, public TableCreateBuilder addForeignKey(@NotNull String tableColumn, @Nullable String constraintName,
@NotNull String foreignTable, @NotNull String foreignColumn, @NotNull String foreignTable, @NotNull String foreignColumn,
@Nullable ForeignKeyRule updateRule, @Nullable ForeignKeyRule deleteRule) { @Nullable ForeignKeyRule updateRule, @Nullable ForeignKeyRule deleteRule) {
StringBuilder keyBuilder = new StringBuilder(); StringBuilder keyBuilder = new StringBuilder();
keyBuilder.append("CONSTRAINT "); keyBuilder.append("CONSTRAINT ");
if (constraintName == null) { if (constraintName == null) {
keyBuilder.append("`").append("fk_").append(tableColumn).append("_").append(foreignTable).append("`"); keyBuilder.append(withBackQuote("fk_" + tableColumn + "_" + foreignTable));
} else { } else {
keyBuilder.append("`").append(constraintName).append("`"); keyBuilder.append(withBackQuote(constraintName));
} }
keyBuilder.append(" "); keyBuilder.append(" ");
keyBuilder.append("FOREIGN KEY (`").append(tableColumn).append("`) "); keyBuilder.append("FOREIGN KEY (").append(withBackQuote(tableColumn)).append(") ");
keyBuilder.append("REFERENCES `").append(foreignTable).append("`(`").append(foreignColumn).append("`)"); keyBuilder.append("REFERENCES ").append(withBackQuote(foreignTable)).append("(").append(withBackQuote(foreignColumn)).append(")");
if (updateRule != null) keyBuilder.append(" ON UPDATE ").append(updateRule.getRuleName()); if (updateRule != null) keyBuilder.append(" ON UPDATE ").append(updateRule.getRuleName());
if (deleteRule != null) keyBuilder.append(" ON DELETE ").append(deleteRule.getRuleName()); if (deleteRule != null) keyBuilder.append(" ON DELETE ").append(deleteRule.getRuleName());
@@ -111,7 +114,7 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
} }
@Override @Override
public TableCreateBuilder setColumns(@NotNull String[] columns) { public TableCreateBuilder setColumns(@NotNull String... columns) {
this.columns = Arrays.asList(columns); this.columns = Arrays.asList(columns);
return this; return this;
} }
@@ -129,16 +132,16 @@ public class TableCreateBuilderImpl extends AbstractSQLBuilder implements TableC
} }
protected static String buildIndexSettings(@NotNull IndexType indexType, @Nullable String indexName, protected static String buildIndexSettings(@NotNull IndexType indexType, @Nullable String indexName,
@NotNull String columnName, @NotNull String... moreColumns) { @NotNull String columnName, @NotNull String... moreColumns) {
StringBuilder indexBuilder = new StringBuilder(); StringBuilder indexBuilder = new StringBuilder();
indexBuilder.append(indexType.getName()).append(" "); indexBuilder.append(indexType.getName()).append(" ");
if (indexName != null) { if (indexName != null) {
indexBuilder.append("`").append(indexName).append("`"); indexBuilder.append(withBackQuote(indexName));
} }
indexBuilder.append("("); indexBuilder.append("(");
indexBuilder.append("`").append(columnName).append("`"); indexBuilder.append(withBackQuote(columnName));
if (moreColumns.length > 0) { if (moreColumns.length > 0) {
indexBuilder.append(", "); indexBuilder.append(", ");
@@ -7,81 +7,83 @@ import cc.carm.lib.easysql.manager.SQLManagerImpl;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public class TableQueryBuilderImpl public class TableQueryBuilderImpl
extends AbstractConditionalBuilder<TableQueryBuilder, PreparedQueryAction> extends AbstractConditionalBuilder<TableQueryBuilder, PreparedQueryAction>
implements TableQueryBuilder { implements TableQueryBuilder {
@NotNull String tableName; @NotNull String tableName;
String[] columns; String[] columns;
@Nullable String orderBy; @Nullable String orderBy;
int[] pageLimit; int[] pageLimit;
public TableQueryBuilderImpl(@NotNull SQLManagerImpl manager, @NotNull String tableName) { public TableQueryBuilderImpl(@NotNull SQLManagerImpl manager, @NotNull String tableName) {
super(manager); super(manager);
this.tableName = tableName; this.tableName = tableName;
} }
@Override @Override
public PreparedQueryActionImpl build() { public PreparedQueryActionImpl build() {
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("SELECT").append(" "); sqlBuilder.append("SELECT").append(" ");
if (columns == null || columns.length < 1) { if (columns == null || columns.length < 1) {
sqlBuilder.append("*"); sqlBuilder.append("*");
} else { } else {
for (int i = 0; i < columns.length; i++) { for (int i = 0; i < columns.length; i++) {
String name = columns[i]; String name = columns[i];
sqlBuilder.append("`").append(name).append("`"); sqlBuilder.append(withBackQuote(name));
if (i != columns.length - 1) { if (i != columns.length - 1) {
sqlBuilder.append(","); sqlBuilder.append(",");
} }
} }
} }
sqlBuilder.append(" ").append("FROM").append(" "); sqlBuilder.append(" ").append("FROM").append(" ").append(withBackQuote(tableName));
sqlBuilder.append("`").append(tableName).append("`");
if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL()); if (hasConditions()) sqlBuilder.append(" ").append(buildConditionSQL());
if (pageLimit != null && pageLimit.length == 2) { if (orderBy != null) sqlBuilder.append(" ").append(orderBy);
sqlBuilder.append(" LIMIT ").append(pageLimit[0]).append(",").append(pageLimit[1]);
} else if (limit > 0) {
sqlBuilder.append(" ").append(buildLimitSQL());
}
if (orderBy != null) sqlBuilder.append(orderBy); if (pageLimit != null && pageLimit.length == 2) {
sqlBuilder.append(" LIMIT ").append(pageLimit[0]).append(",").append(pageLimit[1]);
} else if (limit > 0) {
sqlBuilder.append(" ").append(buildLimitSQL());
}
return new PreparedQueryActionImpl(getManager(), sqlBuilder.toString())
.setParams(hasConditionParams() ? getConditionParams() : null);
}
@Override return new PreparedQueryActionImpl(getManager(), sqlBuilder.toString())
public @NotNull String getTableName() { .setParams(hasConditionParams() ? getConditionParams() : null);
return tableName; }
}
@Override @Override
public TableQueryBuilderImpl selectColumns(@NotNull String[] columnNames) { public @NotNull String getTableName() {
this.columns = columnNames; return tableName;
return this; }
}
@Override @Override
public TableQueryBuilder orderBy(@NotNull String columnName, boolean asc) { public TableQueryBuilderImpl selectColumns(@NotNull String... columnNames) {
this.orderBy = "ORDER BY `" + columnName + "` " + (asc ? "ASC" : "DESC"); this.columns = columnNames;
return this; return this;
} }
@Override @Override
public TableQueryBuilder setPageLimit(int start, int end) { public TableQueryBuilder orderBy(@NotNull String columnName, boolean asc) {
this.pageLimit = new int[]{start, end}; this.orderBy = "ORDER BY " + withBackQuote(columnName) + " " + (asc ? "ASC" : "DESC");
return this; return this;
} }
@Override @Override
protected TableQueryBuilderImpl getThis() { public TableQueryBuilder setPageLimit(int start, int end) {
return this; this.pageLimit = new int[]{start, end};
} return this;
}
@Override
protected TableQueryBuilderImpl getThis() {
return this;
}
} }
@@ -9,6 +9,8 @@ import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;
import static cc.carm.lib.easysql.api.SQLBuilder.withBackQuote;
public class UpdateBuilderImpl public class UpdateBuilderImpl
extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Integer>> extends AbstractConditionalBuilder<UpdateBuilder, SQLAction<Integer>>
implements UpdateBuilder { implements UpdateBuilder {
@@ -28,11 +30,11 @@ public class UpdateBuilderImpl
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("UPDATE `").append(getTableName()).append("` SET "); sqlBuilder.append("UPDATE ").append(withBackQuote(getTableName())).append(" SET ");
Iterator<String> iterator = this.columnNames.iterator(); Iterator<String> iterator = this.columnNames.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
sqlBuilder.append("`").append(iterator.next()).append("` = ?"); sqlBuilder.append(withBackQuote(iterator.next())).append(" = ?");
if (iterator.hasNext()) sqlBuilder.append(" , "); if (iterator.hasNext()) sqlBuilder.append(" , ");
} }
List<Object> allParams = new ArrayList<>(this.columnValues); List<Object> allParams = new ArrayList<>(this.columnValues);
@@ -62,6 +62,7 @@ public class SQLManagerImpl implements SQLManager {
if (isDebugMode()) getLogger().info("[DEBUG] " + msg); if (isDebugMode()) getLogger().info("[DEBUG] " + msg);
} }
@Override
public Logger getLogger() { public Logger getLogger() {
return LOGGER; return LOGGER;
} }
@@ -103,7 +104,7 @@ public class SQLManagerImpl implements SQLManager {
} }
@Override @Override
public List<Integer> executeSQLBatch(@NotNull String sql, String[] moreSQL) { public List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL) {
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, sql); SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, sql);
if (moreSQL != null && moreSQL.length > 0) { if (moreSQL != null && moreSQL.length > 0) {
Arrays.stream(moreSQL).forEach(action::addBatch); Arrays.stream(moreSQL).forEach(action::addBatch);
@@ -128,16 +128,12 @@ public class StatementUtil {
* @return 数据类型,默认为 {@link Types#VARCHAR} * @return 数据类型,默认为 {@link Types#VARCHAR}
*/ */
public static int getNullType(PreparedStatement statement, int paramIndex) { public static int getNullType(PreparedStatement statement, int paramIndex) {
int sqlType = Types.VARCHAR;
final ParameterMetaData pmd;
try { try {
pmd = statement.getParameterMetaData(); ParameterMetaData pmd = statement.getParameterMetaData();
sqlType = pmd.getParameterType(paramIndex); return pmd.getParameterType(paramIndex);
} catch (SQLException ignore) { } catch (SQLException ignore) {
return Types.VARCHAR;
} }
return sqlType;
} }
/** /**
@@ -201,6 +197,12 @@ public class StatementUtil {
// 其它数字类型按照默认类型传入 // 其它数字类型按照默认类型传入
} }
if (param instanceof Enum) {
//枚举类采用 name()
preparedStatement.setString(paramIndex, ((Enum<?>) param).name());
return;
}
// 其它参数类型直接传入 // 其它参数类型直接传入
preparedStatement.setObject(paramIndex, param); preparedStatement.setObject(paramIndex, param);
} }
+2 -2
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>0.3.0</version> <version>0.3.6</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -22,7 +22,7 @@
<artifactId>easysql-demo</artifactId> <artifactId>easysql-demo</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>99-EasySQL-Demo</name> <name>EasySQL-Demo</name>
<description>EasySQL的演示部分</description> <description>EasySQL的演示部分</description>
<url>https://github.com/CarmJos/EasySQL</url> <url>https://github.com/CarmJos/EasySQL</url>
+10 -5
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>0.3.0</version> <version>0.3.6</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -20,10 +20,15 @@
</properties> </properties>
<artifactId>easysql-test</artifactId> <artifactId>easysql-test</artifactId>
<name>EasySQL-Test</name>
<description>EasySQL的测试代码</description>
<url>https://github.com/CarmJos/EasySQL</url>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>${project.parent.groupId}</groupId> <groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-hikaricp</artifactId> <artifactId>easysql-beecp</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -32,14 +37,14 @@
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version> <version>8.0.28</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.7.29</version> <version>1.7.35</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -79,7 +84,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version> <version>3.2.4</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -2,22 +2,25 @@ package cc.carm.lib.easysql.testrunner;
import cc.carm.lib.easysql.EasySQL; import cc.carm.lib.easysql.EasySQL;
import cc.carm.lib.easysql.api.SQLManager; import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.testrunner.tests.TableAlterTest; import cc.carm.lib.easysql.testrunner.tests.DeleteTest;
import cc.carm.lib.easysql.testrunner.tests.QueryCloseTest;
import cc.carm.lib.easysql.testrunner.tests.QueryFunctionTest;
import cc.carm.lib.easysql.testrunner.tests.TableCreateTest; import cc.carm.lib.easysql.testrunner.tests.TableCreateTest;
import cc.carm.lib.easysql.testrunner.tests.TableRenameTest;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set; import java.util.Set;
@TestOnly
@SuppressWarnings("all")
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
if (args.length < 4) { if (args.length < 4) {
print("请提供以下参数: 数据库地址 数据库用户数据库密码"); print("请提供以下参数:<数据库驱动> <数据库地址(JDBC)> <数据库用户> <数据库密码> [是否采用DEBUG(y/n)]");
return; return;
} }
@@ -40,8 +43,14 @@ public class Main {
print("加载测试类..."); print("加载测试类...");
Set<EasySQLTest> tests = new LinkedHashSet<>(); Set<EasySQLTest> tests = new LinkedHashSet<>();
tests.add(new TableCreateTest()); tests.add(new TableCreateTest());
tests.add(new TableAlterTest()); // tests.add(new TableAlterTest());
tests.add(new TableRenameTest()); // tests.add(new TableRenameTest());
// tests.add(new QueryNotCloseTest());
tests.add(new QueryCloseTest());
// tests.add(new SQLUpdateBatchTests());
// tests.add(new SQLUpdateReturnKeysTest());
tests.add(new QueryFunctionTest());
tests.add(new DeleteTest());
print("准备进行测试..."); print("准备进行测试...");
@@ -73,21 +82,12 @@ public class Main {
success, (tests.size() - success) success, (tests.size() - success)
); );
} EasySQL.shutdownManager(sqlManager);
}
public static void print(@NotNull String format, Object... params) { public static void print(@NotNull String format, Object... params) {
System.out.printf((format) + "%n", params); System.out.printf((format) + "%n", params);
} }
public static @Nullable EasySQLTest cast(@NotNull Class<?> value) {
if (!EasySQLTest.class.isAssignableFrom(value)) return null;
try {
return (EasySQLTest) value.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return null;
}
}
} }
@@ -0,0 +1,22 @@
package cc.carm.lib.easysql.testrunner.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.testrunner.EasySQLTest;
import java.sql.SQLException;
public class DeleteTest extends EasySQLTest {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
Integer changes = sqlManager.createDelete("test_user_table")
.addCondition("id", ">", 5)
.addNotNullCondition("username")
.build().execute();
System.out.println("change(s): " + changes);
}
}
@@ -0,0 +1,31 @@
package cc.carm.lib.easysql.testrunner.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.testrunner.EasySQLTest;
import java.sql.ResultSet;
import java.sql.SQLException;
public class QueryCloseTest extends EasySQLTest {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
try (SQLQuery query = sqlManager.createQuery()
.inTable("test_user_table")
.orderBy("id", false)
.setLimit(5)
.build().execute()) {
ResultSet resultSet = query.getResultSet();
while (resultSet.next()) {
System.out.println("id: " + resultSet.getInt("id") + " username: " + resultSet.getString("username"));
}
}
}
}
@@ -0,0 +1,34 @@
package cc.carm.lib.easysql.testrunner.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.testrunner.EasySQLTest;
import java.sql.SQLException;
public class QueryFunctionTest extends EasySQLTest {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
Integer id_1 = sqlManager.createQuery()
.inTable("test_user_table")
.orderBy("id", false)
.setLimit(1)
.build().executeFunction(query -> {
if (!query.getResultSet().next()) return -1;
else return query.getResultSet().getInt("id");
});
System.out.println("id (ps): " + id_1);
Integer id_2 = sqlManager.createQuery().withSQL("SELECT id FROM test_user_table ORDER BY id DESC LIMIT 1")
.executeFunction(query -> {
if (!query.getResultSet().next()) return -1;
else return query.getResultSet().getInt("id");
});
System.out.println("id (s): " + id_2);
}
}
@@ -0,0 +1,30 @@
package cc.carm.lib.easysql.testrunner.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.testrunner.EasySQLTest;
import java.sql.ResultSet;
import java.sql.SQLException;
public class QueryNotCloseTest extends EasySQLTest {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
SQLQuery query = sqlManager.createQuery()
.inTable("test_user_table")
.orderBy("id", false)
.setLimit(5)
.build().execute();
ResultSet resultSet = query.getResultSet();
while (resultSet.next()) {
System.out.println("id: " + resultSet.getInt("id") + " username: " + resultSet.getString("username"));
}
}
}
@@ -0,0 +1,38 @@
package cc.carm.lib.easysql.testrunner.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.testrunner.EasySQLTest;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class SQLUpdateBatchTests extends EasySQLTest {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
List<Integer> updates = sqlManager.createInsertBatch("test_user_table")
.setColumnNames("uuid", "username", "age")
.setAllParams(generateParams())
.execute();
System.out.println("changes " + Arrays.toString(updates.toArray()));
}
protected List<Object[]> generateParams() {
return IntStream.range(0, 5).mapToObj(i -> generateParam()).collect(Collectors.toList());
}
protected Object[] generateParam() {
UUID uuid = UUID.randomUUID();
return new Object[]{uuid, uuid.toString().substring(0, 5), (int) (Math.random() * 50)};
}
}
@@ -0,0 +1,24 @@
package cc.carm.lib.easysql.testrunner.tests;
import cc.carm.lib.easysql.api.SQLManager;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
public class SQLUpdateReturnKeysTest extends SQLUpdateBatchTests {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
List<Integer> generatedKeys = sqlManager.createInsertBatch("test_user_table")
.setColumnNames("uuid", "username", "age")
.setAllParams(generateParams())
.returnGeneratedKeys()
.execute();
System.out.println("generated " + Arrays.toString(generatedKeys.toArray()));
}
}
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="cc.carm.lib.easysql">
<Appenders>
<console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
</console>
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<root level="info">
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
</filters>
<!-- <AppenderRef ref="WINDOWS_COMPAT" level="info"/>-->
<AppenderRef ref="File"/>
<appender-ref ref="Console"/>
</root>
</Loggers>
</Configuration>
+25 -22
View File
@@ -5,8 +5,9 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <java.version>8</java.version>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding> <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<sonar.organization>carmjos</sonar.organization> <sonar.organization>carmjos</sonar.organization>
@@ -16,7 +17,7 @@
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>0.3.0</version> <version>0.3.6</version>
<modules> <modules>
<module>easysql-api</module> <module>easysql-api</module>
@@ -31,7 +32,7 @@
<name>EasySQL</name> <name>EasySQL</name>
<description>简单便捷的数据库操作工具,可自选连接池。</description> <description>简单便捷的数据库操作工具,可自选连接池。</description>
<url>https://github.com/CarmJos/${project.name}</url> <url>https://github.com/CarmJos/EasySQL</url>
<developers> <developers>
<developer> <developer>
@@ -59,12 +60,12 @@
<issueManagement> <issueManagement>
<system>GitHub Issues</system> <system>GitHub Issues</system>
<url>${project.url}/issues</url> <url>https://github.com/CarmJos/EasySQL/issues</url>
</issueManagement> </issueManagement>
<ciManagement> <ciManagement>
<system>GitHub Actions</system> <system>GitHub Actions</system>
<url>${project.url}/actions/workflows/maven.yml</url> <url>https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml</url>
</ciManagement> </ciManagement>
<repositories> <repositories>
@@ -95,11 +96,11 @@
<distributionManagement> <distributionManagement>
<downloadUrl>${project.url}/releases</downloadUrl> <downloadUrl>https://github.com/CarmJos/EasySQL/releases</downloadUrl>
<site> <site>
<id>easysql-javadoc</id> <id>easysql-javadoc</id>
<name>EasySQL JavaDoc (on Github Pages)</name> <name>EasySQL JavaDoc (on Github Pages)</name>
<url>https://carmjos.github.io/EasySQL</url> <url>https://CarmJos.github.io/EasySQL</url>
</site> </site>
</distributionManagement> </distributionManagement>
@@ -116,7 +117,7 @@
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>
<version>22.0.0</version> <version>23.0.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@@ -133,7 +134,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId> <artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version> <version>3.0.1</version>
<executions> <executions>
<execution> <execution>
<id>sign-artifacts</id> <id>sign-artifacts</id>
@@ -153,7 +154,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version> <version>2.5.3</version>
<configuration> <configuration>
<autoVersionSubmodules>true</autoVersionSubmodules> <autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile> <useReleaseProfile>false</useReleaseProfile>
@@ -169,17 +170,19 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version> <version>3.3.1</version>
<configuration> <configuration>
<classifier>javadoc</classifier> <classifier>javadoc</classifier>
<links>
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
</links>
<detectJavaApiLink>false</detectJavaApiLink> <detectJavaApiLink>false</detectJavaApiLink>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<charset>UTF-8</charset> <charset>UTF-8</charset>
<docencoding>UTF-8</docencoding> <docencoding>UTF-8</docencoding>
<locale>zh_CN</locale> <locale>zh_CN</locale>
<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>
<dependencySourceInclude>cc.carm.lib:*</dependencySourceInclude>
</dependencySourceIncludes>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@@ -194,10 +197,10 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.9.0</version>
<configuration> <configuration>
<source>1.8</source> <source>${java.version}</source>
<target>1.8</target> <target>${java.version}</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<compilerArgument>-parameters</compilerArgument> <compilerArgument>-parameters</compilerArgument>
</configuration> </configuration>
@@ -206,13 +209,13 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version> <version>3.2.2</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version> <version>3.2.1</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -226,7 +229,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version> <version>3.2.4</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -254,7 +257,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version> <version>2.22.2</version>
<configuration> <configuration>
<useSystemClassLoader>false</useSystemClassLoader> <useSystemClassLoader>false</useSystemClassLoader>
</configuration> </configuration>
+17 -6
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>0.3.0</version> <version>0.3.6</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -20,7 +20,7 @@
<artifactId>easysql-beecp</artifactId> <artifactId>easysql-beecp</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>12-EasySQL-BeeCP</name> <name>EasySQL-BeeCP</name>
<description>EasySQL的应用部分。此为BeeCP版本。</description> <description>EasySQL的应用部分。此为BeeCP版本。</description>
<url>https://github.com/CarmJos/EasySQL</url> <url>https://github.com/CarmJos/EasySQL</url>
@@ -45,16 +45,23 @@
<issueManagement> <issueManagement>
<system>GitHub Issues</system> <system>GitHub Issues</system>
<url>${project.url}/issues</url> <url>https://github.com/CarmJos/EasySQL/issues</url>
</issueManagement> </issueManagement>
<ciManagement> <ciManagement>
<system>GitHub Actions</system> <system>GitHub Actions</system>
<url>${project.url}/actions/workflows/maven.yml</url> <url>https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml</url>
</ciManagement> </ciManagement>
<dependencies> <dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>${project.parent.groupId}</groupId> <groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-impl</artifactId> <artifactId>easysql-impl</artifactId>
@@ -66,7 +73,7 @@
<!--项目地址 https://github.com/Chris2018998/BeeCP --> <!--项目地址 https://github.com/Chris2018998/BeeCP -->
<groupId>com.github.chris2018998</groupId> <groupId>com.github.chris2018998</groupId>
<artifactId>beecp</artifactId> <artifactId>beecp</artifactId>
<version>3.3.0</version> <version>3.3.1</version>
<optional>true</optional> <optional>true</optional>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@@ -87,10 +94,14 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version> <version>3.2.4</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
+16 -5
View File
@@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>easysql-parent</artifactId> <artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId> <groupId>cc.carm.lib</groupId>
<version>0.3.0</version> <version>0.3.6</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -19,7 +19,7 @@
<artifactId>easysql-hikaricp</artifactId> <artifactId>easysql-hikaricp</artifactId>
<name>11-EasySQL-HikariCP</name> <name>EasySQL-HikariCP</name>
<description>EasySQL的应用部分。此为HikariCP版本。</description> <description>EasySQL的应用部分。此为HikariCP版本。</description>
<url>https://github.com/CarmJos/EasySQL</url> <url>https://github.com/CarmJos/EasySQL</url>
@@ -44,16 +44,23 @@
<issueManagement> <issueManagement>
<system>GitHub Issues</system> <system>GitHub Issues</system>
<url>${project.url}/issues</url> <url>https://github.com/CarmJos/EasySQL/issues</url>
</issueManagement> </issueManagement>
<ciManagement> <ciManagement>
<system>GitHub Actions</system> <system>GitHub Actions</system>
<url>${project.url}/actions/workflows/maven.yml</url> <url>https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml</url>
</ciManagement> </ciManagement>
<dependencies> <dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-api</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>${project.parent.groupId}</groupId> <groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-impl</artifactId> <artifactId>easysql-impl</artifactId>
@@ -86,10 +93,14 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version> <version>3.2.4</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>