Skip to content

Commit fc9e7e5

Browse files
Nagarjuna BaligadugulaGitHub Enterprise
authored andcommitted
Merge pull request apache#1 from nbaligad/fix/code_quality
fix(refactor) : Improved code quality by refactoring as per sonar suggestions
2 parents e10e36c + 7943ce1 commit fc9e7e5

File tree

9 files changed

+22
-24
lines changed

9 files changed

+22
-24
lines changed

core/src/main/java/io/seata/core/store/db/AbstractDataSourceProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
/**
3939
* The abstract datasource provider
40-
*
40+
*
4141
* @author zhangsen
4242
* @author will
4343
*/
@@ -161,6 +161,7 @@ private static Map<String, ClassLoader> createMysqlDriverClassLoaders() {
161161
loaders.putIfAbsent(MYSQL_DRIVER_CLASS_NAME, loader);
162162
}
163163
} catch (MalformedURLException ignore) {
164+
LOGGER.error("MysqlDriverClassLoaders URL is not valid");
164165
}
165166
});
166167
return loaders;

discovery/seata-discovery-zk/src/main/java/io/seata/discovery/registry/zk/ZookeeperRegisterServiceImpl.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,10 @@ public void unsubscribe(String cluster, IZkChildListener listener) throws Except
157157
String path = ROOT_PATH + cluster;
158158
if (getClientInstance().exists(path)) {
159159
getClientInstance().unsubscribeChildChanges(path, listener);
160-
161-
List<IZkChildListener> subscribeList = LISTENER_SERVICE_MAP.get(cluster);
162-
if (subscribeList != null) {
163-
List<IZkChildListener> newSubscribeList = subscribeList.stream()
164-
.filter(eventListener -> !eventListener.equals(listener))
165-
.collect(Collectors.toList());
166-
LISTENER_SERVICE_MAP.put(cluster, newSubscribeList);
167-
}
160+
List<IZkChildListener> newSubscribeList = LISTENER_SERVICE_MAP.computeIfPresent(cluster,
161+
(key, subscribeList) -> subscribeList.stream()
162+
.filter(eventListener -> !eventListener.equals(listener)).collect(Collectors.toList()));
163+
LISTENER_SERVICE_MAP.put(cluster, newSubscribeList);
168164
}
169165

