Fixed sonar fix in DataSourceWrap.java 85/75085/1
authorezhil <ezhrajam@in.ibm.com>
Wed, 26 Dec 2018 10:25:51 +0000 (15:55 +0530)
committerezhil <ezhrajam@in.ibm.com>
Wed, 26 Dec 2018 10:26:04 +0000 (15:56 +0530)
Fixed major bug
Issue-ID: CCSDK-838
Change-Id: Iee8ce39e54f15f33e9d682068d721fb56610d12c
Signed-off-by: ezhil <ezhrajam@in.ibm.com>
resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/util/db/DataSourceWrap.java

index 2aebb83..259b9d8 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
  *                         reserved.
+ * Modifications Copyright (C) 2018 IBM.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -74,25 +75,22 @@ public class DataSourceWrap implements DataSource {
 
     @Override
     public Connection getConnection() throws SQLException {
-        Connection c = dataSource.getConnection();
-
-        log.debug("getConnection: " + c.getClass().getName());
-
-        c.setAutoCommit(true);
-        return c;
+        try (Connection c = dataSource.getConnection()){
+            log.debug("getConnection: " + c.getClass().getName());
+            c.setAutoCommit(true);
+            return c;
+        }
     }
-
     @Override
     public Connection getConnection(String username, String password) throws SQLException {
-        Connection c = dataSource.getConnection(username, password);
-
-        log.debug("getConnection: " + c.getClass().getName());
-
-        c.setAutoCommit(true);
-        return c;
+        try (Connection c = dataSource.getConnection(username, password)){
+            log.debug("getConnection: " + c.getClass().getName());
+            c.setAutoCommit(true);
+            return c;
+        }
     }
 
-    public void setDataSource(DataSource dataSource) {
+        public void setDataSource(DataSource dataSource) {
         this.dataSource = dataSource;
     }
 }