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

Compare commits

..

9 Commits

Author SHA1 Message Date
carm 7669257028 添加version地址 2021-12-14 16:16:18 +08:00
carm bc00330eef 添加version地址 2021-12-14 16:14:53 +08:00
carm d7db2fbb52 实装 executeAsync 功能,修改异常处理方式,提供action方便获取相关信息。 2021-12-14 16:11:22 +08:00
carm 6de493afbc 修改实例代码 2021-12-14 16:09:55 +08:00
carm 2ecc442bd9 修改Javadoc地址 2021-12-14 06:22:52 +08:00
carm ec2dab31ab 添加Javadoc地址 2021-12-14 06:21:26 +08:00
carm 315a591375 修改部署地址 2021-12-14 06:12:48 +08:00
carm cfac4e2ec6 修改 JAVADOC-README.md 的路径 2021-12-14 06:11:21 +08:00
carm 0f94204b6a 修改javadoc生成方式 2021-12-14 06:03:44 +08:00
21 changed files with 93 additions and 81 deletions
+9
View File
@@ -0,0 +1,9 @@
# EasySQL Javadoc
基于 [Github Pages](https://pages.github.com/) 搭建,请访问 [JavaDoc](https://carmjos.github.io/EasySQL) 。
## 如何实现?
若您也想通过 [Github Actions](https://docs.github.com/en/actions/learn-github-actions)
自动部署项目的Javadoc到 [Github Pages](https://pages.github.com/)
可以参考我的文章 [《自动部署Javadoc到Github Pages》](https://pages.carm.cc/doc/javadoc-in-github.html) 。
+5 -5
View File
@@ -24,20 +24,20 @@ jobs:
distribution: 'adopt' distribution: 'adopt'
- name: Generate docs - name: Generate docs
run: mvn javadoc:javadoc run: mvn clean package
- name: Copy to Location - name: Copy to Location
run: | run: |
rm -rf docs rm -rf docs
mkdir -vp docs mkdir -vp docs
cp -vrf easysql-api/target/site/apidocs/* docs/ cp -vrf easysql-api/target/apidocs/* docs/
cp -vrf JAVADOC-README.md docs/README.md cp -vrf .documentation/JAVADOC-README.md docs/README.md
- name: Generate the sitemap - name: Generate the sitemap
id: sitemap id: sitemap
uses: cicirello/generate-sitemap@v1 uses: cicirello/generate-sitemap@v1
with: with:
base-url-path: https://carmjos.github.io/userprefix base-url-path: https://carmjos.github.io/EasySQL
path-to-root: docs path-to-root: docs
- name: Output stats - name: Output stats
@@ -62,7 +62,7 @@ jobs:
run: | run: |
cd docs cd docs
git init git init
git remote add origin git@github.com:CarmJos/UserPrefix.git git remote add origin git@github.com:CarmJos/EasySQL.git
git checkout -b gh-pages git checkout -b gh-pages
git add -A git add -A
git commit -m "API Document generated." git commit -m "API Document generated."
+12 -12
View File
@@ -8,14 +8,13 @@
``` ```
# EasySQL # EasySQL
[![version](https://img.shields.io/github/v/release/CarmJos/EasySQL)](https://github.com/CarmJos/EasySQL/releases)
[![CodeFactor](https://www.codefactor.io/repository/github/carmjos/easysql/badge)](https://www.codefactor.io/repository/github/carmjos/easysql)
![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/EasySQL)
[![License](https://img.shields.io/github/license/CarmJos/EasySQL)](https://opensource.org/licenses/GPL-3.0) [![License](https://img.shields.io/github/license/CarmJos/EasySQL)](https://opensource.org/licenses/GPL-3.0)
[![workflow](https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml) [![workflow](https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml)
[![CodeFactor](https://www.codefactor.io/repository/github/carmjos/easysql/badge)](https://www.codefactor.io/repository/github/carmjos/easysql)
![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/EasySQL)
![](https://visitor-badge.glitch.me/badge?page_id=EasySQL.readme) ![](https://visitor-badge.glitch.me/badge?page_id=EasySQL.readme)
简单便捷的数据库操作工具,可自定义连接池来源。 简单便捷的数据库操作工具,可自定义连接池来源。
随项目分别提供 [BeeCP](https://github.com/Chris2018998/BeeCP) 与 [Hikari](https://github.com/brettwooldridge/HikariCP~~~~) 随项目分别提供 [BeeCP](https://github.com/Chris2018998/BeeCP) 与 [Hikari](https://github.com/brettwooldridge/HikariCP~~~~)
@@ -34,7 +33,7 @@
## 开发 ## 开发
详细开发介绍请 [点击这里](.documentation/INDEX.md) 。 详细开发介绍请 [点击这里](.documentation/INDEX.md) , JavaDoc(最新Release) 请 [点击这里](https://carmjos.github.io/EasySQL)
### 示例代码 ### 示例代码
@@ -46,6 +45,7 @@ public class EasySQLDemo {
sqlManager.createTable("users") sqlManager.createTable("users")
.addColumn("id", "INT(11) AUTO_INCREMENT NOT NULL PRIMARY KEY") .addColumn("id", "INT(11) AUTO_INCREMENT NOT NULL PRIMARY KEY")
.addColumn("username", "VARCHAR(16) NOT NULL UNIQUE KEY") .addColumn("username", "VARCHAR(16) NOT NULL UNIQUE KEY")
.addColumn("age", "INT(3) NOT NULL DEFAULT 1")
.addColumn("email", "VARCHAR(32)") .addColumn("email", "VARCHAR(32)")
.addColumn("phone", "VARCHAR(16)") .addColumn("phone", "VARCHAR(16)")
.addColumn("registerTime", "DATETIME NOT NULL") .addColumn("registerTime", "DATETIME NOT NULL")
@@ -56,14 +56,14 @@ public class EasySQLDemo {
// 同步SQL查询 // 同步SQL查询
try (SQLQuery query = sqlManager.createQuery() try (SQLQuery query = sqlManager.createQuery()
.inTable("users") // 在users表中查询 .inTable("users") // 在users表中查询
.addCondition("id", ">", 5) // 限定 id 要大于5 .selectColumn("id", "name") // 选中 id 与 name列~~~~
.addCondition("email", null) // 限定查询email字段为空 .addCondition("age", ">", 18) // 限定 age 要大于5
.addNotNullCondition("phone") // 限定 phone字段为空 .addCondition("email", null) // 限定查询 email 字段为空
.addTimeCondition( .addNotNullCondition("phone") // 限定 phone 字段不为空
"registerTime", // 时间字段 .addTimeCondition("registerTime", // 时间字段
System.currentTimeMillis() - 100000, //限制开始时间 System.currentTimeMillis() - 100000, //限制开始时间
-1) //不限制结束时间 -1//不限制结束时间
.build().execute()) { ).build().execute()) {
ResultSet resultSet = query.getResultSet(); ResultSet resultSet = query.getResultSet();
//do something //do something
+1 -1
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>v0.0.1</version> <version>0.2.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
public interface SQLAction<T> { public interface SQLAction<T> {
@@ -22,13 +23,13 @@ public interface SQLAction<T> {
@NotNull T execute() throws SQLException; @NotNull T execute() throws SQLException;
@Nullable @Nullable
default T execute(@Nullable Consumer<SQLException> exceptionHandler) { default T execute(@Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler) {
if (exceptionHandler == null) exceptionHandler = defaultExceptionHandler(); if (exceptionHandler == null) exceptionHandler = defaultExceptionHandler();
T value = null; T value = null;
try { try {
value = execute(); value = execute();
} catch (SQLException exception) { } catch (SQLException exception) {
exceptionHandler.accept(exception); exceptionHandler.accept(exception, this);
} }
return value; return value;
} }
@@ -37,22 +38,16 @@ public interface SQLAction<T> {
executeAsync(null); executeAsync(null);
} }
default void executeAsync(Consumer<T> success) { default void executeAsync(@Nullable Consumer<T> success) {
executeAsync(success, null); executeAsync(success, null);
} }
void executeAsync(Consumer<T> success, Consumer<SQLException> failure); void executeAsync(@Nullable Consumer<T> success, @Nullable BiConsumer<SQLException, SQLAction<T>> failure);
SQLAction<T> handleException(Consumer<SQLException> failure); default BiConsumer<SQLException, SQLAction<T>> defaultExceptionHandler() {
return (exception, action) -> {
@NotNull Consumer<SQLException> getExceptionHandler(); getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
getManager().getLogger().severe(exception.getLocalizedMessage());
default Consumer<SQLException> defaultExceptionHandler() {
return Throwable::printStackTrace;
}
default Consumer<T> defaultResultHandler() {
return t -> {
}; };
} }
@@ -12,9 +12,12 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Logger;
public interface SQLManager { public interface SQLManager {
Logger getLogger();
boolean isDebugMode(); boolean isDebugMode();
void setDebugMode(boolean enable); void setDebugMode(boolean enable);
@@ -0,0 +1,4 @@
package cc.carm.lib.easysql.api.builder;
public interface UpsertBuilder {
}
+3 -1
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>v0.0.1</version> <version>0.2.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -50,6 +50,8 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</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>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties> </properties>
<dependencies> <dependencies>
+3 -1
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>v0.0.1</version> <version>0.2.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -49,6 +49,8 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</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>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties> </properties>
<dependencies> <dependencies>
+2 -1
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>v0.0.1</version> <version>0.2.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -50,6 +50,7 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</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>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties> </properties>
<dependencies> <dependencies>
@@ -3,9 +3,11 @@ package cc.carm.lib.easysql.action;
import cc.carm.lib.easysql.api.SQLAction; import cc.carm.lib.easysql.api.SQLAction;
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 org.jetbrains.annotations.Nullable;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
public abstract class AbstractSQLAction<T> implements SQLAction<T> { public abstract class AbstractSQLAction<T> implements SQLAction<T> {
@@ -17,7 +19,7 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
protected @NotNull String sqlContent; protected @NotNull String sqlContent;
protected @NotNull Consumer<SQLException> exceptionHandler = defaultExceptionHandler(); protected @Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler = null;
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql) { public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql) {
this(manager, sql, System.currentTimeMillis()); this(manager, sql, System.currentTimeMillis());
@@ -69,14 +71,25 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
getManager().debug("#" + getShortID() + " ->" + getSQLContent()); getManager().debug("#" + getShortID() + " ->" + getSQLContent());
} }
@Override public void handleException(SQLException exception) {
public SQLAction<T> handleException(Consumer<SQLException> handler) { if (this.exceptionHandler == null) {
this.exceptionHandler = handler; defaultExceptionHandler().accept(exception, this);
return this; } else {
this.exceptionHandler.accept(exception, this);
}
} }
@NotNull @Override
public Consumer<SQLException> getExceptionHandler() { public void executeAsync(Consumer<T> success, BiConsumer<SQLException, SQLAction<T>> failure) {
return exceptionHandler; getManager().getExecutorPool().submit(() -> {
try {
T returnedValue = execute();
if (success != null) success.accept(returnedValue);
} catch (SQLException e) {
(failure == null ? defaultExceptionHandler() : failure).accept(e, this);
} }
});
}
} }
@@ -72,8 +72,4 @@ public class PreparedSQLBatchUpdateActionImpl extends SQLUpdateBatchActionImpl i
return returnedValues; return returnedValues;
} }
@Override
public void executeAsync(Consumer<List<Integer>> success, Consumer<SQLException> failure) {
}
} }
@@ -11,7 +11,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements PreparedSQLUpdateAction { public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements PreparedSQLUpdateAction {
@@ -63,9 +62,4 @@ public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements
return value; return value;
} }
@Override
public void executeAsync(Consumer<Integer> success, Consumer<SQLException> failure) {
}
} }
@@ -43,10 +43,6 @@ public class SQLUpdateActionImpl extends AbstractSQLAction<Integer> implements S
return returnedValue; return returnedValue;
} }
@Override
public void executeAsync(Consumer<Integer> success, Consumer<SQLException> failure) {
}
@Override @Override
public SQLUpdateActionImpl setKeyIndex(int keyIndex) { public SQLUpdateActionImpl setKeyIndex(int keyIndex) {
@@ -10,7 +10,6 @@ import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> implements SQLUpdateBatchAction { public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> implements SQLUpdateBatchAction {
@@ -52,10 +51,4 @@ public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> i
return returnedValues; return returnedValues;
} }
@Override
public void executeAsync(Consumer<List<Integer>> success, Consumer<SQLException> failure) {
}
} }
@@ -1,6 +1,5 @@
package cc.carm.lib.easysql.action.query; package cc.carm.lib.easysql.action.query;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.api.action.query.PreparedQueryAction; import cc.carm.lib.easysql.api.action.query.PreparedQueryAction;
import cc.carm.lib.easysql.manager.SQLManagerImpl; import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.query.SQLQueryImpl; import cc.carm.lib.easysql.query.SQLQueryImpl;
@@ -68,9 +67,4 @@ public class PreparedQueryActionImpl extends QueryActionImpl implements Prepared
return new SQLQueryImpl(getManager(), this, connection, preparedStatement, resultSet); return new SQLQueryImpl(getManager(), this, connection, preparedStatement, resultSet);
} }
@Override
public void executeAsync(Consumer<SQLQuery> success, Consumer<SQLException> failure) {
}
} }
@@ -32,9 +32,4 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
return query; return query;
} }
@Override
public void executeAsync(Consumer<SQLQuery> success, Consumer<SQLException> failure) {
}
} }
@@ -19,6 +19,8 @@ import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Logger; import java.util.logging.Logger;
public class SQLManagerImpl implements SQLManager { public class SQLManagerImpl implements SQLManager {
@@ -29,13 +31,21 @@ public class SQLManagerImpl implements SQLManager {
boolean debug = false; boolean debug = false;
protected ExecutorService executorPool;
public SQLManagerImpl(@NotNull DataSource dataSource) { public SQLManagerImpl(@NotNull DataSource dataSource) {
this(dataSource, null); this(dataSource, null);
} }
public SQLManagerImpl(@NotNull DataSource dataSource, @Nullable String name) { public SQLManagerImpl(@NotNull DataSource dataSource, @Nullable String name) {
this.LOGGER = Logger.getLogger("SQLManager" + (name != null ? "#" + name : "")); String managerName = "SQLManager" + (name != null ? "#" + name : "");
this.LOGGER = Logger.getLogger(managerName);
this.dataSource = dataSource; this.dataSource = dataSource;
this.executorPool = Executors.newFixedThreadPool(3, r -> {
Thread thread = new Thread(r, managerName);
thread.setDaemon(true);
return thread;
});
} }
@Override @Override
@@ -56,6 +66,9 @@ public class SQLManagerImpl implements SQLManager {
return LOGGER; return LOGGER;
} }
public ExecutorService getExecutorPool() {
return executorPool;
}
@Override @Override
public @NotNull DataSource getDataSource() { public @NotNull DataSource getDataSource() {
@@ -70,7 +70,7 @@ public class SQLQueryImpl implements SQLQuery {
); );
getManager().getActiveQuery().remove(getAction().getActionUUID()); getManager().getActiveQuery().remove(getAction().getActionUUID());
} catch (SQLException e) { } catch (SQLException e) {
getAction().getExceptionHandler().accept(e); getAction().handleException(e);
} }
this.queryAction = null; this.queryAction = null;
} }
@@ -1,5 +1,7 @@
package cc.carm.lib.easysql.util; package cc.carm.lib.easysql.util;
import cc.carm.lib.easysql.api.SQLAction;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.sql.*; import java.sql.*;
+3 -3
View File
@@ -7,7 +7,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>v0.0.1</version> <version>0.2.0</version>
<modules> <modules>
<module>easysql-api</module> <module>easysql-api</module>
@@ -79,7 +79,7 @@
<repository> <repository>
<id>github</id> <id>github</id>
<name>GitHub Packages</name> <name>GitHub Packages</name>
<url>https://maven.pkg.github.com/CarmJos/${project.name}</url> <url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
</repository> </repository>
</repositories> </repositories>
@@ -91,7 +91,7 @@
<repository> <repository>
<id>github</id> <id>github</id>
<name>GitHub Packages</name> <name>GitHub Packages</name>
<url>https://maven.pkg.github.com/CarmJos/${project.name}</url> <url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
</repository> </repository>
</distributionManagement> </distributionManagement>