You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2023/05/13 12:17:20 UTC

[shardingsphere] branch master updated: Fix sonar issue of CalculationContext (#25642)

This is an automated email from the ASF dual-hosted git repository.

zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d8275fe3884 Fix sonar issue of CalculationContext (#25642)
d8275fe3884 is described below

commit d8275fe3884e99a983e02a7fff896c5840668d1d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat May 13 20:17:11 2023 +0800

    Fix sonar issue of CalculationContext (#25642)
---
 ...DataMatchDataConsistencyCalculateAlgorithm.java | 41 +++++++++++++++++-----
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java
index e720a9a3fd9..c6ea5031b44 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.data.pipeline.core.check.consistency.algorithm
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
-import lombok.Setter;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.builder.EqualsBuilder;
@@ -55,6 +54,7 @@ import java.util.LinkedList;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 /**
@@ -191,21 +191,46 @@ public final class DataMatchDataConsistencyCalculateAlgorithm extends AbstractSt
     }
     
     @RequiredArgsConstructor
-    @Getter
     private static final class CalculationContext implements AutoCloseable {
         
+        @Getter
         private final Connection connection;
         
-        @Setter
-        private volatile PreparedStatement preparedStatement;
+        private final AtomicReference<PreparedStatement> preparedStatement = new AtomicReference<>();
+        
+        private final AtomicReference<ResultSet> resultSet = new AtomicReference<>();
+        
+        /**
+         * Get result set.
+         *
+         * @return result set
+         */
+        public ResultSet getResultSet() {
+            return resultSet.get();
+        }
         
-        @Setter
-        private volatile ResultSet resultSet;
+        /**
+         * Set prepared statement.
+         * 
+         * @param preparedStatement prepared statement
+         */
+        public void setPreparedStatement(final PreparedStatement preparedStatement) {
+            this.preparedStatement.set(preparedStatement);
+        }
+        
+        /**
+         * Set result set.
+         * 
+         * @param resultSet result set
+         */
+        public void setResultSet(final ResultSet resultSet) {
+            this.resultSet.set(resultSet);
+        }
         
         @Override
         public void close() {
-            CloseUtils.closeQuietly(resultSet);
-            CloseUtils.closeQuietly(preparedStatement);
+            CloseUtils.closeQuietly(resultSet.get());
+            CloseUtils.closeQuietly(preparedStatement.get());
             CloseUtils.closeQuietly(connection);
         }
     }