jixuan1989 commented on a change in pull request #25: Fix sonar
URL: https://github.com/apache/incubator-iotdb/pull/25#discussion_r250493818
##########
File path: iotdb-cli/src/main/java/org/apache/iotdb/cli/client/WinClient.java
##########
@@ -84,70 +83,50 @@ public static void main(String[] args) throws
ClassNotFoundException, SQLExcepti
hf.printHelp(IOTDB_CLI_PREFIX, options, true);
return;
}
- Scanner scanner = null;
- try {
- String s;
-
- try {
- host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false,
host);
- port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false,
port);
- username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine,
true, null);
- password = commandLine.getOptionValue(PASSWORD_ARGS);
- if (password == null) {
- password = readPassword();
- }
- try {
- connection = (IoTDBConnection) DriverManager
- .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port +
"/", username, password);
- properties = connection.getServerProperties();
-
AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
- } catch (SQLException e) {
- System.out.println(IOTDB_CLI_PREFIX + "> " + e.getMessage());
- return;
- }
- } catch (ArgsErrorException e) {
- // System.out.println(TSFILEDB_CLI_PREFIX + ": " + e.getMessage());
- return;
+ try (Scanner scanner = new Scanner(System.in)){
+ host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
+ port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
+ username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine,
true, null);
+ password = commandLine.getOptionValue(PASSWORD_ARGS);
+ if (password == null) {
+ password = readPassword();
}
-
- displayLogo(properties.getVersion());
-
- System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
- scanner = new Scanner(System.in);
- while (true) {
- System.out.print(IOTDB_CLI_PREFIX + "> ");
- s = scanner.nextLine();
- if (s == null) {
- continue;
- } else {
- String[] cmds = s.trim().split(";");
- for (int i = 0; i < cmds.length; i++) {
- String cmd = cmds[i];
- if (cmd != null && !cmd.trim().equals("")) {
- OperationResult result = handleInputInputCmd(cmd, connection);
- switch (result) {
- case RETURN_OPER:
- return;
- case CONTINUE_OPER:
- continue;
- default:
- break;
+ try(IoTDBConnection connection = (IoTDBConnection) DriverManager
+ .getConnection(Config.IOTDB_URL_PREFIX + host + ":" + port +
"/", username, password)){
+ properties = connection.getServerProperties();
+
AGGREGRATE_TIME_LIST.addAll(properties.getSupportedTimeAggregationOperations());
+ displayLogo(properties.getVersion());
+ System.out.println(IOTDB_CLI_PREFIX + "> login successfully");
+ while (true) {
+ System.out.print(IOTDB_CLI_PREFIX + "> ");
+ String s = scanner.nextLine();
+ if(s != null){
+ String[] cmds = s.trim().split(";");
+ for (int i = 0; i < cmds.length; i++) {
+ String cmd = cmds[i];
+ if (cmd != null && !cmd.trim().equals("")) {
+ OperationResult result = handleInputCmd(cmd, connection);
+ switch (result) {
+ case RETURN_OPER:
+ return;
+ case CONTINUE_OPER:
+ continue;
+ default:
+ break;
+ }
}
}
}
}
+ } catch (SQLException e) {
+ System.out.println(String.format("%s> %s Host is %s, port is %s.",
IOTDB_CLI_PREFIX, e.getMessage(), host, port));
}
- } catch (Exception e) {
- System.out.println(IOTDB_CLI_PREFIX + "> exit client with error " +
e.getMessage());
- } finally {
- if (scanner != null) {
- scanner.close();
- }
- if (connection != null) {
- connection.close();
- }
- }
+ } catch (ArgsErrorException e) {
+ System.out.println(IOTDB_CLI_PREFIX + "> input params error because" +
e.getMessage());
+ }catch (Exception e) {
Review comment:
checkstyle
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services