mirror of
https://github.com/CarmJos/EasySQL.git
synced 2026-06-05 09:01:26 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50b36d8430 | |||
| cd60bf256e | |||
| ebe68befee | |||
| 594413e13b | |||
| df94272c73 | |||
| ab986e9526 | |||
| 3f3b7bf4a5 | |||
| c69695c16d | |||
| 02aad28715 | |||
| b423000fe5 | |||
| cf356f2492 |
@@ -0,0 +1,36 @@
|
||||
name: Build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
- name: Cache SonarCloud packages
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.sonar/cache
|
||||
key: ${{ runner.os }}-sonar
|
||||
restore-keys: ${{ runner.os }}-sonar
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-m2
|
||||
- name: Build and analyze
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=CarmJos_EasySQL
|
||||
@@ -26,10 +26,6 @@
|
||||
- 基于JDBC开发,可自选连接池、JDBC驱动。
|
||||
- 简单便捷的增删改查接口,无需手写SQL语句。
|
||||
- 额外提供部分常用情况的SQL操作
|
||||
- 存在则更新,不存在则插入
|
||||
- 创建表
|
||||
- 修改表
|
||||
- ...
|
||||
- 自动关闭数据流
|
||||
- 支持同步操作与异步操作
|
||||
|
||||
@@ -41,18 +37,43 @@
|
||||
|
||||
您可以 [点击这里](easysql-demo/src/main/java/EasySQLDemo.java) 查看部分代码演示,更多演示详见 [开发介绍](.documentation/README.md) 。
|
||||
|
||||
### 依赖方式 (Maven)
|
||||
### 依赖方式
|
||||
|
||||
#### Maven 依赖
|
||||
|
||||
<details>
|
||||
<summary>远程库配置</summary>
|
||||
|
||||
```xml
|
||||
|
||||
<project>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<!--采用github依赖库,安全稳定,但需要配置 (推荐)-->
|
||||
<id>EasySQL</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/EasySQL</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!--采用我的私人依赖库,简单方便,但可能因为变故而无法使用-->
|
||||
<id>carm-repo</id>
|
||||
<name>Carm's Repo</name>
|
||||
<url>https://repo.carm.cc/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
</project>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>原生依赖</summary>
|
||||
|
||||
```xml
|
||||
|
||||
<project>
|
||||
<dependencies>
|
||||
<!--对于需要提供公共接口的项目,可以仅打包API部分,方便他人调用-->
|
||||
<dependency>
|
||||
@@ -70,14 +91,19 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--如需自定义连接池,则可以仅打包实现部分,自行创建SQLManager-->
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-beecp</artifactId>
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>含连接池版本</summary>
|
||||
|
||||
```xml
|
||||
|
||||
<project>
|
||||
<dependencies>
|
||||
<!--也可直接选择打包了连接池的版本-->
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
@@ -91,12 +117,64 @@
|
||||
<version>[LATEST VERSION]</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### Gradle 依赖
|
||||
|
||||
<details>
|
||||
<summary>远程库配置</summary>
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
// 采用github依赖库,安全稳定,但需要配置 (推荐)
|
||||
maven { url 'https://maven.pkg.github.com/CarmJos/EasySQL' }
|
||||
|
||||
// 采用我的私人依赖库,简单方便,但可能因为变故而无法使用
|
||||
maven { url 'https://repo.carm.cc/repository/maven-public/' }
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>原生依赖</summary>
|
||||
|
||||
```groovy
|
||||
|
||||
dependencies {
|
||||
|
||||
//对于需要提供公共接口的项目,可以仅打包API部分,方便他人调用
|
||||
api "cc.carm.lib:easysql-api:[LATEST RELEASE]"
|
||||
|
||||
//如需自定义连接池,则可以仅打包实现部分,自行创建SQLManager
|
||||
api "cc.carm.lib:easysql-impl:[LATEST RELEASE]"
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>含连接池版本</summary>
|
||||
|
||||
```groovy
|
||||
|
||||
dependencies {
|
||||
|
||||
//也可直接选择打包了连接池的版本
|
||||
|
||||
api "cc.carm.lib:easysql-beecp:[LATEST RELEASE]"
|
||||
|
||||
api "cc.carm.lib:easysql-hikaricp:[LATEST RELEASE]"
|
||||
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
## 支持与捐赠
|
||||
|
||||
若您觉得本插件做的不错,您可以通过捐赠支持我!
|
||||
@@ -108,7 +186,9 @@
|
||||
## 开源协议
|
||||
|
||||
本项目源码采用 [GNU General Public License v3.0](https://opensource.org/licenses/GPL-3.0) 开源协议。
|
||||
> ### 关于 GPL 协议
|
||||
<details>
|
||||
<summary>关于 GPL 协议</summary>
|
||||
|
||||
> GNU General Public Licence (GPL) 有可能是开源界最常用的许可模式。GPL 保证了所有开发者的权利,同时为使用者提供了足够的复制,分发,修改的权利:
|
||||
>
|
||||
> #### 可自由复制
|
||||
@@ -123,3 +203,4 @@
|
||||
> 需要注意的是,分发的时候,需要明确提供源代码和二进制文件,另外,用于某些程序的某些协议有一些问题和限制,你可以看一下 @PierreJoye 写的 Practical Guide to GPL Compliance 一文。使用 GPL 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
||||
>
|
||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||
</details>
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<version>0.2.2</version>
|
||||
<version>0.2.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
+28
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.2.2</version>
|
||||
<version>0.2.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
<groupId>com.github.chris2018998</groupId>
|
||||
<artifactId>beecp</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -89,6 +90,32 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>cn.beecp</pattern>
|
||||
<shadedPattern>cc.carm.lib.easysql.beecp</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package cc.carm.lib.easysql;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.util.TimeDateUtils;
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import cn.beecp.BeeDataSource;
|
||||
import cn.beecp.BeeDataSourceConfig;
|
||||
@@ -18,4 +21,26 @@ public class EasySQL {
|
||||
return new SQLManagerImpl(new BeeDataSource(config));
|
||||
}
|
||||
|
||||
|
||||
public static void shutdownManager(SQLManager manager, boolean forceClose, boolean outputActiveQuery) {
|
||||
if (!manager.getActiveQuery().isEmpty()) {
|
||||
manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running");
|
||||
for (SQLQuery value : manager.getActiveQuery().values()) {
|
||||
if (outputActiveQuery) {
|
||||
manager.getLogger().severe("#" + value.getAction().getShortID() + " -> " + value.getSQLContent());
|
||||
manager.getLogger().severe("- execute at " + TimeDateUtils.getTimeString(value.getExecuteTime()));
|
||||
}
|
||||
if (forceClose) value.close();
|
||||
}
|
||||
}
|
||||
if (manager.getDataSource() instanceof BeeDataSource) {
|
||||
//Close bee connection pool
|
||||
((BeeDataSource) manager.getDataSource()).close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdownManager(SQLManager manager) {
|
||||
shutdownManager(manager, true, manager.isDebugMode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.2.2</version>
|
||||
<version>0.2.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.2.2</version>
|
||||
<version>0.2.5</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>4.0.3</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -88,6 +89,32 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>cc.carm.lib.easysql.hikari</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package cc.carm.lib.easysql;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.util.TimeDateUtils;
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class EasySQL {
|
||||
|
||||
public static SQLManagerImpl createManager(
|
||||
@NotNull String driver, @NotNull String url,
|
||||
@NotNull String username, @Nullable String password) {
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setDriverClassName(driver);
|
||||
config.setJdbcUrl(url);
|
||||
config.setUsername(username);
|
||||
config.setPassword(password);
|
||||
return createManager(config);
|
||||
}
|
||||
|
||||
public static SQLManagerImpl createManager(@NotNull Properties properties) {
|
||||
return createManager(new HikariConfig(properties));
|
||||
}
|
||||
|
||||
public static SQLManagerImpl createManager(@NotNull HikariConfig config) {
|
||||
return new SQLManagerImpl(new HikariDataSource(config));
|
||||
}
|
||||
|
||||
public static void shutdownManager(SQLManager manager, boolean forceClose, boolean outputActiveQuery) {
|
||||
if (!manager.getActiveQuery().isEmpty()) {
|
||||
manager.getLogger().severe("There are " + manager.getActiveQuery().size() + " connections still running");
|
||||
for (SQLQuery value : manager.getActiveQuery().values()) {
|
||||
if (outputActiveQuery) {
|
||||
manager.getLogger().severe("#" + value.getAction().getShortID() + " -> " + value.getSQLContent());
|
||||
manager.getLogger().severe("- execute at " + TimeDateUtils.getTimeString(value.getExecuteTime()));
|
||||
}
|
||||
if (forceClose) value.close();
|
||||
}
|
||||
}
|
||||
if (manager.getDataSource() instanceof HikariDataSource) {
|
||||
//Close hikari pool
|
||||
((HikariDataSource) manager.getDataSource()).close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdownManager(SQLManager manager) {
|
||||
shutdownManager(manager, true, manager.isDebugMode());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package easysql;
|
||||
|
||||
import cc.carm.lib.easysql.manager.SQLManagerImpl;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class EasySQL {
|
||||
|
||||
public static SQLManagerImpl createManager(
|
||||
@NotNull String driver, @NotNull String url,
|
||||
@NotNull String username, @Nullable String password) {
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setDriverClassName(driver);
|
||||
config.setJdbcUrl(url);
|
||||
config.setUsername(username);
|
||||
config.setPassword(password);
|
||||
return createManager(config);
|
||||
}
|
||||
|
||||
public static SQLManagerImpl createManager(@NotNull Properties properties) {
|
||||
return createManager(new HikariConfig(properties));
|
||||
}
|
||||
|
||||
public static SQLManagerImpl createManager(@NotNull HikariConfig config) {
|
||||
return new SQLManagerImpl(new HikariDataSource(config));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>0.2.2</version>
|
||||
<version>0.2.5</version>
|
||||
</parent>
|
||||
<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.SQLUpdateBatchActionImpl;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateAction;
|
||||
import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
|
||||
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
|
||||
import cc.carm.lib.easysql.api.action.query.SQLQuery;
|
||||
import cc.carm.lib.easysql.api.builder.*;
|
||||
import cc.carm.lib.easysql.builder.impl.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -4,10 +4,19 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<sonar.organization>carmjos</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easysql-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>0.2.2</version>
|
||||
<version>0.2.5</version>
|
||||
|
||||
<modules>
|
||||
<module>easysql-api</module>
|
||||
@@ -55,13 +64,6 @@
|
||||
<url>${project.url}/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
@@ -252,4 +254,4 @@
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user