From 203b7dff12668f702351c5caa4a213ad60a2581e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E4=BD=B3=E5=BD=AC?= Date: Fri, 12 May 2023 11:29:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=8F=98=E5=B1=9E=E6=80=A7=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0final=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/audit/DefaultMessageFactory.java | 4 ++-- .../core/audit/ScheduledMessageCollector.java | 10 +++++----- .../core/audit/http/HttpMessageReporter.java | 6 +++--- .../mybatisflex/core/datasource/DataSourceBuilder.java | 10 +++------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/DefaultMessageFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/DefaultMessageFactory.java index 541a44e6..55d9b19a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/DefaultMessageFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/DefaultMessageFactory.java @@ -25,8 +25,8 @@ import java.util.Enumeration; */ public class DefaultMessageFactory implements MessageFactory { - private String platform = "mybatis-flex"; - private String hostIp = getHostIp(); + private final String platform = "mybatis-flex"; + private final String hostIp = getHostIp(); @Override diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java index 9e82ac62..b0860043 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/ScheduledMessageCollector.java @@ -28,12 +28,12 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; */ public class ScheduledMessageCollector implements MessageCollector, Runnable { - private long period; - private ScheduledExecutorService scheduler; - private MessageReporter messageSender; + private final long period; + private final ScheduledExecutorService scheduler; + private final MessageReporter messageSender; - private List messages = Collections.synchronizedList(new ArrayList<>()); - private ReentrantReadWriteLock rrwLock = new ReentrantReadWriteLock(); + private final List messages = Collections.synchronizedList(new ArrayList<>()); + private final ReentrantReadWriteLock rrwLock = new ReentrantReadWriteLock(); public ScheduledMessageCollector() { this(10, new ConsoleMessageReporter()); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java index ace10e3d..c2bb87bc 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/audit/http/HttpMessageReporter.java @@ -22,9 +22,9 @@ import java.util.List; public class HttpMessageReporter implements MessageReporter { - private String endpoint; - private String secretKey; - private JSONFormatter jsonFormatter; + private final String endpoint; + private final String secretKey; + private final JSONFormatter jsonFormatter; public HttpMessageReporter(String endpoint, String secretKey, JSONFormatter jsonFormatter) { this.endpoint = endpoint; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java index 3734b619..5e718d70 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceBuilder.java @@ -27,7 +27,7 @@ import java.util.Map; public class DataSourceBuilder { - private static Map dataSourceAlias = new HashMap<>(); + private static final Map dataSourceAlias = new HashMap<>(); static { dataSourceAlias.put("druid", "com.alibaba.druid.pool.DruidDataSource"); @@ -39,7 +39,7 @@ public class DataSourceBuilder { dataSourceAlias.put("dbcp2", "org.apache.commons.dbcp2.BasicDataSource"); } - private Map dataSourceProperties; + private final Map dataSourceProperties; public DataSourceBuilder(Map dataSourceProperties) { this.dataSourceProperties = dataSourceProperties; @@ -49,11 +49,7 @@ public class DataSourceBuilder { String dataSourceClassName = null; String type = dataSourceProperties.get("type"); if (StringUtil.isNotBlank(type)) { - if (dataSourceAlias.containsKey(type)) { - dataSourceClassName = dataSourceAlias.get(type); - } else { - dataSourceClassName = type; - } + dataSourceClassName = dataSourceAlias.getOrDefault(type, type); } else { dataSourceClassName = detectDataSourceClass(); }