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(); }