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

tuichenchuxin 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 1bb3c99bfb2 Unify ReflectiveUtil in ShardingSphere (#21744)
1bb3c99bfb2 is described below

commit 1bb3c99bfb220d66ba2b10990ed280a7c49f6193
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Tue Oct 25 18:33:05 2022 +0800

    Unify ReflectiveUtil in ShardingSphere (#21744)
    
    * Unify ReflectiveUtil in ShardingSphere
    
    * optimize code style
---
 agent/core/pom.xml                                 |  6 ++
 .../loader/AgentConfigurationLoaderTest.java       |  2 +-
 .../agent/core/util/ReflectiveUtil.java            | 50 -----------------
 .../shardingsphere/agent/metrics/api/BaseTest.java |  2 +-
 .../agent/metrics/api/util/ReflectiveUtil.java     | 50 -----------------
 .../metrics/prometheus/util/ReflectiveUtil.java    | 60 --------------------
 .../prometheus/wrapper/CounterWrapperTest.java     |  2 +-
 .../prometheus/wrapper/GaugeWrapperTest.java       |  2 +-
 .../prometheus/wrapper/HistogramWrapperTest.java   |  2 +-
 .../prometheus/wrapper/SummaryWrapperTest.java     |  2 +-
 .../AbstractJDBCExecutorCallbackAdviceTest.java    |  2 +-
 .../infra/util/reflect/ReflectiveUtil.java         | 56 ++++++++++---------
 .../AtomikosTransactionManagerProviderTest.java    |  6 +-
 .../atomikos/manager/fixture/ReflectiveUtil.java   | 65 ----------------------
 .../BitronixXATransactionManagerProviderTest.java  |  6 +-
 .../bitronix/manager/fixture/ReflectiveUtil.java   | 65 ----------------------
 .../DataSourceXAResourceRecoveryHelperTest.java    |  4 +-
 .../NarayanaXATransactionManagerProviderTest.java  |  8 +--
 .../narayana/manager/fixture/ReflectiveUtil.java   | 65 ----------------------
 .../general/PostgreSQLMigrationGeneralIT.java      |  2 +-
 20 files changed, 57 insertions(+), 400 deletions(-)

diff --git a/agent/core/pom.xml b/agent/core/pom.xml
index 27b53ab4b6e..20f533c2fd2 100644
--- a/agent/core/pom.xml
+++ b/agent/core/pom.xml
@@ -39,6 +39,12 @@
             <groupId>org.yaml</groupId>
             <artifactId>snakeyaml</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-infra-util</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     
     <build>
diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoaderTest.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoaderTest.java
index 458cc7ea946..a3956c2a70c 100644
--- 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoaderTest.java
+++ 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoaderTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.core.config.loader;
 
 import org.apache.shardingsphere.agent.core.config.path.AgentPathBuilder;
-import org.apache.shardingsphere.agent.core.util.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Test;
 
 import java.io.File;
diff --git 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/util/ReflectiveUtil.java
 
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/util/ReflectiveUtil.java
deleted file mode 100644
index bd0ad4883e3..00000000000
--- 
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/util/ReflectiveUtil.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.util;
-
-import java.lang.reflect.Modifier;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.lang.reflect.Field;
-
-/**
- * Reflective utility.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReflectiveUtil {
-    
-    /**
-     * Set value to static field.
-     *
-     * @param target target
-     * @param fieldName field name
-     * @param value value
-     */
-    @SneakyThrows(ReflectiveOperationException.class)
-    public static void setStaticField(final Class<?> target, final String 
fieldName, final Object value) {
-        Field[] fields = target.getDeclaredFields();
-        for (Field each : fields) {
-            if (Modifier.isStatic(each.getModifiers()) && 
each.getName().equalsIgnoreCase(fieldName)) {
-                each.setAccessible(true);
-                each.set(null, value);
-            }
-        }
-    }
-}
diff --git 
a/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
 
b/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
index 226b3965ae2..23735bac3e5 100644
--- 
a/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
+++ 
b/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/BaseTest.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.agent.metrics.api;
 import 
org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
 import org.apache.shardingsphere.agent.core.config.path.AgentPathBuilder;
 import 
org.apache.shardingsphere.agent.core.config.registry.AgentConfigurationRegistry;
-import org.apache.shardingsphere.agent.metrics.api.util.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Before;
 
 import java.io.File;
diff --git 
a/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/util/ReflectiveUtil.java
 
b/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/util/ReflectiveUtil.java
deleted file mode 100644
index ab9f553b100..00000000000
--- 
a/agent/plugins/metrics/api/src/test/java/org/apache/shardingsphere/agent/metrics/api/util/ReflectiveUtil.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.metrics.api.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-
-/**
- * Reflective utility.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReflectiveUtil {
-    
-    /**
-     * Set value to static field.
-     *
-     * @param target target
-     * @param fieldName field name
-     * @param value value
-     */
-    @SneakyThrows(ReflectiveOperationException.class)
-    public static void setStaticField(final Class<?> target, final String 
fieldName, final Object value) {
-        Field[] fields = target.getDeclaredFields();
-        for (Field each : fields) {
-            if (Modifier.isStatic(each.getModifiers()) && 
each.getName().equalsIgnoreCase(fieldName)) {
-                each.setAccessible(true);
-                each.set(null, value);
-            }
-        }
-    }
-}
diff --git 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/util/ReflectiveUtil.java
 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/util/ReflectiveUtil.java
