jt2594838 commented on a change in pull request #31: Fix sonar
URL: https://github.com/apache/incubator-iotdb/pull/31#discussion_r251005856
 
 

 ##########
 File path: 
iotdb/src/main/java/org/apache/iotdb/db/postback/receiver/ServerServiceImpl.java
 ##########
 @@ -193,32 +203,30 @@ public String startReceiving(String md5OfSender, 
List<String> filePathSplit,
    * IoTDB through jdbc status = 1 : the schema file has not received 
completely.
    */
   @Override
-  public void getSchema(ByteBuffer schema, int status) throws TException {
-    FileOutputStream fos = null;
-    FileChannel channel = null;
+  public void getSchema(ByteBuffer schema, int status) {
+    FileOutputStream fos;
+    FileChannel channel;
     if (status == 0) {
-      Connection connection = null;
       Statement statement = null;
-      try {
+      try (Connection connection = 
DriverManager.getConnection("jdbc:iotdb://localhost:" +
+          config.rpcPort + "/", "root", "root")) {
         Class.forName(JDBC_DRIVER_NAME);
-        connection = DriverManager.getConnection("jdbc:iotdb://localhost:" +
-            tsfileDBConfig.rpcPort + "/", "root", "root");
         statement = connection.createStatement();
 
-        BufferedReader bf;
-        try {
-          bf = new BufferedReader(new 
java.io.FileReader(schemaFromSenderPath.get()));
+        try (BufferedReader bf = new BufferedReader(
+            new java.io.FileReader(schemaFromSenderPath.get()))) {
           String data;
           statement.clearBatch();
           int count = 0;
           while ((data = bf.readLine()) != null) {
-            String item[] = data.split(",");
+            String[] item = data.split(",");
             if (item[0].equals("2")) {
-              String sql = "SET STORAGE GROUP TO " + item[1];
+              String sql = String.format("SET STORAGE GROUP TO %s", item[1]);
               statement.addBatch(sql);
             } else if (item[0].equals("0")) {
-              String sql = "CREATE TIMESERIES " + item[1] + " WITH DATATYPE=" 
+ item[2]
-                  + "," + " ENCODING=" + item[3];
+              String sql = String
+                  .format("CREATE TIMESERIES %s WITH DATATYPE=%s, 
ENCODING=%s", item[1], item[2],
+                      item[3]);
 
 Review comment:
   It is better to make the SQL templates some constants, while it is ok for me 
to leave them here.

----------------------------------------------------------------
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

Reply via email to