1
mirror of https://github.com/CarmJos/MineSQL.git synced 2026-06-04 16:43:03 +08:00

修改文件夹名称

This commit is contained in:
2022-03-13 19:42:48 +08:00
parent aa83feea05
commit a2ab7d4d9f
31 changed files with 7 additions and 7 deletions
+109
View File
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>easysql-plugin</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>0.0.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<artifactId>easysql-plugin-api</artifactId>
<packaging>jar</packaging>
<name>EasySQL-Plugin-API</name>
<description>轻松(用)SQL的独立运行库插件的公用API接口部分。</description>
<url>https://github.com/CarmJos/EasySQL-Plugin</url>
<developers>
<developer>
<id>CarmJos</id>
<name>Carm Jos</name>
<email>carm@carm.cc</email>
<url>https://www.carm.cc</url>
<roles>
<role>Main Developer</role>
<role>Designer</role>
</roles>
</developer>
</developers>
<licenses>
<license>
<name>GNU General Public License v3.0</name>
<url>https://opensource.org/licenses/GPL-3.0</url>
</license>
</licenses>
<issueManagement>
<system>GitHub Issues</system>
<url>https://github.com/CarmJos/EasySQL-Plugin/issues</url>
</issueManagement>
<ciManagement>
<system>GitHub Actions</system>
<url>https://github.com/CarmJos/EasySQL-Plugin/actions/workflows/maven.yml</url>
</ciManagement>
<dependencies>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<classifier>javadoc</classifier>
<detectJavaApiLink>false</detectJavaApiLink>
<encoding>UTF-8</encoding>
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
<locale>zh_CN</locale>
<includeDependencySources>true</includeDependencySources>
<dependencySourceIncludes>cc.carm.lib:easysql-api</dependencySourceIncludes>
<dependencySourceIncludes>cc.carm.plugin:*</dependencySourceIncludes>
<outputDirectory>${project.parent.basedir}/api-docs/</outputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,17 @@
package cc.carm.plugin.easysql;
import cc.carm.plugin.easysql.api.EasySQLRegistry;
public class EasySQLAPI {
protected static EasySQLRegistry api;
protected static void initializeAPI(EasySQLRegistry api) {
EasySQLAPI.api = api;
}
public static EasySQLRegistry get() {
return api;
}
}
@@ -0,0 +1,226 @@
package cc.carm.plugin.easysql.api;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
public class DBConfiguration {
public static DBConfiguration create(@NotNull SQLDriverType sourceType, @NotNull String url) {
return new DBConfiguration(sourceType.getDriverClass(), sourceType.getUrlPrefix(), url, sourceType.getInitializeSQLs());
}
private final @NotNull String driverClassName;
private final @NotNull String urlPrefix;
private final @NotNull List<String> initializeSQLs;
private @NotNull String url;
private @Nullable String username;
private @Nullable String password;
private @Nullable String connectionInitSql;
private @Nullable String poolName;
private @Nullable Integer maxPoolSize;
private @Nullable Integer maxActive;
private @Nullable Integer maxHoldTime;
private @Nullable Long idleTimeout;
private @Nullable Long maxWaitTime;
private @Nullable String schema;
private @Nullable Boolean autoCommit;
private @Nullable Boolean readOnly;
private @Nullable String validationSQL;
private @Nullable Integer validationTimeout;
private @Nullable Long validationInterval;
private DBConfiguration(@NotNull String driverClass, @NotNull String urlPrefix,
@NotNull String url, @NotNull String[] initializeSQLs) {
this.driverClassName = driverClass;
this.urlPrefix = urlPrefix;
this.url = url;
this.initializeSQLs = Arrays.asList(initializeSQLs);
}
public @NotNull String getDriverClassName() {
return driverClassName;
}
public @NotNull String getUrlPrefix() {
return urlPrefix;
}
public @NotNull List<String> getInitializeSQLs() {
return initializeSQLs;
}
public DBConfiguration setInitializeSQLs(@Nullable String[] initializeSQLs) {
this.initializeSQLs.clear();
this.initializeSQLs.addAll(Arrays.asList(initializeSQLs));
return this;
}
public DBConfiguration addInitializeSQL(@NotNull String initializeSQL) {
this.initializeSQLs.add(initializeSQL);
return this;
}
public DBConfiguration clearExtraSettings() {
this.initializeSQLs.clear();
return this;
}
public @NotNull String getUrl() {
return url;
}
public DBConfiguration setUrl(String url) {
this.url = url;
return this;
}
public @Nullable String getUsername() {
return username;
}
public DBConfiguration setUsername(String username) {
this.username = username;
return this;
}
public @Nullable String getPassword() {
return password;
}
public DBConfiguration setPassword(String password) {
this.password = password;
return this;
}
public @Nullable String getConnectionInitSql() {
return connectionInitSql;
}
public DBConfiguration setConnectionInitSql(String connectionInitSql) {
this.connectionInitSql = connectionInitSql;
return this;
}
public @Nullable String getValidationSQL() {
return validationSQL;
}
public DBConfiguration setValidationSQL(String validationSQL) {
this.validationSQL = validationSQL;
return this;
}
public @Nullable Long getValidationInterval() {
return validationInterval;
}
public DBConfiguration setValidationInterval(@Nullable Long validationInterval) {
this.validationInterval = validationInterval;
return this;
}
public @Nullable String getPoolName() {
return poolName;
}
public DBConfiguration setPoolName(String poolName) {
this.poolName = poolName;
return this;
}
public @Nullable String getSchema() {
return schema;
}
public DBConfiguration setSchema(String schema) {
this.schema = schema;
return this;
}
public @Nullable Boolean getAutoCommit() {
return autoCommit;
}
public DBConfiguration setAutoCommit(Boolean autoCommit) {
this.autoCommit = autoCommit;
return this;
}
public @Nullable Boolean getReadOnly() {
return readOnly;
}
public DBConfiguration setReadOnly(Boolean readOnly) {
this.readOnly = readOnly;
return this;
}
public @Nullable Integer getMaxHoldTime() {
return maxHoldTime;
}
public DBConfiguration setMaxHoldTime(@Nullable Integer maxHoldTime) {
this.maxHoldTime = maxHoldTime;
return this;
}
public @Nullable Integer getValidationTimeout() {
return validationTimeout;
}
public DBConfiguration setValidationTimeout(Integer validationTimeout) {
this.validationTimeout = validationTimeout;
return this;
}
public @Nullable Long getIdleTimeout() {
return idleTimeout;
}
public DBConfiguration setIdleTimeout(Long idleTimeout) {
this.idleTimeout = idleTimeout;
return this;
}
public @Nullable Integer getMaxActive() {
return maxActive;
}
public DBConfiguration setMaxActive(Integer maxActive) {
this.maxActive = maxActive;
return this;
}
public @Nullable Integer getMaxPoolSize() {
return maxPoolSize;
}
public DBConfiguration setMaxPoolSize(@Nullable Integer maxPoolSize) {
this.maxPoolSize = maxPoolSize;
return this;
}
public @Nullable Long getMaxWaitTime() {
return maxWaitTime;
}
public DBConfiguration setMaxWaitTime(Long maxWaitTime) {
this.maxWaitTime = maxWaitTime;
return this;
}
}
@@ -0,0 +1,108 @@
package cc.carm.plugin.easysql.api;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.SQLQuery;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.UUID;
import java.util.function.Consumer;
/**
* 入口类
*/
public interface EasySQLRegistry {
/**
* 获取原生注册的指定名称的 SQLManager 实例
*
* @param name 要获取的 SQLManager 实例名称, 如果为 null 则获取首个实例
* @return {@link SQLManager} 实例
* @throws NullPointerException 若不存在对应实例则抛出空指针异常
*/
@NotNull SQLManager get(@Nullable String name) throws NullPointerException;
/**
* 获取原生注册的指定名称的 SQLManager 实例
*
* @param name 要获取的 SQLManager 实例名称, 如果为 null 则获取首个实例
* @return {@link SQLManager} 实例
*/
@NotNull Optional<? extends SQLManager> getOptional(@Nullable String name);
/**
* 获取某命名空间下所有 SQLManager 实例
*
* @return {@link SQLManager} 实例集合
*/
@Unmodifiable
@NotNull Map<String, ? extends SQLManager> list();
/**
* 创建并注册一个新的 SQLManager 实例
*
* @param name 实例名称
* @param configuration SQLManager 实例的配置
* @return {@link SQLManager} 实例
* @throws Exception 若创建失败则抛出异常
*/
@NotNull SQLManager create(@Nullable String name,
@NotNull DBConfiguration configuration) throws Exception;
/**
* 创建并注册一个新的 SQLManager 实例
*
* @param name 实例名称
* @param properties SQLManager 实例的配置文件
* @return {@link SQLManager} 实例
* @throws Exception 若创建失败则抛出异常
*/
@NotNull SQLManager create(@Nullable String name,
@NotNull Properties properties) throws Exception;
/**
* 创建并注册一个新的 SQLManager 实例
*
* @param name 实例名称
* @param propertyFileName 配置文件的资源名称
* @return {@link SQLManager} 实例
* @throws Exception 若创建失败则抛出异常
*/
@NotNull SQLManager create(@Nullable String name,
@NotNull String propertyFileName) throws Exception;
/**
* 终止并关闭一个 SQLManager 实例。
*
* @param manager SQLManager实例
* @param activeQueries 终止前仍未被关闭的SQLQuery列表
*/
void shutdown(SQLManager manager, @Nullable Consumer<Map<UUID, SQLQuery>> activeQueries);
/**
* 终止并关闭一个 SQLManager 实例。
*
* @param manager SQLManager实例
* @param forceClose 是否强制关闭进行中的查询
*/
default void shutdown(SQLManager manager, boolean forceClose) {
shutdown(manager, (unclosedQueries) -> {
if (forceClose) unclosedQueries.values().forEach(SQLQuery::close);
});
}
/**
* 终止并关闭一个 SQLManager 实例。
* <br>若在终止时仍有活跃的查询,则将会强制关闭。
*
* @param manager SQLManager实例
*/
default void shutdown(SQLManager manager) {
shutdown(manager, true);
}
}
@@ -0,0 +1,65 @@
package cc.carm.plugin.easysql.api;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
public enum SQLDriverType {
MARIADB("org.mariadb.jdbc.Driver", "jdbc:mariadb://",
new String[]{"mariadb", "maria-db"}, new String[]{}
),
MYSQL("com.mysql.jdbc.Driver", "jdbc:mysql://",
new String[]{"mysql"}, new String[]{}
),
H2("org.h2.Driver", "jdbc:h2:",
new String[]{"h2", "h2-db", "h2-database"},
new String[]{"SET MODE=MySQL", "SET DB_CLOSE_DELAY=-1"}
);
private final @NotNull String driverClass;
private final @NotNull String urlPrefix;
private final @NotNull String[] databaseAlias;
private final @NotNull String[] initializeSQLs;
SQLDriverType(@NotNull String driverClass, @NotNull String urlPrefix,
@NotNull String[] databaseAlias,
@NotNull String[] initializeSQLs) {
this.driverClass = driverClass;
this.urlPrefix = urlPrefix;
this.databaseAlias = databaseAlias;
this.initializeSQLs = initializeSQLs;
}
public @NotNull String[] getDatabaseAlias() {
return databaseAlias;
}
public @NotNull String getDriverClass() {
return driverClass;
}
public @NotNull String getUrlPrefix() {
return urlPrefix;
}
public @NotNull String[] getInitializeSQLs() {
return initializeSQLs;
}
@Contract("null->null")
public static @Nullable SQLDriverType parse(@Nullable String driverString) {
if (driverString == null) return null;
return Arrays.stream(values())
.filter(value -> value.name().equalsIgnoreCase(driverString) || has(value.getDatabaseAlias(), driverString))
.findFirst().orElse(null);
}
private static boolean has(String[] array, String value) {
return Arrays.stream(array).anyMatch(s -> s.equalsIgnoreCase(value));
}
}