deleted file mode 100644
index 9166528c505..00000000000
--- 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/util/ReflectiveUtil.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.metrics.prometheus.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.lang.reflect.Field;
-import java.util.Arrays;
-
-/**
- * Reflective utility.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReflectiveUtil {
-    
-    /**
-     * Get field value object.
-     *
-     * @param object object
-     * @param fieldName field name
-     * @return object
-     */
-    public static Object getFieldValue(final Object object, final String 
fieldName) {
-        return getFieldValue(object, getField(object.getClass(), fieldName));
-    }
-    
-    private static Object getFieldValue(final Object object, final Field 
field) {
-        if (null == object || null == field) {
-            return null;
-        }
-        field.setAccessible(true);
-        Object result = null;
-        try {
-            result = field.get(object);
-        } catch (IllegalAccessException ignored) {
-        }
-        return result;
-    }
-    
-    private static Field getField(final Class<?> clazz, final String 
fieldName) {
-        Field[] fields = clazz.getDeclaredFields();
-        return 0 == fields.length ? null : Arrays.stream(fields).filter(each 
-> fieldName.equals(each.getName())).findFirst().orElse(null);
-    }
-}
diff --git 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/CounterWrapperTest.java
 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/CounterWrapperTest.java
index 4f2c5eb5b63..0d851d2f733 100644
--- 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/CounterWrapperTest.java
+++ 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/CounterWrapperTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.metrics.prometheus.wrapper;
 
 import io.prometheus.client.Counter;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
diff --git 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/GaugeWrapperTest.java
 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/GaugeWrapperTest.java
index 639c6f7ac09..54d3a45c0d8 100644
--- 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/GaugeWrapperTest.java
+++ 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/GaugeWrapperTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.metrics.prometheus.wrapper;
 
 import io.prometheus.client.Gauge;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
diff --git 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/HistogramWrapperTest.java
 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/HistogramWrapperTest.java
index c5ce89aa106..e7f3e0e5af5 100644
--- 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/HistogramWrapperTest.java
+++ 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/HistogramWrapperTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.metrics.prometheus.wrapper;
 
 import io.prometheus.client.Histogram;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
diff --git 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/SummaryWrapperTest.java
 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/SummaryWrapperTest.java
index 6d5d12374df..97d7c779705 100644
--- 
a/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/SummaryWrapperTest.java
+++ 
b/agent/plugins/metrics/prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/wrapper/SummaryWrapperTest.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.agent.metrics.prometheus.wrapper;
 
 import io.prometheus.client.Summary;
-import org.apache.shardingsphere.agent.metrics.prometheus.util.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Test;
 
 import static org.hamcrest.CoreMatchers.is;
diff --git 
a/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
 
b/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
index a6f0aac1734..e65095e8dcb 100644
--- 
a/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
+++ 
b/agent/plugins/tracing/test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
@@ -87,7 +87,7 @@ public abstract class AbstractJDBCExecutorCallbackAdviceTest 
implements AdviceTe
         cachedDatasourceMetadata.put("mock_url", new MockDataSourceMetaData());
         Map<String, DatabaseType> storageTypes = new LinkedHashMap<>(1, 1);
         storageTypes.put("mock.db", new MySQLDatabaseType());
-        ReflectiveUtil.setProperty(mock, "storageTypes", storageTypes);
+        ReflectiveUtil.setField(mock, "storageTypes", storageTypes);
         targetObject = (AdviceTargetObject) mock;
     }
 }
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtil.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtil.java
index 5c80aa6a46a..1a6d86c2a1b 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtil.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/reflect/ReflectiveUtil.java
@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
 import lombok.SneakyThrows;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
 import java.util.Objects;
 
 /**
@@ -31,31 +32,21 @@ import java.util.Objects;
 public final class ReflectiveUtil {
     
     /**
-     * Get field value object.
+     * Get field value.
      *
-     * @param object object
+     * @param target target
      * @param fieldName field name
-     * @return object
+     * @return field value
      */
