mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-14 03:15:55 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7669257028 | |||
| bc00330eef | |||
| d7db2fbb52 | |||
| 6de493afbc | |||
| 2ecc442bd9 | |||
| ec2dab31ab | |||
| 315a591375 | |||
| cfac4e2ec6 | |||
| 0f94204b6a |
@@ -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) 。
|
||||
@@ -24,20 +24,20 @@ jobs:
|
||||
distribution: 'adopt'
|
||||
|
||||
- name: Generate docs
|
||||
run: mvn javadoc:javadoc
|
||||
run: mvn clean package
|
||||
|
||||
- name: Copy to Location
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf easysql-api/target/site/apidocs/* docs/
|
||||
cp -vrf JAVADOC-README.md docs/README.md
|
||||
cp -vrf easysql-api/target/apidocs/* docs/
|
||||
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: Generate the sitemap
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://carmjos.github.io/userprefix
|
||||
base-url-path: https://carmjos.github.io/EasySQL
|
||||
path-to-root: docs
|
||||
|
||||
- name: Output stats
|
||||
@@ -62,7 +62,7 @@ jobs:
|
||||
run: |
|
||||
cd docs
|
||||
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 add -A
|
||||
git commit -m "API Document generated."
|
||||
|
||||
@@ -8,14 +8,13 @@
|
||||
```
|
||||
|
||||
# EasySQL
|
||||
|
||||
[](https://www.codefactor.io/repository/github/carmjos/easysql)
|
||||

|
||||
[](https://github.com/CarmJos/EasySQL/releases)
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/EasySQL/actions/workflows/maven.yml)
|
||||
[](https://www.codefactor.io/repository/github/carmjos/easysql)
|
||||

|
||||

|
||||
|
||||
|
||||
简单便捷的数据库操作工具,可自定义连接池来源。
|
||||
|
||||
随项目分别提供 [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")
|
||||
.addColumn("id", "INT(11) AUTO_INCREMENT NOT NULL PRIMARY KEY")
|
||||
.addColumn("username", "VARCHAR(16) NOT NULL UNIQUE KEY")
|
||||
.addColumn("age", "INT(3) NOT NULL DEFAULT 1")
|
||||
.addColumn("email", "VARCHAR(32)")
|
||||
.addColumn("phone", "VARCHAR(16)")
|
||||
.addColumn("registerTime", "DATETIME NOT NULL")
|
||||
@@ -56,14 +56,14 @@ public class EasySQLDemo {
|
||||
// 同步SQL查询
|
||||
try (SQLQuery query = sqlManager.createQuery()
|
||||
.inTable("users") // 在users表中查询
|
||||
.addCondition("id", ">", 5) // 限定 id 要大于5
|
||||
.addCondition("email", null) // 限定查询email字段为空
|
||||
.addNotNullCondition("phone") // 限定 phone字段不为空
|
||||
.addTimeCondition(
|
||||
"registerTime", // 时间字段
|
||||
.selectColumn("id", "name") // 选中 id 与 name列~~~~
|
||||
.addCondition("age", ">", 18) // 限定 age 要大于5
|
||||
.addCondition("email", null) // 限定查询 email 字段为空
|
||||
.addNotNullCondition("phone") // 限定 phone 字段不为空
|
||||
.addTimeCondition("registerTime", // 时间字段
|
||||
System.currentTimeMillis() - 100000, //限制开始时间
|
||||
-1) //不限制结束时间
|
||||
.build().execute()) {
|
||||
-1//不限制结束时间
|
||||
).build().execute()) {
|
||||
ResultSet resultSet = query.getResultSet();
|
||||
//do something
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<version>v0.0.1</version>
|
||||
<version>0.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface SQLAction<T> {
|
||||
@@ -22,13 +23,13 @@ public interface SQLAction<T> {
|
||||
@NotNull T execute() throws SQLException;
|
||||
|
||||
@Nullable
|
||||
default T execute(@Nullable Consumer<SQLException> exceptionHandler) {
|
||||
default T execute(@Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler) {
|
||||
if (exceptionHandler == null) exceptionHandler = defaultExceptionHandler();
|
||||
T value = null;
|
||||
try {
|
||||
value = execute();
|
||||
} catch (SQLException exception) {
|
||||
exceptionHandler.accept(exception);
|
||||
exceptionHandler.accept(exception, this);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -37,22 +38,16 @@ public interface SQLAction<T> {
|
||||
executeAsync(null);
|
||||
}
|
||||
|
||||
default void executeAsync(Consumer<T> success) {
|
||||
default void executeAsync(@Nullable Consumer<T> success) {
|
||||
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);
|
||||
|
||||
@NotNull Consumer<SQLException> getExceptionHandler();
|
||||
|
||||
default Consumer<SQLException> defaultExceptionHandler() {
|
||||
return Throwable::printStackTrace;
|
||||
}
|
||||
|
||||
default Consumer<T> defaultResultHandler() {
|
||||
return t -> {
|
||||
default BiConsumer<SQLException, SQLAction<T>> defaultExceptionHandler() {
|
||||
return (exception, action) -> {
|
||||
getManager().getLogger().severe("Error when execute [" + action.getSQLContent() + "]");
|
||||
getManager().getLogger().severe(exception.getLocalizedMessage());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,12 @@ import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface SQLManager {
|
||||
|
||||
Logger getLogger();
|
||||
|
||||
boolean isDebugMode();
|
||||
|
||||
void setDebugMode(boolean enable);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package cc.carm.lib.easysql.api.builder;
|
||||
|
||||
public interface UpsertBuilder {
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>v0.0.1</version>
|
||||
<version>0.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>v0.0.1</version>
|
||||
<version>0.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>v0.0.1</version>
|
||||
<version>0.2.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -3,9 +3,11 @@ package cc.carm.lib.easysql.action;
|
||||
import cc.carm.lib.easysql.api.SQLAction;
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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 Consumer<SQLException> exceptionHandler = defaultExceptionHandler();
|
||||
protected @Nullable BiConsumer<SQLException, SQLAction<T>> exceptionHandler = null;
|
||||
|
||||
public AbstractSQLAction(@NotNull SQLManagerImpl manager, @NotNull String sql) {
|
||||
this(manager, sql, System.currentTimeMillis());
|
||||
@@ -69,14 +71,25 @@ public abstract class AbstractSQLAction<T> implements SQLAction<T> {
|
||||
getManager().debug("#" + getShortID() + " ->" + getSQLContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLAction<T> handleException(Consumer<SQLException> handler) {
|
||||
this.exceptionHandler = handler;
|
||||
return this;
|
||||
public void handleException(SQLException exception) {
|
||||
if (this.exceptionHandler == null) {
|
||||
defaultExceptionHandler().accept(exception, this);
|
||||
} else {
|
||||
this.exceptionHandler.accept(exception, this);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Consumer<SQLException> getExceptionHandler() {
|
||||
return exceptionHandler;
|
||||
@Override
|
||||
public void executeAsync(Consumer<T> success, BiConsumer<SQLException, SQLAction<T>> failure) {
|
||||
getManager().getExecutorPool().submit(() -> {
|
||||
try {
|
||||
T returnedValue = execute();
|
||||
if (success != null) success.accept(returnedValue);
|
||||
} catch (SQLException e) {
|
||||
(failure == null ? defaultExceptionHandler() : failure).accept(e, this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-4
@@ -72,8 +72,4 @@ public class PreparedSQLBatchUpdateActionImpl extends SQLUpdateBatchActionImpl i
|
||||
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.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements PreparedSQLUpdateAction {
|
||||
|
||||
@@ -63,9 +62,4 @@ public class PreparedSQLUpdateActionImpl extends SQLUpdateActionImpl implements
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAsync(Consumer<Integer> success, Consumer<SQLException> failure) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLUpdateActionImpl setKeyIndex(int keyIndex) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> implements SQLUpdateBatchAction {
|
||||
@@ -52,10 +51,4 @@ public class SQLUpdateBatchActionImpl extends AbstractSQLAction<List<Integer>> i
|
||||
return returnedValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAsync(Consumer<List<Integer>> success, Consumer<SQLException> failure) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-6
@@ -1,6 +1,5 @@
|
||||
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.manager.SQLManagerImpl;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAsync(Consumer<SQLQuery> success, Consumer<SQLException> failure) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,9 +32,4 @@ public class QueryActionImpl extends AbstractSQLAction<SQLQuery> implements Quer
|
||||
|
||||
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.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SQLManagerImpl implements SQLManager {
|
||||
@@ -29,13 +31,21 @@ public class SQLManagerImpl implements SQLManager {
|
||||
|
||||
boolean debug = false;
|
||||
|
||||
protected ExecutorService executorPool;
|
||||
|
||||
public SQLManagerImpl(@NotNull DataSource dataSource) {
|
||||
this(dataSource, null);
|
||||
}
|
||||
|
||||
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.executorPool = Executors.newFixedThreadPool(3, r -> {
|
||||
Thread thread = new Thread(r, managerName);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,6 +66,9 @@ public class SQLManagerImpl implements SQLManager {
|
||||
return LOGGER;
|
||||
}
|
||||
|
||||
public ExecutorService getExecutorPool() {
|
||||
return executorPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull DataSource getDataSource() {
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SQLQueryImpl implements SQLQuery {
|
||||
);
|
||||
getManager().getActiveQuery().remove(getAction().getActionUUID());
|
||||
} catch (SQLException e) {
|
||||
getAction().getExceptionHandler().accept(e);
|
||||
getAction().handleException(e);
|
||||
}
|
||||
this.queryAction = null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package cc.carm.lib.easysql.util;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLAction;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.*;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>v0.0.1</version>
|
||||
<version>0.2.0</version>
|
||||
|
||||
<modules>
|
||||
<module>easysql-api</module>
|
||||
@@ -40,7 +40,7 @@
|
||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>${project.url}/issues</url>
|
||||
@@ -79,7 +79,7 @@
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/${project.name}</url>
|
||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
@@ -91,7 +91,7 @@
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/${project.name}</url>
|
||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
||||
</repository>
|
||||
|
||||
</distributionManagement>
|
||||
|
||||
Reference in New Issue
Block a user