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

wuweijie 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 40b8b8b  For code format (#10103)
40b8b8b is described below

commit 40b8b8ba34f965cf5594034dd42e6c093628fecf
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Apr 16 00:05:29 2021 +0800

    For code format (#10103)
---
 .../builder/dialect/SQLServerPrivilegeHandler.java | 59 ++++++++++------------
 .../dialect/OraclePrivilegeHandlerTest.java        |  5 +-
 .../dialect/PostgreSQLPrivilegeHandlerTest.java    |  5 +-
 .../dialect/SQLServerPrivilegeLoaderTest.java      | 22 +++-----
 .../rdl/impl/AddResourceBackendHandler.java        | 15 +++---
 5 files changed, 45 insertions(+), 61 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java
index c305a68..58651af 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/main/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeHandler.java
@@ -45,34 +45,34 @@ import java.util.stream.Collectors;
  * SQLServer privilege loader.
  */
 public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler {
-
+    
     private static final String GLOBAL_PRIVILEGE_SQL =
             "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, 
pe.permission_name AS PRIVILEGE_TYPE"
                     + "FROM sys.server_principals AS pr JOIN 
sys.server_permissions AS pe"
                     + "ON pe.grantee_principal_id = pr.principal_id WHERE 
pr.name IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name";
-
+    
     private static final String SCHEMA_PRIVILEGE_SQL =
             "SELECT pr.name AS GRANTEE, pe.state_desc AS STATE, 
pe.permission_name AS PRIVILEGE_TYPE, o.name AS DB"
                     + "FROM sys.database_principals AS pr JOIN 
sys.database_permissions AS pe"
                     + "ON pe.grantee_principal_id = pr.principal_id JOIN 
sys.objects AS o"
                     + "ON pe.major_id = o.object_id WHERE pr.name IN (%s) 
GROUP BY pr.name, pe.state_desc, pe.permission_name, o.name";
-
+    
     private static final String TABLE_PRIVILEGE_SQL =
             "SELECT GRANTOR, GRANTEE, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, 
PRIVILEGE_TYPE, IS_GRANTABLE from INFORMATION_SCHEMA.TABLE_PRIVILEGES WHERE 
GRANTEE IN (%s)";
-
+    
     @Override
-    public Collection<ShardingSphereUser> diff(final 
Collection<ShardingSphereUser> users, final DataSource dataSource) throws 
SQLException {
+    public Collection<ShardingSphereUser> diff(final 
Collection<ShardingSphereUser> users, final DataSource dataSource) {
         return Collections.emptyList();
     }
-
+    
     @Override
-    public void create(final Collection<ShardingSphereUser> users, final 
DataSource dataSource) throws SQLException {
+    public void create(final Collection<ShardingSphereUser> users, final 
DataSource dataSource) {
     }
-
+    
     @Override
-    public void grantAll(final Collection<ShardingSphereUser> users, final 
DataSource dataSource) throws SQLException {
+    public void grantAll(final Collection<ShardingSphereUser> users, final 
DataSource dataSource) {
     }
-
+    
     @Override
     public Map<ShardingSphereUser, NativePrivileges> load(final 
Collection<ShardingSphereUser> users, final DataSource dataSource) throws 
SQLException {
         Map<ShardingSphereUser, NativePrivileges> result = new 
LinkedHashMap<>();
@@ -82,7 +82,7 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
         fillTablePrivileges(result, dataSource, users);
         return result;
     }
-
+    
     private void fillGlobalPrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap,
                                       final DataSource dataSource, final 
Collection<ShardingSphereUser> users) throws SQLException {
         try (Connection connection = dataSource.getConnection()) {
@@ -94,16 +94,15 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
             }
         }
     }
-
+    
     private void fillGlobalPrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws 
SQLException {
         Optional<ShardingSphereUser> user = 
findShardingSphereUser(userPrivilegeMap, resultSet);
         if (user.isPresent()) {
             
userPrivilegeMap.get(user.get()).getAdministrativePrivileges().getPrivileges().addAll(loadPrivileges(resultSet));
         }
     }
-
-    private void fillSchemaPrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap,
-                                      final DataSource dataSource, final 
Collection<ShardingSphereUser> users) throws SQLException {
+    
+    private void fillSchemaPrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap, final DataSource dataSource, final 
Collection<ShardingSphereUser> users) throws SQLException {
         try (Connection connection = dataSource.getConnection()) {
             Statement statement = connection.createStatement();
             try (ResultSet resultSet = 
statement.executeQuery(getSchemaPrivilegesSQL(users))) {
@@ -113,7 +112,7 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
             }
         }
     }
-
+    
     private void fillSchemaPrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap, final ResultSet resultSet) throws 
SQLException {
         Optional<ShardingSphereUser> user = 
findShardingSphereUser(userPrivilegeMap, resultSet);
         if (user.isPresent()) {
@@ -123,9 +122,8 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
             
userPrivilegeMap.get(user.get()).getDatabasePrivileges().getSpecificPrivileges().put(db,
 schemaPrivileges);
         }
     }
-
-    private void fillTablePrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap,
-                                     final DataSource dataSource, final 
Collection<ShardingSphereUser> users) throws SQLException {
+    
+    private void fillTablePrivileges(final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap, final DataSource dataSource, final 
Collection<ShardingSphereUser> users) throws SQLException {
         Map<ShardingSphereUser, Map<String, Map<String, List<PrivilegeType>>>> 
privilegeCache = new HashMap<>();
         try (Connection connection = dataSource.getConnection()) {
             Statement statement = connection.createStatement();
@@ -137,9 +135,8 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
         }
         fillTablePrivileges(privilegeCache, userPrivilegeMap);
     }
-
-    private void fillTablePrivileges(final Map<ShardingSphereUser, Map<String, 
Map<String, List<PrivilegeType>>>> privilegeCache,
-                                     final Map<ShardingSphereUser, 
NativePrivileges> userPrivilegeMap) {
+    
+    private void fillTablePrivileges(final Map<ShardingSphereUser, Map<String, 
Map<String, List<PrivilegeType>>>> privilegeCache, final 
Map<ShardingSphereUser, NativePrivileges> userPrivilegeMap) {
         for (Map.Entry<ShardingSphereUser, Map<String, Map<String, 
List<PrivilegeType>>>> entry : privilegeCache.entrySet()) {
             for (String db : entry.getValue().keySet()) {
                 for (String tableName : entry.getValue().get(db).keySet()) {
@@ -153,12 +150,12 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
             }
         }
     }
-
+    
     private void collectPrivileges(final Map<ShardingSphereUser, Map<String, 
Map<String, List<PrivilegeType>>>> privilegeCache, final ResultSet resultSet) 
throws SQLException {
         String db = resultSet.getString("TABLE_CATALOG");
         String tableName = resultSet.getString("TABLE_NAME");
         String privilegeType = resultSet.getString("PRIVILEGE_TYPE");
-        boolean hasPrivilege = 
resultSet.getString("IS_GRANTABLE").equalsIgnoreCase("YES");
+        boolean hasPrivilege = 
"YES".equalsIgnoreCase(resultSet.getString("IS_GRANTABLE"));
         String grantee = resultSet.getString("GRANTEE");
         if (hasPrivilege) {
             privilegeCache
@@ -168,28 +165,28 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
                     .add(getPrivilegeType(privilegeType));
         }
     }
-
+    
     private Optional<ShardingSphereUser> findShardingSphereUser(final 
Map<ShardingSphereUser, NativePrivileges> privileges, final ResultSet 
resultSet) throws SQLException {
         Grantee grantee = new Grantee(resultSet.getString("GRANTEE"), "");
         return privileges.keySet().stream().filter(each -> 
each.getGrantee().equals(grantee)).findFirst();
     }
-
+    
     private String getGlobalPrivilegesSQL(final Collection<ShardingSphereUser> 
users) {
         String userHostTuples = users.stream().map(each -> 
String.format("'%s'", 
each.getGrantee().getUsername())).collect(Collectors.joining(","));
         return String.format(GLOBAL_PRIVILEGE_SQL, userHostTuples);
     }
-
+    
     private String getSchemaPrivilegesSQL(final Collection<ShardingSphereUser> 
users) {
         String userList = users.stream().map(each -> String.format("'%s'", 
each.getGrantee().getUsername()))
                 .collect(Collectors.joining(","));
         return String.format(SCHEMA_PRIVILEGE_SQL, userList);
     }
-
+    
     private String getTablePrivilegesSQL(final Collection<ShardingSphereUser> 
users) {
         String userList = users.stream().map(each -> String.format("'%s'", 
each.getGrantee().getUsername())).collect(Collectors.joining(", "));
         return String.format(TABLE_PRIVILEGE_SQL, userList);
     }
-
+    
     private PrivilegeType getPrivilegeType(final String privilege) {
         switch (privilege) {
             case "SELECT":
@@ -296,7 +293,7 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
                 throw new UnsupportedOperationException(privilege);
         }
     }
-
+    
     private Collection<PrivilegeType> loadPrivileges(final ResultSet 
resultSet) throws SQLException {
         Collection<PrivilegeType> result = new LinkedList<>();
         if ("GRANT".equals(resultSet.getString("STATE"))) {
@@ -304,7 +301,7 @@ public final class SQLServerPrivilegeHandler implements 
StoragePrivilegeHandler
         }
         return result;
     }
-
+    
     @Override
     public String getType() {
         return "SQLServer";
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
index 719d39d..36dff0c 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/OraclePrivilegeHandlerTest.java
@@ -17,8 +17,8 @@
 
 package org.apache.shardingsphere.authority.provider.natived.builder.dialect;
 
-import 
org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
 import org.apache.shardingsphere.authority.model.PrivilegeType;
+import 
org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
 import 
org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
 import 
org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
@@ -26,8 +26,6 @@ import 
org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
 import java.sql.ResultSet;
@@ -47,7 +45,6 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
 public final class OraclePrivilegeHandlerTest {
     
     @BeforeClass
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java
index 27aa403..845ed65 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/PostgreSQLPrivilegeHandlerTest.java
@@ -18,16 +18,14 @@
 package org.apache.shardingsphere.authority.provider.natived.builder.dialect;
 
 import org.apache.shardingsphere.authority.model.PrivilegeType;
+import 
org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
 import 
org.apache.shardingsphere.authority.provider.natived.model.privilege.NativePrivileges;
 import 
org.apache.shardingsphere.authority.provider.natived.model.privilege.database.SchemaPrivileges;
-import 
org.apache.shardingsphere.authority.provider.natived.builder.StoragePrivilegeHandler;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
 import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
 import java.sql.ResultSet;
@@ -47,7 +45,6 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
 public final class PostgreSQLPrivilegeHandlerTest {
     
     @BeforeClass
diff --git 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeLoaderTest.java
 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeLoaderTest.java
index 2f7efb3..98a3d1d 100644
--- 
a/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeLoaderTest.java
+++ 
b/shardingsphere-features/shardingsphere-authority/shardingsphere-authority-common/src/test/java/org/apache/shardingsphere/authority/provider/natived/builder/dialect/SQLServerPrivilegeLoaderTest.java
@@ -26,8 +26,6 @@ import 
org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
 
 import javax.sql.DataSource;
 import java.sql.ResultSet;
@@ -46,21 +44,20 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
 public final class SQLServerPrivilegeLoaderTest {
-
+    
     @BeforeClass
     public static void setUp() {
         ShardingSphereServiceLoader.register(StoragePrivilegeHandler.class);
     }
-
+    
     @Test
     public void assertLoad() throws SQLException {
         Collection<ShardingSphereUser> users = createUsers();
         DataSource dataSource = mockDataSource(users);
         
assertPrivileges(TypedSPIRegistry.getRegisteredService(StoragePrivilegeHandler.class,
 "SQLServer", new Properties()).load(users, dataSource));
     }
-
+    
     private void assertPrivileges(final Map<ShardingSphereUser, 
NativePrivileges> actual) {
         assertThat(actual.size(), is(1));
         ShardingSphereUser dbo = new ShardingSphereUser("dbo", "", "");
@@ -73,36 +70,33 @@ public final class SQLServerPrivilegeLoaderTest {
         SchemaPrivileges schemaPrivileges = 
actual.get(dbo).getDatabasePrivileges().getSpecificPrivileges().get("db0");
         
assertThat(schemaPrivileges.getSpecificPrivileges().get("t_order").hasPrivileges(expectedSpecificPrivilege),
 is(true));
     }
-
+    
     private Collection<ShardingSphereUser> createUsers() {
         LinkedList<ShardingSphereUser> result = new LinkedList<>();
         result.add(new ShardingSphereUser("dbo", "", ""));
         return result;
     }
-
+    
     private DataSource mockDataSource(final Collection<ShardingSphereUser> 
users) throws SQLException {
         ResultSet globalPrivilegeResultSet = mockGlobalPrivilegeResultSet();
         DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
         String userList = users.stream().map(item -> String.format("'%s'", 
item.getGrantee().getUsername())).collect(Collectors.joining(", "));
-
         String globalPrivilegeSql = "SELECT pr.name AS GRANTEE, pe.state_desc 
AS STATE, pe.permission_name AS PRIVILEGE_TYPE"
                 + "FROM sys.server_principals AS pr JOIN 
sys.server_permissions AS pe"
                 + "ON pe.grantee_principal_id = pr.principal_id WHERE pr.name 
IN (%s) GROUP BY pr.name, pe.state_desc, pe.permission_name";
         
when(result.getConnection().createStatement().executeQuery(String.format(globalPrivilegeSql,
 userList))).thenReturn(globalPrivilegeResultSet);
-
         ResultSet schemaPrivilegeResultSet = mockSchemaPrivilegeResultSet();
         String schemaPrivilegeSql = "SELECT pr.name AS GRANTEE, pe.state_desc 
AS STATE, pe.permission_name AS PRIVILEGE_TYPE, o.name AS DB"
                 + "FROM sys.database_principals AS pr JOIN 
sys.database_permissions AS pe"
                 + "ON pe.grantee_principal_id = pr.principal_id JOIN 
sys.objects AS o"
                 + "ON pe.major_id = o.object_id WHERE pr.name IN (%s) GROUP BY 
pr.name, pe.state_desc, pe.permission_name, o.name";
         
when(result.getConnection().createStatement().executeQuery(String.format(schemaPrivilegeSql,
 userList))).thenReturn(schemaPrivilegeResultSet);
-
         ResultSet tablePrivilegeResultSet = mockTablePrivilegeResultSet();
         String tablePrivilegeSql = "SELECT GRANTOR, GRANTEE, TABLE_CATALOG, 
TABLE_SCHEMA, TABLE_NAME, PRIVILEGE_TYPE, IS_GRANTABLE from 
INFORMATION_SCHEMA.TABLE_PRIVILEGES WHERE GRANTEE IN (%s)";
         
when(result.getConnection().createStatement().executeQuery(String.format(tablePrivilegeSql,
 userList))).thenReturn(tablePrivilegeResultSet);
         return result;
     }
-
+    
     private ResultSet mockGlobalPrivilegeResultSet() throws SQLException {
         ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
         when(result.next()).thenReturn(true, true, false);
@@ -111,7 +105,7 @@ public final class SQLServerPrivilegeLoaderTest {
         when(result.getString("PRIVILEGE_TYPE")).thenReturn("CONNECT", 
"SHUTDOWN");
         return result;
     }
-
+    
     private ResultSet mockTablePrivilegeResultSet() throws SQLException {
         ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
         when(result.next()).thenReturn(true, true, true, true, true, true, 
true, false);
@@ -122,7 +116,7 @@ public final class SQLServerPrivilegeLoaderTest {
         when(result.getString("GRANTEE")).thenReturn("dbo");
         return result;
     }
-
+    
     private ResultSet mockSchemaPrivilegeResultSet() throws SQLException {
         ResultSet result = mock(ResultSet.class, RETURNS_DEEP_STUBS);
         when(result.next()).thenReturn(true, false);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
index 974af29..2e0cf19 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
@@ -37,6 +37,7 @@ import 
org.apache.shardingsphere.proxy.converter.AddResourcesStatementConverter;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -65,21 +66,19 @@ public final class AddResourceBackendHandler extends 
SchemaRequiredBackendHandle
     
     private Map<String, DataSourceConfiguration> check(final String 
schemaName, final AddResourceStatement sqlStatement) {
         List<String> dataSourceNames = new 
ArrayList<>(sqlStatement.getDataSources().size());
-        Set<String> duplicateDataSourceNames = new HashSet<>();
-        for (DataSourceSegment dataSourceSegment : 
sqlStatement.getDataSources()) {
-            if (dataSourceNames.contains(dataSourceSegment.getName()) 
-                    || ProxyContext.getInstance().getMetaData(schemaName)
-                    
.getResource().getDataSources().containsKey(dataSourceSegment.getName())) {
-                duplicateDataSourceNames.add(dataSourceSegment.getName());
+        Set<String> duplicateDataSourceNames = new 
HashSet<>(sqlStatement.getDataSources().size(), 1);
+        for (DataSourceSegment each : sqlStatement.getDataSources()) {
+            if (dataSourceNames.contains(each.getName()) || 
ProxyContext.getInstance().getMetaData(schemaName).getResource().getDataSources().containsKey(each.getName()))
 {
+                duplicateDataSourceNames.add(each.getName());
             }
-            dataSourceNames.add(dataSourceSegment.getName());
+            dataSourceNames.add(each.getName());
         }
         if (!duplicateDataSourceNames.isEmpty()) {
             throw new DuplicateResourceException(duplicateDataSourceNames);
         }
         Map<String, DataSourceConfiguration> result = 
DataSourceParameterConverter.getDataSourceConfigurationMap(
                 
DataSourceParameterConverter.getDataSourceParameterMapFromYamlConfiguration(AddResourcesStatementConverter.convert(databaseType,
 sqlStatement)));
-        Collection<String> invalidDataSourceNames = new ArrayList<>();
+        Collection<String> invalidDataSourceNames = new LinkedList<>();
         for (Entry<String, DataSourceConfiguration> entry : result.entrySet()) 
{
             if (!dataSourceValidator.validate(entry.getValue())) {
                 invalidDataSourceNames.add(entry.getKey());

Reply via email to