mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-14 03:15:55 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 43baf4aa24 | |||
| edadc50c22 |
@@ -11,8 +11,7 @@ on:
|
|||||||
types: [ published ]
|
types: [ published ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
deploy:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -26,8 +25,55 @@ jobs:
|
|||||||
server-id: github
|
server-id: github
|
||||||
server-username: MAVEN_USERNAME
|
server-username: MAVEN_USERNAME
|
||||||
server-password: MAVEN_TOKEN
|
server-password: MAVEN_TOKEN
|
||||||
- name: "Deploy"
|
|
||||||
|
- name: "Maven Deploy With Javadoc"
|
||||||
run: mvn -B deploy --file pom.xml -DskipTests
|
run: mvn -B deploy --file pom.xml -DskipTests
|
||||||
env:
|
env:
|
||||||
MAVEN_USERNAME: ${{ github.repository_owner }}
|
MAVEN_USERNAME: ${{ github.repository_owner }}
|
||||||
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
MAVEN_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
|
||||||
|
- name: "Copy Javadoc to Location"
|
||||||
|
run: |
|
||||||
|
rm -rf docs
|
||||||
|
mkdir -vp docs
|
||||||
|
cp -vrf easysql-api/target/apidocs/* docs/
|
||||||
|
cp -vrf .documentation/JAVADOC-README.md docs/README.md
|
||||||
|
|
||||||
|
- name: "Generate the Javadoc sitemap"
|
||||||
|
id: sitemap
|
||||||
|
uses: cicirello/generate-sitemap@v1
|
||||||
|
with:
|
||||||
|
base-url-path: https://carmjos.github.io/EasySQL
|
||||||
|
path-to-root: docs
|
||||||
|
|
||||||
|
- name: "Output stats"
|
||||||
|
run: |
|
||||||
|
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
||||||
|
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
||||||
|
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
||||||
|
|
||||||
|
- name: "Configure Git"
|
||||||
|
env:
|
||||||
|
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
||||||
|
run: |
|
||||||
|
sudo timedatectl set-timezone "Asia/Shanghai"
|
||||||
|
mkdir -p ~/.ssh/
|
||||||
|
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
||||||
|
git config --global user.name 'CarmJos'
|
||||||
|
git config --global user.email 'carm@carm.cc'
|
||||||
|
|
||||||
|
- name: "Commit documentations"
|
||||||
|
run: |
|
||||||
|
cd docs
|
||||||
|
git init
|
||||||
|
git remote add origin git@github.com:CarmJos/EasySQL.git
|
||||||
|
git checkout -b gh-pages
|
||||||
|
git add -A
|
||||||
|
git commit -m "API Document generated."
|
||||||
|
|
||||||
|
- name: "Push javadocs"
|
||||||
|
run: |
|
||||||
|
cd docs
|
||||||
|
git push origin HEAD:gh-pages --force
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
|
||||||
|
|
||||||
name: "Javadoc Deployment"
|
|
||||||
|
|
||||||
on:
|
|
||||||
# 支持手动触发构建
|
|
||||||
workflow_dispatch:
|
|
||||||
release:
|
|
||||||
# 创建release的时候触发
|
|
||||||
types: [ published ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
api-website:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout the repo
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up the Java JDK
|
|
||||||
uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
java-version: '11'
|
|
||||||
distribution: 'adopt'
|
|
||||||
|
|
||||||
- name: Generate docs
|
|
||||||
run: mvn clean package -DskipTests
|
|
||||||
|
|
||||||
- name: Copy to Location
|
|
||||||
run: |
|
|
||||||
rm -rf docs
|
|
||||||
mkdir -vp docs
|
|
||||||
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/EasySQL
|
|
||||||
path-to-root: docs
|
|
||||||
|
|
||||||
- name: Output stats
|
|
||||||
run: |
|
|
||||||
echo "sitemap-path = ${{ steps.sitemap.outputs.sitemap-path }}"
|
|
||||||
echo "url-count = ${{ steps.sitemap.outputs.url-count }}"
|
|
||||||
echo "excluded-count = ${{ steps.sitemap.outputs.excluded-count }}"
|
|
||||||
|
|
||||||
- name: Configure Git
|
|
||||||
env:
|
|
||||||
DEPLOY_PRI: ${{secrets.DEPLOY_PRI}}
|
|
||||||
run: |
|
|
||||||
sudo timedatectl set-timezone "Asia/Shanghai"
|
|
||||||
mkdir -p ~/.ssh/
|
|
||||||
echo "$DEPLOY_PRI" > ~/.ssh/id_rsa
|
|
||||||
chmod 600 ~/.ssh/id_rsa
|
|
||||||
ssh-keyscan github.com >> ~/.ssh/known_hosts
|
|
||||||
git config --global user.name 'CarmJos'
|
|
||||||
git config --global user.email 'carm@carm.cc'
|
|
||||||
|
|
||||||
- name: Commit documentation changes
|
|
||||||
run: |
|
|
||||||
cd docs
|
|
||||||
git init
|
|
||||||
git remote add origin git@github.com:CarmJos/EasySQL.git
|
|
||||||
git checkout -b gh-pages
|
|
||||||
git add -A
|
|
||||||
git commit -m "API Document generated."
|
|
||||||
- name: Push javadocs
|
|
||||||
run: |
|
|
||||||
cd docs
|
|
||||||
git push origin HEAD:gh-pages --force
|
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||||
|
|
||||||
name: Build
|
name: Project Build & Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
# 支持手动触发构建
|
# 支持手动触发构建
|
||||||
|
|||||||
+1
-1
@@ -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.2.7</version>
|
<version>0.2.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -14,149 +14,154 @@ 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.function.Supplier;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public interface SQLManager {
|
public interface SQLManager {
|
||||||
|
|
||||||
Logger getLogger();
|
Logger getLogger();
|
||||||
|
|
||||||
boolean isDebugMode();
|
boolean isDebugMode();
|
||||||
|
|
||||||
void setDebugMode(boolean enable);
|
void setDebugMode(@NotNull Supplier<@NotNull Boolean> debugMode);
|
||||||
|
|
||||||
/**
|
default void setDebugMode(boolean enable) {
|
||||||
* 得到连接池源
|
setDebugMode(() -> enable);
|
||||||
*
|
}
|
||||||
* @return DataSource
|
|
||||||
*/
|
|
||||||
@NotNull DataSource getDataSource();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到一个数据库连接实例
|
* 得到连接池源
|
||||||
*
|
*
|
||||||
* @return Connection
|
* @return DataSource
|
||||||
* @throws SQLException 见 {@link DataSource#getConnection()}
|
*/
|
||||||
*/
|
@NotNull DataSource getDataSource();
|
||||||
@NotNull Connection getConnection() throws SQLException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 得到正使用的查询。
|
* 得到一个数据库连接实例
|
||||||
*
|
*
|
||||||
* @return 查询列表
|
* @return Connection
|
||||||
*/
|
* @throws SQLException 见 {@link DataSource#getConnection()}
|
||||||
@NotNull Map<UUID, SQLQuery> getActiveQuery();
|
*/
|
||||||
|
@NotNull Connection getConnection() throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法)
|
* 得到正使用的查询。
|
||||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
*
|
||||||
*
|
* @return 查询列表
|
||||||
* @param sql SQL语句内容
|
*/
|
||||||
* @return 更新的行数
|
@NotNull Map<UUID, SQLQuery> getActiveQuery();
|
||||||
* @see SQLUpdateAction
|
|
||||||
*/
|
|
||||||
@Nullable Integer executeSQL(String sql);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
|
* 执行一条不需要返回结果的SQL语句(多用于UPDATE、REPLACE、DELETE方法)
|
||||||
*
|
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||||
* @param sql SQL语句内容
|
*
|
||||||
* @param params SQL语句中 ? 的对应参数
|
* @param sql SQL语句内容
|
||||||
* @return 更新的行数
|
* @return 更新的行数
|
||||||
* @see PreparedSQLUpdateAction
|
* @see SQLUpdateAction
|
||||||
*/
|
*/
|
||||||
@Nullable Integer executeSQL(String sql, Object[] params);
|
@Nullable Integer executeSQL(String sql);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
|
* 执行一条不需要返回结果的预处理SQL更改(UPDATE、REPLACE、DELETE)
|
||||||
*
|
*
|
||||||
* @param sql SQL语句内容
|
* @param sql SQL语句内容
|
||||||
* @param paramsBatch SQL语句中对应?的参数组
|
* @param params SQL语句中 ? 的对应参数
|
||||||
* @return 对应参数返回的行数
|
* @return 更新的行数
|
||||||
* @see PreparedSQLUpdateBatchAction
|
* @see PreparedSQLUpdateAction
|
||||||
*/
|
*/
|
||||||
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
@Nullable Integer executeSQL(String sql, Object[] params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行多条不需要返回结果的SQL更改(UPDATE、REPLACE、DELETE)
|
||||||
|
*
|
||||||
|
* @param sql SQL语句内容
|
||||||
|
* @param paramsBatch SQL语句中对应?的参数组
|
||||||
|
* @return 对应参数返回的行数
|
||||||
|
* @see PreparedSQLUpdateBatchAction
|
||||||
|
*/
|
||||||
|
@Nullable List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行多条不需要返回结果的SQL。
|
* 执行多条不需要返回结果的SQL。
|
||||||
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
* 该方法使用 Statement 实现,请注意SQL注入风险!
|
||||||
*
|
*
|
||||||
* @param sql SQL语句内容
|
* @param sql SQL语句内容
|
||||||
* @param moreSQL 更多SQL语句内容
|
* @param moreSQL 更多SQL语句内容
|
||||||
* @return 对应参数返回的行数
|
* @return 对应参数返回的行数
|
||||||
* @see SQLUpdateBatchAction
|
* @see SQLUpdateBatchAction
|
||||||
*/
|
*/
|
||||||
@Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL);
|
@Nullable List<Integer> executeSQLBatch(@NotNull String sql, String... moreSQL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行多条不需要返回结果的SQL。
|
* 执行多条不需要返回结果的SQL。
|
||||||
*
|
*
|
||||||
* @param sqlBatch SQL语句内容
|
* @param sqlBatch SQL语句内容
|
||||||
* @return 对应参数返回的行数
|
* @return 对应参数返回的行数
|
||||||
*/
|
*/
|
||||||
@Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch);
|
@Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在库中创建一个表
|
* 在库中创建一个表
|
||||||
*
|
*
|
||||||
* @param tableName 表名
|
* @param tableName 表名
|
||||||
* @return {@link TableCreateBuilder}
|
* @return {@link TableCreateBuilder}
|
||||||
*/
|
*/
|
||||||
TableCreateBuilder createTable(@NotNull String tableName);
|
TableCreateBuilder createTable(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建一个查询
|
* 新建一个查询
|
||||||
*
|
*
|
||||||
* @return {@link QueryBuilder}
|
* @return {@link QueryBuilder}
|
||||||
*/
|
*/
|
||||||
QueryBuilder createQuery();
|
QueryBuilder createQuery();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一条插入操作
|
* 创建一条插入操作
|
||||||
*
|
*
|
||||||
* @param tableName 目标表名
|
* @param tableName 目标表名
|
||||||
* @return {@link InsertBuilder}
|
* @return {@link InsertBuilder}
|
||||||
*/
|
*/
|
||||||
InsertBuilder<PreparedSQLUpdateAction> createInsert(@NotNull String tableName);
|
InsertBuilder<PreparedSQLUpdateAction> createInsert(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建支持多组数据的插入操作
|
* 创建支持多组数据的插入操作
|
||||||
*
|
*
|
||||||
* @param tableName 目标表名
|
* @param tableName 目标表名
|
||||||
* @return {@link InsertBuilder}
|
* @return {@link InsertBuilder}
|
||||||
*/
|
*/
|
||||||
InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(@NotNull String tableName);
|
InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一条替换操作
|
* 创建一条替换操作
|
||||||
*
|
*
|
||||||
* @param tableName 目标表名
|
* @param tableName 目标表名
|
||||||
* @return {@link ReplaceBuilder}
|
* @return {@link ReplaceBuilder}
|
||||||
*/
|
*/
|
||||||
ReplaceBuilder<PreparedSQLUpdateAction> createReplace(@NotNull String tableName);
|
ReplaceBuilder<PreparedSQLUpdateAction> createReplace(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建支持多组数据的替换操作
|
* 创建支持多组数据的替换操作
|
||||||
*
|
*
|
||||||
* @param tableName 目标表名
|
* @param tableName 目标表名
|
||||||
* @return {@link ReplaceBuilder}
|
* @return {@link ReplaceBuilder}
|
||||||
*/
|
*/
|
||||||
ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(@NotNull String tableName);
|
ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建更新操作
|
* 创建更新操作
|
||||||
*
|
*
|
||||||
* @param tableName 目标表名
|
* @param tableName 目标表名
|
||||||
* @return {@link UpdateBuilder}
|
* @return {@link UpdateBuilder}
|
||||||
*/
|
*/
|
||||||
UpdateBuilder createUpdate(@NotNull String tableName);
|
UpdateBuilder createUpdate(@NotNull String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建删除操作
|
* 创建删除操作
|
||||||
*
|
*
|
||||||
* @param tableName 目标表名
|
* @param tableName 目标表名
|
||||||
* @return {@link DeleteBuilder}
|
* @return {@link DeleteBuilder}
|
||||||
*/
|
*/
|
||||||
DeleteBuilder createDelete(@NotNull String tableName);
|
DeleteBuilder createDelete(@NotNull String tableName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.2.7</version>
|
<version>0.2.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -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.2.7</version>
|
<version>0.2.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -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.2.7</version>
|
<version>0.2.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -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.2.7</version>
|
<version>0.2.8</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import cc.carm.lib.easysql.action.PreparedSQLUpdateActionImpl;
|
|||||||
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
|
import cc.carm.lib.easysql.action.SQLUpdateActionImpl;
|
||||||
import cc.carm.lib.easysql.action.SQLUpdateBatchActionImpl;
|
import cc.carm.lib.easysql.action.SQLUpdateBatchActionImpl;
|
||||||
import cc.carm.lib.easysql.api.SQLManager;
|
import cc.carm.lib.easysql.api.SQLManager;
|
||||||
|
import cc.carm.lib.easysql.api.SQLQuery;
|
||||||
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
||||||
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
||||||
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
||||||
import cc.carm.lib.easysql.api.SQLQuery;
|
|
||||||
import cc.carm.lib.easysql.api.builder.*;
|
import cc.carm.lib.easysql.api.builder.*;
|
||||||
import cc.carm.lib.easysql.builder.impl.*;
|
import cc.carm.lib.easysql.builder.impl.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -21,166 +21,168 @@ import java.util.*;
|
|||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class SQLManagerImpl implements SQLManager {
|
public class SQLManagerImpl implements SQLManager {
|
||||||
|
|
||||||
private final Logger LOGGER;
|
private final Logger LOGGER;
|
||||||
private final DataSource dataSource;
|
private final DataSource dataSource;
|
||||||
protected ExecutorService executorPool;
|
protected ExecutorService executorPool;
|
||||||
ConcurrentHashMap<UUID, SQLQuery> activeQuery = new ConcurrentHashMap<>();
|
ConcurrentHashMap<UUID, SQLQuery> activeQuery = new ConcurrentHashMap<>();
|
||||||
boolean debug = false;
|
|
||||||
|
|
||||||
public SQLManagerImpl(@NotNull DataSource dataSource) {
|
@NotNull Supplier<Boolean> debugMode = () -> false;
|
||||||
this(dataSource, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SQLManagerImpl(@NotNull DataSource dataSource, @Nullable String name) {
|
public SQLManagerImpl(@NotNull DataSource dataSource) {
|
||||||
String managerName = "SQLManager" + (name != null ? "#" + name : "");
|
this(dataSource, null);
|
||||||
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
|
public SQLManagerImpl(@NotNull DataSource dataSource, @Nullable String name) {
|
||||||
public boolean isDebugMode() {
|
String managerName = "SQLManager" + (name != null ? "#" + name : "");
|
||||||
return this.debug;
|
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
|
@Override
|
||||||
public void setDebugMode(boolean enable) {
|
public boolean isDebugMode() {
|
||||||
this.debug = enable;
|
return this.debugMode.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(String msg) {
|
@Override
|
||||||
if (isDebugMode()) getLogger().info("[DEBUG] " + msg);
|
public void setDebugMode(@NotNull Supplier<@NotNull Boolean> debugMode) {
|
||||||
}
|
this.debugMode = debugMode;
|
||||||
|
}
|
||||||
|
|
||||||
public Logger getLogger() {
|
public void debug(String msg) {
|
||||||
return LOGGER;
|
if (isDebugMode()) getLogger().info("[DEBUG] " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutorService getExecutorPool() {
|
public Logger getLogger() {
|
||||||
return executorPool;
|
return LOGGER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ExecutorService getExecutorPool() {
|
||||||
public @NotNull DataSource getDataSource() {
|
return executorPool;
|
||||||
return this.dataSource;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Connection getConnection() throws SQLException {
|
public @NotNull DataSource getDataSource() {
|
||||||
return getDataSource().getConnection();
|
return this.dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Map<UUID, SQLQuery> getActiveQuery() {
|
public @NotNull Connection getConnection() throws SQLException {
|
||||||
return this.activeQuery;
|
return getDataSource().getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer executeSQL(String sql) {
|
public @NotNull Map<UUID, SQLQuery> getActiveQuery() {
|
||||||
return new SQLUpdateActionImpl(this, sql).execute(null);
|
return this.activeQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer executeSQL(String sql, Object[] params) {
|
public Integer executeSQL(String sql) {
|
||||||
return new PreparedSQLUpdateActionImpl(this, sql, params).execute(null);
|
return new SQLUpdateActionImpl(this, sql).execute(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
|
public Integer executeSQL(String sql, Object[] params) {
|
||||||
return new PreparedSQLBatchUpdateActionImpl(this, sql)
|
return new PreparedSQLUpdateActionImpl(this, sql, params).execute(null);
|
||||||
.setAllParams(paramsBatch)
|
}
|
||||||
.execute(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> executeSQLBatch(@NotNull String sql, String[] moreSQL) {
|
public List<Integer> executeSQLBatch(String sql, Iterable<Object[]> paramsBatch) {
|
||||||
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, sql);
|
return new PreparedSQLBatchUpdateActionImpl(this, sql)
|
||||||
if (moreSQL != null && moreSQL.length > 0) {
|
.setAllParams(paramsBatch)
|
||||||
Arrays.stream(moreSQL).forEach(action::addBatch);
|
.execute(null);
|
||||||
}
|
}
|
||||||
return action.execute(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch) {
|
public List<Integer> executeSQLBatch(@NotNull String sql, String[] moreSQL) {
|
||||||
Iterator<String> iterator = sqlBatch.iterator();
|
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, sql);
|
||||||
if (!iterator.hasNext()) return null; // PLEASE GIVE IT SOMETHING
|
if (moreSQL != null && moreSQL.length > 0) {
|
||||||
|
Arrays.stream(moreSQL).forEach(action::addBatch);
|
||||||
|
}
|
||||||
|
return action.execute(null);
|
||||||
|
}
|
||||||
|
|
||||||
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, iterator.next());
|
@Override
|
||||||
while (iterator.hasNext()) {
|
public @Nullable List<Integer> executeSQLBatch(@NotNull Iterable<String> sqlBatch) {
|
||||||
action.addBatch(iterator.next());
|
Iterator<String> iterator = sqlBatch.iterator();
|
||||||
}
|
if (!iterator.hasNext()) return null; // PLEASE GIVE IT SOMETHING
|
||||||
|
|
||||||
return action.execute(null);
|
SQLUpdateBatchAction action = new SQLUpdateBatchActionImpl(this, iterator.next());
|
||||||
}
|
while (iterator.hasNext()) {
|
||||||
|
action.addBatch(iterator.next());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return action.execute(null);
|
||||||
public TableCreateBuilder createTable(@NotNull String tableName) {
|
}
|
||||||
return new TableCreateBuilderImpl(this, tableName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryBuilder createQuery() {
|
public TableCreateBuilder createTable(@NotNull String tableName) {
|
||||||
return new QueryBuilderImpl(this);
|
return new TableCreateBuilderImpl(this, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(@NotNull String tableName) {
|
public QueryBuilder createQuery() {
|
||||||
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction>(this, tableName) {
|
return new QueryBuilderImpl(this);
|
||||||
@Override
|
}
|
||||||
public PreparedSQLUpdateBatchAction setColumnNames(List<String> columnNames) {
|
|
||||||
return new PreparedSQLBatchUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InsertBuilder<PreparedSQLUpdateAction> createInsert(@NotNull String tableName) {
|
public InsertBuilder<PreparedSQLUpdateBatchAction> createInsertBatch(@NotNull String tableName) {
|
||||||
return new InsertBuilderImpl<PreparedSQLUpdateAction>(this, tableName) {
|
return new InsertBuilderImpl<PreparedSQLUpdateBatchAction>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateAction setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateBatchAction setColumnNames(List<String> columnNames) {
|
||||||
return new PreparedSQLUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
return new PreparedSQLBatchUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(@NotNull String tableName) {
|
public InsertBuilder<PreparedSQLUpdateAction> createInsert(@NotNull String tableName) {
|
||||||
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction>(this, tableName) {
|
return new InsertBuilderImpl<PreparedSQLUpdateAction>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateBatchAction setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateAction setColumnNames(List<String> columnNames) {
|
||||||
return new PreparedSQLBatchUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
return new PreparedSQLUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReplaceBuilder<PreparedSQLUpdateAction> createReplace(@NotNull String tableName) {
|
public ReplaceBuilder<PreparedSQLUpdateBatchAction> createReplaceBatch(@NotNull String tableName) {
|
||||||
return new ReplaceBuilderImpl<PreparedSQLUpdateAction>(this, tableName) {
|
return new ReplaceBuilderImpl<PreparedSQLUpdateBatchAction>(this, tableName) {
|
||||||
@Override
|
@Override
|
||||||
public PreparedSQLUpdateAction setColumnNames(List<String> columnNames) {
|
public PreparedSQLUpdateBatchAction setColumnNames(List<String> columnNames) {
|
||||||
return new PreparedSQLUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
return new PreparedSQLBatchUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UpdateBuilder createUpdate(@NotNull String tableName) {
|
public ReplaceBuilder<PreparedSQLUpdateAction> createReplace(@NotNull String tableName) {
|
||||||
return new UpdateBuilderImpl(this, tableName);
|
return new ReplaceBuilderImpl<PreparedSQLUpdateAction>(this, tableName) {
|
||||||
}
|
@Override
|
||||||
|
public PreparedSQLUpdateAction setColumnNames(List<String> columnNames) {
|
||||||
|
return new PreparedSQLUpdateActionImpl(getManager(), buildSQL(getTableName(), columnNames));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeleteBuilder createDelete(@NotNull String tableName) {
|
public UpdateBuilder createUpdate(@NotNull String tableName) {
|
||||||
return new DeleteBuilderImpl(this, tableName);
|
return new UpdateBuilderImpl(this, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeleteBuilder createDelete(@NotNull String tableName) {
|
||||||
|
return new DeleteBuilderImpl(this, tableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,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.2.7</version>
|
<version>0.2.8</version>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>easysql-api</module>
|
<module>easysql-api</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user