170166
}
@@ -196,7 +192,7 @@ List<InetSocketAddress> doLookup(String clusterName) throws Exception {
196192
if (!LISTENER_SERVICE_MAP.containsKey(clusterName)) {
197193
boolean exist = getClientInstance().exists(ROOT_PATH + clusterName);
198194
if (!exist) {
199-
return null;
195+
return new ArrayList<>();
200196
}
201197

202198
List<String> childClusterPath = getClientInstance().getChildren(ROOT_PATH + clusterName);
@@ -232,11 +228,12 @@ private ZkClient getClientInstance() {
232228
// visible for test.
233229
ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout,String... authInfo) {
234230
ZkClient zkClient = new ZkClient(address, sessionTimeout, connectTimeout);
235-
if (authInfo != null && authInfo.length == 2) {
236-
if (!StringUtils.isBlank(authInfo[0]) && !StringUtils.isBlank(authInfo[1])) {
237-
StringBuilder auth = new StringBuilder(authInfo[0]).append(":").append(authInfo[1]);
238-
zkClient.addAuthInfo("digest", auth.toString().getBytes());
239-
}
231+
if (authInfo != null && authInfo.length == 2 &&
232+
!StringUtils.isBlank(authInfo[0]) && !StringUtils.isBlank(authInfo[1])) {
233+
234+
StringBuilder auth = new StringBuilder(authInfo[0]).append(":").append(authInfo[1]);
235+
zkClient.addAuthInfo("digest", auth.toString().getBytes());
236+
240237
}
241238
if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) {
242239
zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true);

rm-datasource/src/main/java/io/seata/rm/datasource/AbstractConnectionProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public abstract class AbstractConnectionProxy implements Connection {
6464
* @param dataSourceProxy the data source proxy
6565
* @param targetConnection the target connection
6666
*/
67-
public AbstractConnectionProxy(DataSourceProxy dataSourceProxy, Connection targetConnection) {
67+
protected AbstractConnectionProxy(DataSourceProxy dataSourceProxy, Connection targetConnection) {
6868
this.dataSourceProxy = dataSourceProxy;
6969
this.targetConnection = targetConnection;
7070
}

rm-datasource/src/main/java/io/seata/rm/datasource/AbstractDataSourceCacheResourceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class AbstractDataSourceCacheResourceManager extends AbstractRes
3434
/**
3535
* Instantiates a new Data source manager.
3636
*/
37-
public AbstractDataSourceCacheResourceManager() {
37+
protected AbstractDataSourceCacheResourceManager() {
3838
}
3939

4040
@Override

rm-datasource/src/main/java/io/seata/rm/datasource/AbstractDataSourceProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ public abstract class AbstractDataSourceProxy implements SeataDataSourceProxy {
3636
/**
3737
* Instantiates a new Abstract data source proxy.
3838
*/
39-
public AbstractDataSourceProxy(){}
39+
protected AbstractDataSourceProxy(){}
4040

4141
/**
4242
* Instantiates a new Abstract data source proxy.
4343
*
4444
* @param targetDataSource the target data source
4545
*/
46-
public AbstractDataSourceProxy(DataSource targetDataSource) {
46+
protected AbstractDataSourceProxy(DataSource targetDataSource) {
4747
this.targetDataSource = targetDataSource;
4848
}
4949

rm-datasource/src/main/java/io/seata/rm/datasource/exec/AbstractDMLBaseExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract class AbstractDMLBaseExecutor<T, S extends Statement> extends Ba
5858
* @param statementCallback the statement callback
5959
* @param sqlRecognizer the sql recognizer
6060
*/
61-
public AbstractDMLBaseExecutor(StatementProxy<S> statementProxy, StatementCallback<T, S> statementCallback,
61+
protected AbstractDMLBaseExecutor(StatementProxy<S> statementProxy, StatementCallback<T, S> statementCallback,
6262
SQLRecognizer sqlRecognizer) {
6363
super(statementProxy, statementCallback, sqlRecognizer);
6464
}
@@ -70,7 +70,7 @@ public AbstractDMLBaseExecutor(StatementProxy<S> statementProxy, StatementCallba
7070
* @param statementCallback the statement callback
7171
* @param sqlRecognizers the multi sql recognizer
7272
*/
73-
public AbstractDMLBaseExecutor(StatementProxy<S> statementProxy, StatementCallback<T, S> statementCallback,
73+
protected AbstractDMLBaseExecutor(StatementProxy<S> statementProxy, StatementCallback<T, S> statementCallback,
7474
List<SQLRecognizer> sqlRecognizers) {
7575
super(statementProxy, statementCallback, sqlRecognizers);
7676
}

rm-datasource/src/main/java/io/seata/rm/datasource/xa/AbstractConnectionProxyXA.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract class AbstractConnectionProxyXA implements Connection {
5858

5959
protected String xid;
6060

61-
public AbstractConnectionProxyXA(Connection originalConnection, XAConnection xaConnection, BaseDataSourceResource resource, String xid) {
61+
protected AbstractConnectionProxyXA(Connection originalConnection, XAConnection xaConnection, BaseDataSourceResource resource, String xid) {
6262
this.originalConnection = originalConnection;
6363
this.xaConnection = xaConnection;
6464
this.resource = resource;

server/src/main/java/io/seata/server/coordinator/AbstractCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public abstract class AbstractCore implements Core {
6161

6262
protected RemotingServer remotingServer;
6363

64-
public AbstractCore(RemotingServer remotingServer) {
64+
protected AbstractCore(RemotingServer remotingServer) {
6565
if (remotingServer == null) {
6666
throw new IllegalArgumentException("remotingServer must be not null");
6767
}

tm/src/test/java/io/seata/tm/api/APITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void cleanRootContext() {
8686
public void testCurrent() throws Exception {
8787
RootContext.bind(DEFAULT_XID);
8888
GlobalTransaction tx = GlobalTransactionContext.getCurrentOrCreate();
89-
Assertions.assertEquals(tx.getXid(), DEFAULT_XID);
89+
Assertions.assertEquals(DEFAULT_XID,tx.getXid());
9090
Assertions.assertEquals(tx.getStatus(), GlobalStatus.Begin);
9191

9292
}

0 commit comments

Comments
 (0)