Skip to content

Commit 1f2aa40

Browse files
committed
Fix checkstyle warnings
1 parent bc44d82 commit 1f2aa40

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/link/mysql/MySQLConnectionUtils.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package com.microsoft.azure.toolkit.intellij.link.mysql;
77

88
import com.microsoft.azuretools.ActionConstants;
9-
import com.microsoft.azuretools.telemetry.TelemetryConstants;
109
import com.microsoft.azuretools.telemetrywrapper.EventType;
1110
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
1211
import com.mysql.cj.jdbc.ConnectionImpl;
@@ -27,9 +26,9 @@ public static boolean connect(String url, String username, String password) {
2726
Class.forName("com.mysql.jdbc.Driver");
2827
DriverManager.getConnection(url, username, password);
2928
return true;
30-
} catch (ClassNotFoundException | SQLException exception) {
29+
} catch (final ClassNotFoundException | SQLException exception) {
30+
return false;
3131
}
32-
return false;
3332
}
3433

3534
public static ConnectResult connectWithPing(String url, String username, String password) {
@@ -41,20 +40,20 @@ public static ConnectResult connectWithPing(String url, String username, String
4140
// refresh property
4241
try {
4342
Class.forName("com.mysql.jdbc.Driver");
44-
long start = System.currentTimeMillis();
45-
Connection connection = DriverManager.getConnection(url, username, password);
43+
final long start = System.currentTimeMillis();
44+
final Connection connection = DriverManager.getConnection(url, username, password);
4645
connected = true;
47-
Statement statement = connection.createStatement();
48-
ResultSet resultSet = statement.executeQuery("select 'hi'");
46+
final Statement statement = connection.createStatement();
47+
final ResultSet resultSet = statement.executeQuery("select 'hi'");
4948
if (resultSet.next()) {
50-
String result = resultSet.getString(1);
49+
final String result = resultSet.getString(1);
5150
connected = "hi".equals(result);
5251
}
5352
pingCost = System.currentTimeMillis() - start;
5453
serverVersion = ((ConnectionImpl) connection).getServerVersion().toString();
55-
} catch (ClassNotFoundException exception) {
54+
} catch (final ClassNotFoundException exception) {
5655
errorMessage = exception.getMessage();
57-
} catch (SQLException exception) {
56+
} catch (final SQLException exception) {
5857
errorCode = exception.getErrorCode();
5958
errorMessage = isConnectionIssue(exception) ? String.format(CONNECTION_ISSUE_MESSAGE, exception.getMessage()) : exception.getMessage();
6059
}
@@ -64,17 +63,17 @@ public static ConnectResult connectWithPing(String url, String username, String
6463
return new ConnectResult(connected, errorMessage, pingCost, serverVersion, errorCode);
6564
}
6665

67-
private static boolean isConnectionIssue(final SQLException exception){
66+
private static boolean isConnectionIssue(final SQLException exception) {
6867
return exception.getErrorCode() == CONNECTION_ERROR_CODE;
6968
}
7069

7170
@Getter
7271
@AllArgsConstructor
7372
public static class ConnectResult {
74-
private boolean connected;
75-
private String message;
76-
private Long pingCost;
77-
private String serverVersion;
78-
private int errorCode;
73+
private final boolean connected;
74+
private final String message;
75+
private final Long pingCost;
76+
private final String serverVersion;
77+
private final int errorCode;
7978
}
8079
}

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/lib/link/AzureLinkService.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ private AzureLinkService() {
4444
}
4545

4646
public void link(Project project, LinkConfig<MySQLResourceConfig, ModuleResourceConfig> linkComposite, boolean storageResource) {
47-
ModulePO modulePO = createModulePO(linkComposite.getModule());
47+
final ModulePO modulePO = createModulePO(linkComposite.getModule());
4848
// create resource
49-
MySQLResourcePO resource = createResourcePO(linkComposite.getResource());
49+
final MySQLResourcePO resource = createResourcePO(linkComposite.getResource());
5050
// create link
51-
LinkPO linkPO = new LinkPO(resource.getId(), modulePO.getResourceId(), LinkType.SERVICE_WITH_MODULE, linkComposite.getEnvPrefix());
51+
final LinkPO linkPO = new LinkPO(resource.getId(), modulePO.getResourceId(), LinkType.SERVICE_WITH_MODULE, linkComposite.getEnvPrefix());
5252
// storage mysql
5353
if (storageResource) {
5454
AzureMySQLStorage.getStorage().addResource(resource);
5555
}
5656
// storage password
5757
if (ArrayUtils.isNotEmpty(linkComposite.getResource().getPasswordConfig().getPassword())) {
58-
String inputPassword = String.valueOf(linkComposite.getResource().getPasswordConfig().getPassword());
58+
final String inputPassword = String.valueOf(linkComposite.getResource().getPasswordConfig().getPassword());
5959
AzureMySQLStorage.getStorage().savePassword(resource, resource.getPasswordSave(), resource.getUsername(), inputPassword);
6060
}
6161
// storage link
@@ -67,40 +67,39 @@ private ModulePO createModulePO(ModuleResourceConfig config) {
6767
}
6868

6969
private MySQLResourcePO createResourcePO(MySQLResourceConfig config) {
70-
JdbcUrl jdbcUrl = JdbcUrl.from(config.getUrl());
71-
String businessUniqueKey = MySQLResourcePO.getBusinessUniqueKey(config.getServer().id(), jdbcUrl.getDatabase());
72-
MySQLResourcePO existedResourcePO = AzureMySQLStorage.getStorage().getResourceByBusinessUniqueKey(businessUniqueKey);
73-
String id = Objects.nonNull(existedResourcePO) ? existedResourcePO.getId() : DigestUtils.md5Hex(businessUniqueKey);
74-
MySQLResourcePO resourcePO = MySQLResourcePO.builder()
70+
final JdbcUrl jdbcUrl = JdbcUrl.from(config.getUrl());
71+
final String businessUniqueKey = MySQLResourcePO.getBusinessUniqueKey(config.getServer().id(), jdbcUrl.getDatabase());
72+
final MySQLResourcePO existedResourcePO = AzureMySQLStorage.getStorage().getResourceByBusinessUniqueKey(businessUniqueKey);
73+
final String id = Objects.nonNull(existedResourcePO) ? existedResourcePO.getId() : DigestUtils.md5Hex(businessUniqueKey);
74+
return MySQLResourcePO.builder()
7575
.id(id)
7676
.resourceId(config.getServer().id())
7777
.url(config.getUrl())
7878
.username(config.getUsername())
7979
.passwordSave(config.getPasswordConfig().getPasswordSaveType())
8080
.build();
81-
return resourcePO;
8281
}
8382

8483
public Map<String, String> retrieveLinkEnvsByModuleName(Project project, String moduleName) {
85-
Map<String, String> linkedEnvMap = new LinkedHashMap<>();
86-
List<LinkPO> moduleRelatedLinkList = AzureLinkStorage.getProjectStorage(project).getLinkByModuleId(moduleName)
84+
final Map<String, String> linkedEnvMap = new LinkedHashMap<>();
85+
final List<LinkPO> moduleRelatedLinkList = AzureLinkStorage.getProjectStorage(project).getLinkByModuleId(moduleName)
8786
.stream()
8887
.filter(e -> LinkType.SERVICE_WITH_MODULE.equals(e.getType()))
8988
.collect(Collectors.toList());
9089
if (CollectionUtils.isEmpty(moduleRelatedLinkList)) {
9190
return linkedEnvMap;
9291
}
9392
// services in application level
94-
Set<? extends BaseResourcePO> serviceSet = AzureMySQLStorage.getStorage().getResources();
95-
for (BaseResourcePO service : serviceSet) {
96-
for (LinkPO link : moduleRelatedLinkList) {
93+
final Set<? extends BaseResourcePO> serviceSet = AzureMySQLStorage.getStorage().getResources();
94+
for (final BaseResourcePO service : serviceSet) {
95+
for (final LinkPO link : moduleRelatedLinkList) {
9796
if (!StringUtils.equals(link.getResourceId(), service.getId())) {
9897
continue;
9998
}
100-
String envPrefix = link.getEnvPrefix();
99+
final String envPrefix = link.getEnvPrefix();
101100
if (ResourceType.AZURE_DATABASE_FOR_MYSQL.equals(service.getType())) {
102-
MySQLResourcePO mysql = (MySQLResourcePO) service;
103-
String password = readPasswordCredentials(project, mysql);
101+
final MySQLResourcePO mysql = (MySQLResourcePO) service;
102+
final String password = readPasswordCredentials(project, mysql);
104103
linkedEnvMap.put(envPrefix + "URL", mysql.getUrl());
105104
linkedEnvMap.put(envPrefix + "USERNAME", mysql.getUsername());
106105
linkedEnvMap.put(envPrefix + "PASSWORD", password);
@@ -123,12 +122,12 @@ private String readPasswordCredentials(Project project, MySQLResourcePO service)
123122
}
124123
}
125124
// re-input password
126-
AtomicReference<PasswordConfig> passwordConfigReference = new AtomicReference<>();
125+
final AtomicReference<PasswordConfig> passwordConfigReference = new AtomicReference<>();
127126
ApplicationManager.getApplication().invokeAndWait(() -> {
128-
PasswordDialog dialog = new PasswordDialog(project, service.getUsername(), service.getUrl());
127+
final PasswordDialog dialog = new PasswordDialog(project, service.getUsername(), service.getUrl());
129128
dialog.setOkActionListener(data -> {
130129
dialog.close();
131-
String inputPassword = String.valueOf(data.getPassword());
130+
final String inputPassword = String.valueOf(data.getPassword());
132131
if (MySQLConnectionUtils.connect(service.getUrl(), service.getUsername(), inputPassword)) {
133132
AzureMySQLStorage.getStorage().savePassword(service, data.getPasswordSaveType(), service.getUsername(), inputPassword);
134133
if (!Objects.equals(service.getPasswordSave(), data.getPasswordSaveType())) {
@@ -141,7 +140,7 @@ private String readPasswordCredentials(Project project, MySQLResourcePO service)
141140
EventUtil.logEvent(EventType.info, ActionConstants.parse(ActionConstants.MySQL.UPDATE_PASSWORD).getServiceName(),
142141
ActionConstants.parse(ActionConstants.MySQL.UPDATE_PASSWORD).getOperationName(), null);
143142
});
144-
PasswordConfig passwordConfig = passwordConfigReference.get();
143+
final PasswordConfig passwordConfig = passwordConfigReference.get();
145144
if (Objects.nonNull(passwordConfig)) {
146145
return String.valueOf(passwordConfig.getPassword());
147146
} else {

0 commit comments

Comments
 (0)