-    public static Object getFieldValue(final Object object, final String 
fieldName) {
-        return getFieldValue(object, getField(object, fieldName));
-    }
-    
-    private static Object getFieldValue(final Object object, final Field 
field) {
-        if (null == object || null == field) {
-            return null;
-        }
-        field.setAccessible(true);
-        Object result = null;
-        try {
-            result = field.get(object);
-        } catch (IllegalAccessException ignored) {
-        }
-        return result;
+    @SneakyThrows(IllegalAccessException.class)
+    public static Object getFieldValue(final Object target, final String 
fieldName) {
+        Field field = getField(target.getClass(), fieldName);
+        Objects.requireNonNull(field).setAccessible(true);
+        return field.get(target);
     }
     
-    private static Field getField(final Object target, final String fieldName) 
{
-        Class<?> clazz = target.getClass();
+    private static Field getField(final Class<?> target, final String 
fieldName) {
+        Class<?> clazz = target;
         while (null != clazz) {
             try {
                 return clazz.getDeclaredField(fieldName);
@@ -73,11 +64,26 @@ public final class ReflectiveUtil {
      * @param fieldName field name
      * @param value value
      */
-    @SneakyThrows(ReflectiveOperationException.class)
-    public static void setProperty(final Object target, final String 
fieldName, final Object value) {
-        Field field = getField(target, fieldName);
-        Objects.requireNonNull(field);
-        field.setAccessible(true);
+    @SneakyThrows(IllegalAccessException.class)
+    public static void setField(final Object target, final String fieldName, 
final Object value) {
+        Field field = getField(target.getClass(), fieldName);
+        Objects.requireNonNull(field).setAccessible(true);
         field.set(target, value);
     }
+    
+    /**
+     * Set value to specified static field.
+     *
+     * @param target target
+     * @param fieldName field name
+     * @param value value
+     */
+    @SneakyThrows(IllegalAccessException.class)
+    public static void setStaticField(final Class<?> target, final String 
fieldName, final Object value) {
+        Field field = getField(target, fieldName);
+        if (Modifier.isStatic(Objects.requireNonNull(field).getModifiers())) {
+            field.setAccessible(true);
+            field.set(null, value);
+        }
+    }
 }
diff --git 
a/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/AtomikosTransactionManagerProviderTest.java
 
b/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/AtomikosTransactionManagerProviderTest.java
index 0a8bbe55ce0..c79a4aa4c3d 100644
--- 
a/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/AtomikosTransactionManagerProviderTest.java
+++ 
b/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/AtomikosTransactionManagerProviderTest.java
@@ -19,7 +19,7 @@ package 
org.apache.shardingsphere.transaction.xa.atomikos.manager;
 
 import com.atomikos.icatch.config.UserTransactionService;
 import com.atomikos.icatch.jta.UserTransactionManager;
-import 
org.apache.shardingsphere.transaction.xa.atomikos.manager.fixture.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.apache.shardingsphere.transaction.xa.spi.SingleXAResource;
 import org.junit.Before;
 import org.junit.Test;
@@ -55,8 +55,8 @@ public final class AtomikosTransactionManagerProviderTest {
     
     @Before
     public void setUp() {
-        ReflectiveUtil.setProperty(transactionManagerProvider, 
"transactionManager", userTransactionManager);
-        ReflectiveUtil.setProperty(transactionManagerProvider, 
"userTransactionService", userTransactionService);
+        ReflectiveUtil.setField(transactionManagerProvider, 
"transactionManager", userTransactionManager);
+        ReflectiveUtil.setField(transactionManagerProvider, 
"userTransactionService", userTransactionService);
     }
     
     @Test
diff --git 
a/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/fixture/ReflectiveUtil.java
 
b/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/fixture/ReflectiveUtil.java
deleted file mode 100644
index 2d35858161b..00000000000
--- 
a/kernel/transaction/type/xa/provider/atomikos/src/test/java/org/apache/shardingsphere/transaction/xa/atomikos/manager/fixture/ReflectiveUtil.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.transaction.xa.atomikos.manager.fixture;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.lang.reflect.Field;
-
-/**
- * Reflective utility.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReflectiveUtil {
-    
-    /**
-     * Get field.
-     * 
-     * @param target target
-     * @param fieldName field name
-     * @return field
-     */
-    private static Field getField(final Object target, final String fieldName) 
{
-        Class<?> clazz = target.getClass();
-        while (null != clazz) {
-            try {
-                return clazz.getDeclaredField(fieldName);
-            } catch (final NoSuchFieldException ignored) {
-            }
-            clazz = clazz.getSuperclass();
-        }
-        return null;
-    }
-    
-    /**
-     * Set value to specified field.
-     * @param target target
-     * @param fieldName field name
-     * @param value value
-     */
-    @SneakyThrows(ReflectiveOperationException.class)
-    public static void setProperty(final Object target, final String 
fieldName, final Object value) {
-        Field field = getField(target, fieldName);
-        Preconditions.checkNotNull(field);
-        field.setAccessible(true);
-        field.set(target, value);
-    }
-}
diff --git 
a/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixXATransactionManagerProviderTest.java
 
b/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixXATransactionManagerProviderTest.java
index 57080050cfb..6888356a791 100644
--- 
a/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixXATransactionManagerProviderTest.java
+++ 
b/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/BitronixXATransactionManagerProviderTest.java
@@ -19,7 +19,7 @@ package 
org.apache.shardingsphere.transaction.xa.bitronix.manager;
 
 import bitronix.tm.BitronixTransactionManager;
 import bitronix.tm.resource.ResourceRegistrar;
-import 
org.apache.shardingsphere.transaction.xa.bitronix.manager.fixture.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.apache.shardingsphere.transaction.xa.spi.SingleXAResource;
 import org.junit.Before;
 import org.junit.Test;
@@ -33,9 +33,9 @@ import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -53,7 +53,7 @@ public final class BitronixXATransactionManagerProviderTest {
     
     @Before
     public void setUp() {
-        ReflectiveUtil.setProperty(transactionManagerProvider, 
"transactionManager", transactionManager);
+        ReflectiveUtil.setField(transactionManagerProvider, 
"transactionManager", transactionManager);
     }
     
     @Test
diff --git 
a/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/fixture/ReflectiveUtil.java
 
b/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/fixture/ReflectiveUtil.java
deleted file mode 100644
index 83870342585..00000000000
--- 
a/kernel/transaction/type/xa/provider/bitronix/src/test/java/org/apache/shardingsphere/transaction/xa/bitronix/manager/fixture/ReflectiveUtil.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.transaction.xa.bitronix.manager.fixture;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.lang.reflect.Field;
-
-/**
- * Reflective utility.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReflectiveUtil {
-    
-    /**
-     * Get field.
-     * 
-     * @param target target
-     * @param fieldName field name
-     * @return field
-     */
-    private static Field getField(final Object target, final String fieldName) 
{
-        Class<?> clazz = target.getClass();
-        while (null != clazz) {
-            try {
-                return clazz.getDeclaredField(fieldName);
-            } catch (final NoSuchFieldException ignored) {
-            }
-            clazz = clazz.getSuperclass();
-        }
-        return null;
-    }
-    
-    /**
-     * Set value to specified field.
-     * @param target target
-     * @param fieldName field name
-     * @param value value
-     */
-    @SneakyThrows(ReflectiveOperationException.class)
-    public static void setProperty(final Object target, final String 
fieldName, final Object value) {
-        Field field = getField(target, fieldName);
-        Preconditions.checkNotNull(field);
-        field.setAccessible(true);
-        field.set(target, value);
-    }
-}
diff --git 
a/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/DataSourceXAResourceRecoveryHelperTest.java
 
b/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/DataSourceXAResourceRecoveryHelperTest.java
index 236a646ae1e..5e253cffc69 100644
--- 
a/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/DataSourceXAResourceRecoveryHelperTest.java
+++ 
b/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/DataSourceXAResourceRecoveryHelperTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.transaction.xa.narayana.manager;
 
-import 
org.apache.shardingsphere.transaction.xa.narayana.manager.fixture.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -70,7 +70,7 @@ public final class DataSourceXAResourceRecoveryHelperTest {
     
     @Test
     public void assertGetXAResourcesWithoutConnecting() throws SQLException {
-        ReflectiveUtil.setProperty(recoveryHelper, "delegate", xaResource);
+        ReflectiveUtil.setField(recoveryHelper, "delegate", xaResource);
         recoveryHelper.getXAResources();
         XAResource[] xaResources = recoveryHelper.getXAResources();
         assertThat(xaResources.length, is(1));
diff --git 
a/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/NarayanaXATransactionManagerProviderTest.java
 
b/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/NarayanaXATransactionManagerProviderTest.java
index 140531f45d9..5f488f510e1 100644
--- 
a/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/NarayanaXATransactionManagerProviderTest.java
+++ 
b/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/NarayanaXATransactionManagerProviderTest.java
@@ -19,7 +19,7 @@ package 
org.apache.shardingsphere.transaction.xa.narayana.manager;
 
 import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
 import com.arjuna.ats.jbossatx.jta.RecoveryManagerService;
-import 
org.apache.shardingsphere.transaction.xa.narayana.manager.fixture.ReflectiveUtil;
+import org.apache.shardingsphere.infra.util.reflect.ReflectiveUtil;
 import org.apache.shardingsphere.transaction.xa.spi.SingleXAResource;
 import org.junit.Before;
 import org.junit.Test;
@@ -59,9 +59,9 @@ public final class NarayanaXATransactionManagerProviderTest {
     
     @Before
     public void setUp() {
-        ReflectiveUtil.setProperty(transactionManagerProvider, 
"xaRecoveryModule", xaRecoveryModule);
-        ReflectiveUtil.setProperty(transactionManagerProvider, 
"transactionManager", transactionManager);
-        ReflectiveUtil.setProperty(transactionManagerProvider, 
"recoveryManagerService", recoveryManagerService);
+        ReflectiveUtil.setField(transactionManagerProvider, 
"xaRecoveryModule", xaRecoveryModule);
+        ReflectiveUtil.setField(transactionManagerProvider, 
"transactionManager", transactionManager);
+        ReflectiveUtil.setField(transactionManagerProvider, 
"recoveryManagerService", recoveryManagerService);
     }
     
     @Test
diff --git 
a/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/fixture/ReflectiveUtil.java
 
b/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/fixture/ReflectiveUtil.java
deleted file mode 100644
index dbc73bdc167..00000000000
--- 
a/kernel/transaction/type/xa/provider/narayana/src/test/java/org/apache/shardingsphere/transaction/xa/narayana/manager/fixture/ReflectiveUtil.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.transaction.xa.narayana.manager.fixture;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-
-import java.lang.reflect.Field;
-
-/**
- * Reflective utility.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ReflectiveUtil {
-    
-    /**
-     * Get field.
-     * 
-     * @param target target
-     * @param fieldName field name
-     * @return field
-     */
-    private static Field getField(final Object target, final String fieldName) 
{
-        Class<?> clazz = target.getClass();
-        while (null != clazz) {
-            try {
-                return clazz.getDeclaredField(fieldName);
-            } catch (final NoSuchFieldException ignored) {
-            }
-            clazz = clazz.getSuperclass();
-        }
-        return null;
-    }
-    
-    /**
-     * Set value to specified field.
-     * @param target target
-     * @param fieldName field name
-     * @param value value
-     */
-    @SneakyThrows(ReflectiveOperationException.class)
-    public static void setProperty(final Object target, final String 
fieldName, final Object value) {
-        Field field = getField(target, fieldName);
-        Preconditions.checkNotNull(field);
-        field.setAccessible(true);
-        field.set(target, value);
-    }
-}
diff --git 
a/test/integration-test/scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralIT.java
 
b/test/integration-test/scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralIT.java
index 8b340415fb0..34fe2e7816e 100644
--- 
a/test/integration-test/scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralIT.java
+++ 
b/test/integration-test/scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/migration/general/PostgreSQLMigrationGeneralIT.java
@@ -119,7 +119,7 @@ public final class PostgreSQLMigrationGeneralIT extends 
AbstractMigrationITCase
         Comparable<?> recordId = KEY_GENERATE_ALGORITHM.generateKey();
         sourceExecuteWithLog(String.format("INSERT INTO %s 
(order_id,user_id,status) VALUES (%s, %s, '%s')", String.join(".", SCHEMA_NAME, 
getSourceTableOrderName()), recordId, 1, "afterStop"));
         startMigrationByJobId(jobId);
-        // must refresh firstly, otherwise proxy can't get schema and table 
info 
+        // must refresh firstly, otherwise proxy can't get schema and table 
info
         proxyExecuteWithLog("REFRESH TABLE METADATA;", 2);
         assertProxyOrderRecordExist(recordId, String.join(".", SCHEMA_NAME, 
getTargetTableOrderName()));
         assertCheckMigrationSuccess(jobId, "DATA_MATCH");


Reply via email to