1
mirror of https://github.com/CarmJos/EasySQL.git synced 2024-09-19 21:35:47 +00:00

[0.3.9] 版本更新

- `[R]` 修改项目结构,移除无用的 `easysql-tester` 模块, 整合相关测试到 `easysql-demo` 的`src/test` 下。
- `[U]` 移除`DefaultSQLExceptionHandler` 类,与 `SQLExceptionHandler` 接口下添加 `detailed()` 与 `silent()` 两种预设错误处理器,并支持通过 `SQLManager#setExceptionHandler()` 方法应用全局生效的默认错误处理器。
> 注意: 十分不建议使用 `silent()` 处理器为默认处理器!
This commit is contained in:
Carm Jos 2022-04-09 01:22:23 +08:00
parent f00e741035
commit 0a6c8ae1a9
25 changed files with 216 additions and 363 deletions

View File

@ -5,13 +5,13 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<version>0.3.8</version>
<version>0.3.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<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>

View File

@ -3,7 +3,6 @@ package cc.carm.lib.easysql.api;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.api.function.SQLFunction;
import cc.carm.lib.easysql.api.function.SQLHandler;
import cc.carm.lib.easysql.api.function.defaults.DefaultSQLExceptionHandler;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -189,13 +188,14 @@ public interface SQLAction<T> {
}
/**
* 默认的异常处理器
* 获取管理器提供的默认异常处理器
* 若未使用过 {@link #setExceptionHandler(SQLExceptionHandler)} 方法
* 则默认返回 {@link SQLExceptionHandler#detailed(Logger)}
*
* @return {@link DefaultSQLExceptionHandler#get(Logger)}
* @see DefaultSQLExceptionHandler
* @return {@link SQLExceptionHandler}
*/
default SQLExceptionHandler defaultExceptionHandler() {
return DefaultSQLExceptionHandler.get(getManager().getLogger());
return getManager().getExceptionHandler();
}
/**
@ -206,7 +206,7 @@ public interface SQLAction<T> {
* @param handler 异常处理器
*/
default void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
DefaultSQLExceptionHandler.setCustomHandler(handler);
getManager().setExceptionHandler(handler);
}
}

View File

