mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-13 21:01:08 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 010b5d846a | |||
| 1c650b53eb | |||
| e001050f15 | |||
| a461932135 | |||
| 5ecd7f54e2 | |||
| 2321ed35c2 | |||
| 38afb05fc8 |
@@ -0,0 +1,27 @@
|
||||
# MineSQL Repository
|
||||
|
||||
采用github的repo分支进行依赖,随项目发布而自动更新。
|
||||
|
||||
其他依赖方式见主页介绍。
|
||||
|
||||
## 依赖方式
|
||||
|
||||
### Maven
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>MineSQL</id>
|
||||
<name>GitHub Branch Repository</name>
|
||||
<url>https://github.com/CarmJos/MineSQL/blob/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
|
||||
### Gradle
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
maven { url 'https://github.com/CarmJos/MineSQL/blob/repo/' }
|
||||
}
|
||||
```
|
||||
@@ -8,8 +8,8 @@ on:
|
||||
types: [ published ]
|
||||
|
||||
jobs:
|
||||
gh-deploy:
|
||||
name: "Deploy Project (GitHub)"
|
||||
packages-deploy:
|
||||
name: "Deploy Project (GitHub Packages)"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -43,6 +43,81 @@ jobs:
|
||||
asset_path: ".asset/*.jar"
|
||||
asset_content_type: application/java-archive
|
||||
|
||||
github-deploy:
|
||||
name: "Deploy Project (GitHub Repo)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
|
||||
- name: "Maven Deploy"
|
||||
run: mvn -B -Plocal deploy --file pom.xml -DskipTests -Dgpg.skip
|
||||
|
||||
- name: "Copy artifacts"
|
||||
run: |
|
||||
rm -rf deploy
|
||||
mkdir -vp deploy
|
||||
cp -vrf $HOME/local-deploy/* deploy/
|
||||
cp -vrf .documentation/repository/REPO-README.md deploy/README.md
|
||||
|
||||
- name: "Copy Javadoc"
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf api/target/apidocs/* docs/
|
||||
cp -vrf .documentation/javadoc/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: "Generate Javadoc sitemap"
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||
path-to-root: docs
|
||||
|
||||
- name: "Output Javadoc 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 }}"
|
||||
ls -l docs
|
||||
|
||||
- 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 '${{ github.repository_owner }}'
|
||||
git config --global user.email '${{ github.repository_owner }}@users.noreply.github.com'
|
||||
|
||||
- name: "Commit&Push repository files"
|
||||
run: |
|
||||
cd deploy
|
||||
git init
|
||||
git remote add origin git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git
|
||||
git checkout -b repo
|
||||
git add -A
|
||||
git commit -m "Maven project deployment."
|
||||
git push origin HEAD:repo --force
|
||||
|
||||
- name: "Commit&Push API documentation"
|
||||
run: |
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
git push origin HEAD:gh-pages --force
|
||||
|
||||
central-deploy:
|
||||
name: "Deploy Project (Central)"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
name: "Publish Javadoc"
|
||||
|
||||
on:
|
||||
# 支持手动触发构建
|
||||
workflow_dispatch:
|
||||
release:
|
||||
# 创建release的时候触发
|
||||
types: [ published ]
|
||||
|
||||
|
||||
jobs:
|
||||
|
||||
javadoc-deploy:
|
||||
name: "Deploy Javadoc (Github Pages)"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: "Set up JDK"
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: '8'
|
||||
distribution: 'adopt'
|
||||
cache: maven
|
||||
|
||||
- name: "Generate Javadoc"
|
||||
run: mvn -B javadoc:javadoc -pl api --file pom.xml -DskipTests
|
||||
|
||||
- name: "Copy Javadoc"
|
||||
run: |
|
||||
rm -rf docs
|
||||
mkdir -vp docs
|
||||
cp -vrf api/target/site/apidocs/* docs/
|
||||
cp -vrf .doc/javadoc/JAVADOC-README.md docs/README.md
|
||||
|
||||
- name: "Generate Sitemap"
|
||||
id: sitemap
|
||||
uses: cicirello/generate-sitemap@v1
|
||||
with:
|
||||
base-url-path: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
|
||||
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 }}"
|
||||
ls -l docs
|
||||
|
||||
- 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 '${{ github.repository_owner }}'
|
||||
git config --global user.email '${{ github.repository_owner }}@users.noreply.github.com'
|
||||
|
||||
- name: Commit documentation changes
|
||||
run: |
|
||||
echo "Committing changes to git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git ..."
|
||||
cd docs
|
||||
git init
|
||||
git remote add origin git@github.com:${{ github.repository_owner }}/${{ github.event.repository.name }}.git
|
||||
git checkout -b gh-pages
|
||||
git add -A
|
||||
git commit -m "API Document generated."
|
||||
|
||||
- name: Javadoc Website Push
|
||||
run: |
|
||||
cd docs
|
||||
git push origin HEAD:gh-pages --force
|
||||
@@ -7,6 +7,7 @@
|
||||
```
|
||||
|
||||
# MineSQL (EasySQL-Plugin)
|
||||
|
||||
[](https://github.com/CarmJos/MineSQL/releases)
|
||||
[](https://opensource.org/licenses/GPL-3.0)
|
||||
[](https://github.com/CarmJos/MineSQL/actions/workflows/maven.yml)
|
||||
@@ -16,30 +17,52 @@
|
||||
|
||||
轻松(用)SQL的独立运行库插件,支持多种服务端,适用于MineCraft全版本。
|
||||
|
||||
## 使用场景
|
||||
## 优势
|
||||
|
||||
### 对于插件使用者
|
||||
### 对于服主 (插件使用者)
|
||||
|
||||
- 统一配置数据库连接,避免重复配置费时费力分神。
|
||||
-
|
||||
|
||||
支持更高级更全面的配置方式,以根据不同的使用场景独立优化[连接池配置](https://github.com/Chris2018998/BeeCP/wiki/Configuration--List)
|
||||
。
|
||||
|
||||
- 使相关插件共用连接池,避免每个插件单独新开连接池导致资源的浪费。
|
||||
|
||||
### 对于插件开发者
|
||||
|
||||
- 基于 [EasySQL](https://github.com/CarmJos/EasySQL) 进行快捷的数据库操作。
|
||||
- 通过 `MineSQL.getRegistry().get(database-name)` 快捷获取数据源,避免繁琐的链接过程。
|
||||
- 详细的 DEBUG 方法,找到可恶的错误究竟在哪。
|
||||
- 不再需要打包各类JDBC-Driver、连接池依赖以及EasySQL本体到插件中。
|
||||
|
||||
### 额外提醒
|
||||
|
||||
- 使用本依赖时,请保证其他插件的来源安全,避免可能带来的数据安全风险。
|
||||
|
||||
## 安装
|
||||
|
||||
1. 从 [Releases(发行)](https://github.com/CarmJos/MineSQL/releases/)
|
||||
中点击 [最新版](https://github.com/CarmJos/MineSQL/releases/latest) 下载 `MineSQL-x.y.z.jar` 。
|
||||
2. 将下载的 `MineSQL-x.y.z.jar` 放入服务器 `plugins/` 文件夹下。
|
||||
3. 启动服务器,预加载配置文件后关闭服务器。
|
||||
4. 修改 `plugins/MineSQL/config.yml` 以配置您的数据库选项。
|
||||
5. 启动服务器,若配置无误,则您会看到 MineSQL一切正常的提示消息。
|
||||
|
||||
## 配置
|
||||
|
||||
### 插件配置文件 [`config.yml`](minesql-core/src/main/resources/config.yml)
|
||||
### 插件配置文件 [`config.yml`](.doc/example-config.yml)
|
||||
|
||||
完整示例配置请见 [源文件](minesql-core/src/main/resources/config.yml)。
|
||||
完整示例配置请见 [示例配置文件](.doc/example-config.yml)。
|
||||
|
||||
#### MySQL/MariaDB 数据源详细配置示例
|
||||
|
||||
```yaml
|
||||
databases:
|
||||
sources:
|
||||
"mysql-database": # 数据源ID,建议全英文小写并以“-”分隔,例如:hello-minecraft
|
||||
# 数据库驱动类型
|
||||
# 若您的数据库为 mariadb,则强烈推荐设置为 mariadb
|
||||
driver-type: mysql
|
||||
type: mysql
|
||||
host: 127.0.0.1 # 数据库地址
|
||||
port: 3306 # 数据库端口
|
||||
database: minecraft # 数据库库名
|
||||
@@ -50,20 +73,21 @@ databases:
|
||||
#### h2 数据源详细配置示例
|
||||
|
||||
```yaml
|
||||
databases:
|
||||
"h2-database": # 数据源ID,建议全小写以“-”分隔,例如:hello-minecraft
|
||||
driver-type: h2
|
||||
# h2数据库运行模式
|
||||
# 可选 file(文件模式) 与 mem(内存模式)
|
||||
# 文件模式下,须指定 file-path ,以服务器运行目录为基准,支持绝对路径和相对路径。
|
||||
# 内存模式下,所有数据库都将存储在内存中,一旦关服则数据将全部丢失,该模式一般用于测试
|
||||
mode: file # 可选 mem(内存) file(文件) ;内存模式
|
||||
sources:
|
||||
# h2数据库运行模式
|
||||
# 可选 h2-file(文件模式) 与 h2-mem(内存模式)
|
||||
# 文件模式下,须指定 file路径 ,以服务器运行目录为基准,支持绝对路径和相对路径。
|
||||
# 内存模式下,所有数据库都将存储在内存中,一旦关服则数据将全部丢失,该模式一般用于测试
|
||||
"h2-file-db": # 数据源ID,建议全小写以“-”分隔,例如:hello-minecraft
|
||||
type: h2-file
|
||||
file-path: "db-files/minecraft"
|
||||
"h2-mem-db": # 数据源ID,建议全小写以“-”分隔,例如:hello-minecraft
|
||||
type: h2-mem
|
||||
```
|
||||
|
||||
### Properties 配置文件 [`<插件目录>/db-properties/*.properties`](minesql-core/src/main/resources/db-properties/.example-mysql.properties)
|
||||
### Properties 配置文件 [`<插件目录>/db-properties/*.properties`](core/src/main/resources/db-properties/.example-mysql.properties)
|
||||
|
||||
示例配置请见 [示例MySQL数据源Properties](minesql-core/src/main/resources/db-properties/.example-mysql.properties)。
|
||||
示例配置请见 [示例MySQL数据源Properties](core/src/main/resources/db-properties/.example-mysql.properties)。
|
||||
|
||||
Properties 文件的文件名几位数据源的ID,允许为英文、数字、下划线、短横线;请不要包含中文、其他特殊符号与空格,以`.`开头的文件将被忽略。
|
||||
|
||||
@@ -71,6 +95,24 @@ Properties 文件的文件名几位数据源的ID,允许为英文、数字、
|
||||
|
||||
更多帮助详见 [BeeCP项目帮助](https://github.com/Chris2018998/BeeCP) 。
|
||||
|
||||
## 指令
|
||||
|
||||
插件主指令为 `/minesql` ,所有指令只允许后台执行。
|
||||
|
||||
```text
|
||||
# help
|
||||
- 查看插件指令帮助。
|
||||
|
||||
# version
|
||||
- 查看当前插件、核心库(EasySQL)与连接池依赖版本。
|
||||
|
||||
# list
|
||||
- 列出当前所有的数据源管理器与相关信息。
|
||||
|
||||
# info <数据源名称>
|
||||
- 查看指定数据源的统计信息与当前仍未关闭的查询。
|
||||
```
|
||||
|
||||
## 开发
|
||||
|
||||
### 依赖方式
|
||||
@@ -91,10 +133,10 @@ Properties 文件的文件名几位数据源的ID,允许为英文、数字、
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||
<!--采用github分支依赖库,稳定更新快-->
|
||||
<id>MineSQL</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/MineSQL</url>
|
||||
<name>GitHub Branch Repository</name>
|
||||
<url>https://github.com/CarmJos/MineSQL/blob/repo/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
@@ -130,8 +172,8 @@ repositories {
|
||||
//采用Maven中心库,安全稳定,但版本更新需要等待同步
|
||||
mavenCentral()
|
||||
|
||||
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||
maven { url 'https://maven.pkg.github.com/CarmJos/MineSQL' }
|
||||
// 采用github分支依赖库,稳定更新快
|
||||
maven { url 'https://github.com/CarmJos/MineSQL/blob/repo/' }
|
||||
|
||||
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||
@@ -144,24 +186,41 @@ dependencies {
|
||||
|
||||
</details>
|
||||
|
||||
## 指令
|
||||
### 操作示例
|
||||
|
||||
插件主指令为 `/easysql` ,所有指令只允许后台执行。
|
||||
本插件接口入口类为 `MineSQL` ,更多方法详见 [MineSQL-Javadoc](https://carmjos.github.io/MineSQL/) 。
|
||||
|
||||
```text
|
||||
# help
|
||||
- 查看插件指令帮助。
|
||||
关于 EasySQL的使用方法,请详见 [EasySQL开发文档](https://github.com/CarmJos/EasySQL/tree/master/.documentation) 。
|
||||
|
||||
# version
|
||||
- 查看当前插件、核心库(EasySQL)与连接池依赖版本。
|
||||
|
||||
# list
|
||||
- 列出当前所有的数据源管理器与相关信息。
|
||||
<details>
|
||||
<summary>点击查看简单实例</summary>
|
||||
|
||||
```java
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
SQLManager manager = MineSQL.getRegistery().get(getConfig().getString("database"));
|
||||
|
||||
if (manager == null) {
|
||||
System.out.println("请配置一个正确的数据库名。");
|
||||
setEnable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// do something...
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
# info <数据源名称>
|
||||
- 查看指定数据源的统计信息与当前仍未关闭的查询。
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## 开源协议
|
||||
|
||||
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ interface IMineSQL {
|
||||
|
||||
@NotNull SQLRegistry getRegistry();
|
||||
|
||||
@NotNull SQLRegistry createRegistry();
|
||||
|
||||
/**
|
||||
* 创建一个新的 SQLManager 实例
|
||||
*
|
||||
|
||||
@@ -43,6 +43,15 @@ public class MineSQL {
|
||||
return instance.getRegistry();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个独立的管理器注册池。
|
||||
*
|
||||
* @return {@link SQLRegistry}
|
||||
*/
|
||||
public static @NotNull SQLRegistry createRegistry() {
|
||||
return instance.createRegistry();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个新的 SQLManager 实例
|
||||
*
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.Optional;
|
||||
*/
|
||||
public interface SQLRegistry {
|
||||
|
||||
|
||||
/**
|
||||
* 获取原生注册的指定名称的 SQLManager 实例
|
||||
*
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
|
||||
@@ -29,6 +29,8 @@ import java.util.logging.Logger;
|
||||
|
||||
public class MineSQLCore implements IMineSQL {
|
||||
|
||||
protected static MineSQLCore instance;
|
||||
|
||||
public static final String REPO_OWNER = "CarmJos";
|
||||
public static final String REPO_NAME = "MineSQL";
|
||||
|
||||
@@ -39,6 +41,7 @@ public class MineSQLCore implements IMineSQL {
|
||||
protected final PluginConfiguration config;
|
||||
|
||||
public MineSQLCore(MineSQLPlatform platform) {
|
||||
instance = this;
|
||||
this.platform = platform;
|
||||
|
||||
getLogger().info("加载配置文件...");
|
||||
@@ -50,18 +53,59 @@ public class MineSQLCore implements IMineSQL {
|
||||
MineSQL.initializeAPI(this);
|
||||
|
||||
getLogger().info("初始化注册池...");
|
||||
this.registry = new MineSQLRegistry(this);
|
||||
this.registry = createRegistry();
|
||||
|
||||
Map<String, Properties> dbProperties = readProperties();
|
||||
Map<String, SQLSourceConfig> dbConfigurations = readConfigurations();
|
||||
|
||||
if (dbProperties.isEmpty() && dbConfigurations.isEmpty()) {
|
||||
getLogger().warning("未检测到任何数据库配置,将不会预创建任何SQLManager。");
|
||||
return;
|
||||
}
|
||||
|
||||
dbProperties.forEach((id, properties) -> {
|
||||
try {
|
||||
getLogger().info("正在初始化数据库 #" + id + " ...");
|
||||
SQLManagerImpl sqlManager = create(id, properties);
|
||||
this.registry.getManagers().put(id, sqlManager);
|
||||
getLogger().info("完成成初始化数据库 #" + id + " 。");
|
||||
} catch (Exception ex) {
|
||||
getLogger().severe("初始化SQLManager(#" + id + ") 出错,请检查配置文件: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
dbConfigurations.forEach((id, configuration) -> {
|
||||
try {
|
||||
getLogger().info("正在初始化数据库 #" + id + " ...");
|
||||
SQLManagerImpl sqlManager = create(id, configuration);
|
||||
this.registry.getManagers().put(id, sqlManager);
|
||||
getLogger().info("完成初始化数据库 #" + id + " 。");
|
||||
} catch (Exception ex) {
|
||||
getLogger().severe("初始化SQLManager(#" + id + ") 出错,请检查配置文件: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MineSQLPlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public static MineSQLCore getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull MineSQLRegistry getRegistry() {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull MineSQLRegistry createRegistry() {
|
||||
return new MineSQLRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SQLManagerImpl create(@NotNull String name, @NotNull SQLSourceConfig conf) {
|
||||
BeeDataSourceConfig config = new BeeDataSourceConfig();
|
||||
|
||||
@@ -1,84 +1,24 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import cc.carm.plugin.minesql.api.SQLRegistry;
|
||||
import cc.carm.plugin.minesql.api.source.SQLSourceConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MineSQLRegistry implements SQLRegistry {
|
||||
|
||||
private static MineSQLRegistry instance;
|
||||
|
||||
protected ExecutorService executorPool;
|
||||
protected MineSQLCore core;
|
||||
private final HashMap<String, SQLManager> managers = new HashMap<>();
|
||||
|
||||
protected MineSQLRegistry(@NotNull MineSQLCore core) {
|
||||
this.core = core;
|
||||
MineSQLRegistry.instance = this;
|
||||
this.executorPool = Executors.newFixedThreadPool(2, (r) -> {
|
||||
Thread thread = new Thread(r, "EasySQLRegistry");
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
|
||||
Map<String, Properties> dbProperties = core.readProperties();
|
||||
Map<String, SQLSourceConfig> dbConfigurations = core.readConfigurations();
|
||||
|
||||
if (dbProperties.isEmpty() && dbConfigurations.isEmpty()) {
|
||||
core.getLogger().warning("未检测到任何数据库配置,将不会预创建任何SQLManager。");
|
||||
return;
|
||||
}
|
||||
|
||||
dbProperties.forEach((id, properties) -> {
|
||||
try {
|
||||
core.getLogger().info("正在初始化数据库 #" + id + " ...");
|
||||
SQLManagerImpl sqlManager = this.core.create(id, properties);
|
||||
this.managers.put(id, sqlManager);
|
||||
core.getLogger().info("完成成初始化数据库 #" + id + " 。");
|
||||
} catch (Exception ex) {
|
||||
core.getLogger().severe("初始化SQLManager(#" + id + ") 出错,请检查配置文件: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
dbConfigurations.forEach((id, configuration) -> {
|
||||
try {
|
||||
core.getLogger().info("正在初始化数据库 #" + id + " ...");
|
||||
SQLManagerImpl sqlManager = this.core.create(id, configuration);
|
||||
this.managers.put(id, sqlManager);
|
||||
core.getLogger().info("完成初始化数据库 #" + id + " 。");
|
||||
} catch (Exception ex) {
|
||||
core.getLogger().severe("初始化SQLManager(#" + id + ") 出错,请检查配置文件: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected HashMap<String, SQLManager> getManagers() {
|
||||
return managers;
|
||||
}
|
||||
|
||||
public ExecutorService getExecutor() {
|
||||
return executorPool;
|
||||
}
|
||||
|
||||
public static MineSQLRegistry getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public MineSQLCore getCore() {
|
||||
return core;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<@Nullable SQLManager> getOptional(@Nullable String id) {
|
||||
return Optional.of(this.managers.get(id));
|
||||
|
||||
@@ -3,7 +3,6 @@ package cc.carm.plugin.minesql.command;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.SQLQuery;
|
||||
import cc.carm.plugin.minesql.MineSQLCore;
|
||||
import cc.carm.plugin.minesql.MineSQLRegistry;
|
||||
import cc.carm.plugin.minesql.util.VersionReader;
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.CommandHelp;
|
||||
@@ -66,7 +65,7 @@ public class MineSQLCommand extends BaseCommand {
|
||||
issuer.sendMessage("§c只有后台执行才能使用此命令。");
|
||||
return;
|
||||
}
|
||||
Map<String, ? extends SQLManager> runningManagers = MineSQLRegistry.getInstance().list();
|
||||
Map<String, ? extends SQLManager> runningManagers = MineSQLCore.getInstance().getRegistry().list();
|
||||
if (runningManagers.isEmpty()) {
|
||||
issuer.sendMessage("§r当前无正在运行的数据库管理器。");
|
||||
} else {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.1</version>
|
||||
<modules>
|
||||
<module>api</module>
|
||||
<module>core</module>
|
||||
@@ -62,6 +62,13 @@
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:CarmJos/MineSQL</connection>
|
||||
<developerConnection>scm:git:git@github.com:CarmJos/MineSQL.git</developerConnection>
|
||||
<url>https://github.com/CarmJos/MineSQL</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
@@ -81,11 +88,6 @@
|
||||
|
||||
<distributionManagement>
|
||||
<downloadUrl>https://github.com/CarmJos/MineSQL/releases</downloadUrl>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/MineSQL</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<repositories>
|
||||
@@ -199,6 +201,37 @@
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<configuration>
|
||||
<autoVersionSubmodules>true</autoVersionSubmodules>
|
||||
<useReleaseProfile>false</useReleaseProfile>
|
||||
<releaseProfiles>release</releaseProfiles>
|
||||
<goals>deploy</goals>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
@@ -241,5 +274,48 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>ossrh</id>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</snapshotRepository>
|
||||
|
||||
<repository>
|
||||
<id>ossrh</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>github</id>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/MineSQL</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>local</id>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>localRepository</id>
|
||||
<url>file:${user.home}/local-deploy/</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>localRepository</id>
|
||||
<url>file:${user.home}/local-deploy/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user