@ -5,6 +5,7 @@ import cc.carm.lib.easysql.api.action.PreparedSQLUpdateBatchAction;
import cc.carm.lib.easysql.api.action.SQLUpdateAction;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import cc.carm.lib.easysql.api.builder.*;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -56,6 +57,24 @@ public interface SQLManager {
*/
@NotNull Map<UUID, SQLQuery> getActiveQuery();
/**
* 获取改管理器提供的默认异常处理器
* 若未使用过 {@link #setExceptionHandler(SQLExceptionHandler)} 方法
* 则默认返回 {@link SQLExceptionHandler#detailed(Logger)}
*
* @return {@link SQLExceptionHandler}
*/
@NotNull SQLExceptionHandler getExceptionHandler();
/**
* 设定通用的异常处理器
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时若传入的处理器为null则会采用此处理器
* <br> 若该方法传入参数为 null则会使用 {@link SQLExceptionHandler#detailed(Logger)}
*
* @param handler 异常处理器
*/
void setExceptionHandler(@Nullable SQLExceptionHandler handler);
/**
* 执行一条不需要返回结果的SQL语句(多用于UPDATEREPLACEDELETE方法)
* 该方法使用 Statement 实现请注意SQL注入风险

View File

@ -1,12 +1,51 @@
package cc.carm.lib.easysql.api.function;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import java.sql.SQLException;
import java.util.function.BiConsumer;
import java.util.logging.Logger;
/**
* 异常处理器
* <br> 在使用 {@link SQLAction#execute(SQLExceptionHandler)} 等相关方法时
* 如果发生异常则会调用错误处理器进行错误内容的输出提示
*/
@FunctionalInterface
public interface SQLExceptionHandler extends BiConsumer<SQLException, SQLAction<?>> {
/**
* 默认的异常处理器将详细的输出相关错误与错误来源
*
* @param logger 用于输出错误信息的Logger
* @return 输出详细信息的错误处理器
*/
static SQLExceptionHandler detailed(Logger logger) {
return (exception, sqlAction) -> {
if (sqlAction instanceof SQLUpdateBatchAction) {
logger.severe("Error when execute SQLs : ");
int i = 1;
for (String content : ((SQLUpdateBatchAction) sqlAction).getSQLContents()) {
logger.severe(String.format("#%d {%s}", i, content));
i++;
}
} else {
logger.severe("Error when execute { " + sqlAction.getSQLContent() + " }");
}
exception.printStackTrace();
};
}
/**
* 安静 的错误处理器发生错误什么都不做
* 强烈不建议把此处理器作为默认处理器使用
*
* @return 无输出的处理器
*/
static SQLExceptionHandler silent() {
return (exception, sqlAction) -> {
};
}
}

View File

@ -1,56 +0,0 @@
package cc.carm.lib.easysql.api.function.defaults;
import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.action.SQLUpdateBatchAction;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.sql.SQLException;
import java.util.logging.Logger;
public class DefaultSQLExceptionHandler implements SQLExceptionHandler {
private static @Nullable SQLExceptionHandler customDefaultHandler = null;
private final Logger logger;
public DefaultSQLExceptionHandler(Logger logger) {
this.logger = logger;
}
public static @Nullable SQLExceptionHandler getCustomHandler() {
return customDefaultHandler;
}
public static void setCustomHandler(@Nullable SQLExceptionHandler handler) {
DefaultSQLExceptionHandler.customDefaultHandler = handler;
}
public static @NotNull SQLExceptionHandler get(Logger logger) {
if (getCustomHandler() != null) return getCustomHandler();
else return new DefaultSQLExceptionHandler(logger);
}
protected Logger getLogger() {
return logger;
}
@Override
public void accept(SQLException exception, SQLAction<?> sqlAction) {
if (sqlAction instanceof SQLUpdateBatchAction) {
getLogger().severe("Error when execute SQLs : ");
int i = 1;
for (String content : ((SQLUpdateBatchAction) sqlAction).getSQLContents()) {
getLogger().severe(String.format("#%d {%s}", i, content));
i++;
}
} else {
getLogger().severe("Error when execute { " + sqlAction.getSQLContent() + " }");
}
exception.printStackTrace();
}
}

View File

@ -5,14 +5,14 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.8</version>
<version>0.3.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<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>
<maven.javadoc.skip>true</maven.javadoc.skip>
@ -64,6 +64,22 @@
<scope>compile</scope>
</dependency>
<dependency>
<!--项目地址 https://github.com/brettwooldridge/HikariCP/ -->
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.1.210</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,75 @@
package cc.carm.lib.easysql;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.lib.easysql.tests.*;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.LinkedHashSet;
import java.util.Set;
public class EasySQLTest {
@Test
public void onTest() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.h2.Driver");
config.setJdbcUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=MYSQL;");
SQLManager sqlManager = new SQLManagerImpl(new HikariDataSource(config), "test");
print("加载测试类...");
Set<TestHandler> tests = new LinkedHashSet<>();
tests.add(new TableCreateTest());
// tests.add(new TableAlterTest());
// tests.add(new TableRenameTest());
// tests.add(new QueryNotCloseTest());
tests.add(new QueryCloseTest());
tests.add(new SQLUpdateBatchTests());
tests.add(new SQLUpdateReturnKeysTest());
tests.add(new QueryFunctionTest());
tests.add(new DeleteTest());
print("准备进行测试...");
int index = 1;
int success = 0;
for (TestHandler currentTest : tests) {
print("-------------------------------------------------");
if (currentTest.executeTest(index, sqlManager)) {
success++;
}
index++;
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
print(" ");
print("全部测试执行完毕,成功 %s 个,失败 %s 个。",
success, (tests.size() - success)
);
if (sqlManager.getDataSource() instanceof HikariDataSource) {
//Close bee connection pool
((HikariDataSource) sqlManager.getDataSource()).close();
}
}
public static void print(@NotNull String format, Object... params) {
System.out.printf((format) + "%n", params);
}
}

View File

@ -1,4 +1,4 @@
package cc.carm.lib.easysql.tester;
package cc.carm.lib.easysql;
import cc.carm.lib.easysql.api.SQLManager;
import org.jetbrains.annotations.ApiStatus;
@ -6,10 +6,10 @@ import org.jetbrains.annotations.NotNull;
import java.sql.SQLException;
public abstract class EasySQLTest {
public abstract class TestHandler {
protected static void print(@NotNull String format, Object... params) {
Main.print(format, params);
EasySQLTest.print(format, params);
}
@ApiStatus.OverrideOnly

View File

@ -1,11 +1,11 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.SQLException;
public class DeleteTest extends EasySQLTest {
public class DeleteTest extends TestHandler {
@Override

View File

@ -1,13 +1,13 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.ResultSet;
import java.sql.SQLException;
public class QueryCloseTest extends EasySQLTest {
public class QueryCloseTest extends TestHandler {
@Override

View File

@ -1,11 +1,11 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.TestHandler;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.tester.EasySQLTest;
import java.sql.SQLException;
public class QueryFunctionTest extends EasySQLTest {
public class QueryFunctionTest extends TestHandler {
@Override

View File

@ -1,13 +1,13 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.ResultSet;
import java.sql.SQLException;
public class QueryNotCloseTest extends EasySQLTest {
public class QueryNotCloseTest extends TestHandler {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {

View File

@ -1,7 +1,7 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.SQLException;
import java.util.Arrays;
@ -10,7 +10,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class SQLUpdateBatchTests extends EasySQLTest {
public class SQLUpdateBatchTests extends TestHandler {
protected static List<Object[]> generateParams() {

View File

@ -1,4 +1,4 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;

View File

@ -1,12 +1,12 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.enums.NumberType;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.SQLException;
public class TableAlterTest extends EasySQLTest {
public class TableAlterTest extends TestHandler {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {

View File

@ -1,13 +1,13 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.api.enums.ForeignKeyRule;
import cc.carm.lib.easysql.api.enums.IndexType;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.SQLException;
public class TableCreateTest extends EasySQLTest {
public class TableCreateTest extends TestHandler {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
@ -30,7 +30,6 @@ public class TableCreateTest extends EasySQLTest {
"test_user_table", "id",
ForeignKeyRule.CASCADE, ForeignKeyRule.CASCADE
)
.setIndex(IndexType.FULLTEXT_INDEX, "sign", "info")
.build().execute();
}

View File

@ -1,11 +1,11 @@
package cc.carm.lib.easysql.tester.tests;
package cc.carm.lib.easysql.tests;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.tester.EasySQLTest;
import cc.carm.lib.easysql.TestHandler;
import java.sql.SQLException;
public class TableRenameTest extends EasySQLTest {
public class TableRenameTest extends TestHandler {
@Override
public void onTest(SQLManager sqlManager) throws SQLException {
print(" 重命名 test_user_table");

View File

@ -1,135 +0,0 @@
<?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-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.8</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<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>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<artifactId>easysql-tester</artifactId>
<name>EasySQL-Test</name>
<description>EasySQL的测试代码</description>
<url>https://github.com/CarmJos/EasySQL</url>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-beecp</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<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-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters>
<!-- when downloading via Maven we can pull depends individually -->
<shadedArtifactAttached>true</shadedArtifactAttached>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptRef>jar-with-dependencies</descriptRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>cc.carm.lib.easysql.tester.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,93 +0,0 @@
package cc.carm.lib.easysql.tester;
import cc.carm.lib.easysql.EasySQL;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.tester.tests.DeleteTest;
import cc.carm.lib.easysql.tester.tests.QueryCloseTest;
import cc.carm.lib.easysql.tester.tests.QueryFunctionTest;
import cc.carm.lib.easysql.tester.tests.TableCreateTest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;
@TestOnly
@SuppressWarnings("all")
public class Main {
public static void main(String[] args) {
if (args.length < 4) {
print("请提供以下参数:<数据库驱动> <数据库地址(JDBC)> <数据库用户> <数据库密码> [是否采用DEBUG(y/n)]");
return;
}
SQLManager sqlManager;
try {
print("初始化 SQLManager...");
print("数据库驱动 %s", args[0]);
print("数据库地址 %s", args[1]);
print("数据库用户 %s", args[2]);
print("数据库密码 %s", args[3]);
sqlManager = EasySQL.createManager(args[0], args[1], args[2], args[3]);
sqlManager.setDebugMode(args.length > 4);
print("SQLManager 初始化完成!");
} catch (Exception exception) {
print("SQLManager 初始化失败,请检查数据库配置。");
exception.printStackTrace();
return;
}
print("加载测试类...");
Set<EasySQLTest> tests = new LinkedHashSet<>();
tests.add(new TableCreateTest());
// tests.add(new TableAlterTest());
// tests.add(new TableRenameTest());
// tests.add(new QueryNotCloseTest());
tests.add(new QueryCloseTest());
// tests.add(new SQLUpdateBatchTests());
// tests.add(new SQLUpdateReturnKeysTest());
tests.add(new QueryFunctionTest());
tests.add(new DeleteTest());
print("准备进行测试...");
int index = 1;
int success = 0;
Iterator<EasySQLTest> testIterator = tests.iterator();
print("准备完成,请按回车键开始执行测试。");
while (testIterator.hasNext()) {
Scanner scanner = new Scanner(System.in);
if (scanner.nextLine() != null) {
EasySQLTest currentTest = testIterator.next();
if (currentTest.executeTest(index, sqlManager)) {
success++;
}
index++;
}
}
print(" ");
print("全部测试执行完毕,成功 %s 个,失败 %s 个。",
success, (tests.size() - success)
);
EasySQL.shutdownManager(sqlManager);
}
public static void print(@NotNull String format, Object... params) {
System.out.printf((format) + "%n", params);
}
}

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="cc.carm.lib.easysql">
<Appenders>
<console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
</console>
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="[%d{HH:mm:ss}] [%t/%level]: %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<root level="info">
<filters>
<MarkerFilter marker="NETWORK_PACKETS" onMatch="DENY" onMismatch="NEUTRAL"/>
</filters>
<!-- <AppenderRef ref="WINDOWS_COMPAT" level="info"/>-->
<AppenderRef ref="File"/>
<appender-ref ref="Console"/>
</root>
</Loggers>
</Configuration>

View File

@ -5,13 +5,13 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.8</version>
<version>0.3.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<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>

View File

@ -10,6 +10,7 @@ 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.builder.*;
import cc.carm.lib.easysql.api.function.SQLExceptionHandler;
import cc.carm.lib.easysql.builder.impl.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -32,6 +33,8 @@ public class SQLManagerImpl implements SQLManager {
protected ExecutorService executorPool;
@NotNull Supplier<Boolean> debugMode = () -> Boolean.FALSE;
@NotNull SQLExceptionHandler exceptionHandler;
public SQLManagerImpl(@NotNull DataSource dataSource) {
this(dataSource, null);
}
@ -45,6 +48,8 @@ public class SQLManagerImpl implements SQLManager {
thread.setDaemon(true);
return thread;
});
this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
}
@Override
@ -85,6 +90,17 @@ public class SQLManagerImpl implements SQLManager {
return this.activeQuery;
}
@Override
public @NotNull SQLExceptionHandler getExceptionHandler() {
return this.exceptionHandler;
}
@Override
public void setExceptionHandler(@Nullable SQLExceptionHandler handler) {
if (handler == null) this.exceptionHandler = SQLExceptionHandler.detailed(getLogger());
else this.exceptionHandler = handler;
}
@Override
public Integer executeSQL(String sql) {
return new SQLUpdateActionImpl(this, sql).execute(null);

View File

@ -17,7 +17,7 @@
<groupId>cc.carm.lib</groupId>
<artifactId>easysql-parent</artifactId>
<packaging>pom</packaging>
<version>0.3.8</version>
<version>0.3.9</version>
<modules>
<module>api</module>
@ -27,7 +27,6 @@
<module>with-pool/hikaricp</module>
<module>example/demo</module>
<module>example/tester</module>
</modules>
<name>EasySQL</name>

View File

@ -5,14 +5,14 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.8</version>
<version>0.3.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<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>

View File

@ -5,14 +5,14 @@
<parent>
<artifactId>easysql-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>0.3.8</version>
<version>0.3.9</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<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>