Fix Sonar Issues
authorsurya-huawei <a.u.surya@huawei.com>
Tue, 12 Sep 2017 09:59:44 +0000 (15:29 +0530)
committerSURYA A U <a.u.surya@huawei.com>
Wed, 13 Sep 2017 09:52:19 +0000 (09:52 +0000)
few major issues in sli/core/dblib module

Issue-id: CCSDK-87
Change-Id: Ie3b13468d23c1e7dc2228bb7a0cd1bde5cc632e8
Signed-off-by: surya-huawei <a.u.surya@huawei.com>
dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java
dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java

index 8181b13..40d1a23 100644 (file)
@@ -43,7 +43,6 @@ import java.util.concurrent.Executor;
 import javax.sql.rowset.CachedRowSet;
 
 import org.apache.tomcat.jdbc.pool.PooledConnection;
-import org.apache.tomcat.jdbc.pool.ProxyConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,7 +64,8 @@ public class DBLibConnection implements Connection {
 
        public boolean lockTable(String tablename) {
                this.tableName = tablename;
-               return locked = dataSource.lockTable(connection, tableName);
+               locked = dataSource.lockTable(connection, tableName);
+               return locked;
        }
 
        public void resetInactivityTimer() {
@@ -80,12 +80,13 @@ public class DBLibConnection implements Connection {
 
        public boolean unlock() {
                dataSource.unlockTable(connection);
-               return locked = false;
+               locked = false;
+               return locked;
        }
 
        public boolean writeData(String statement, ArrayList<String> arguments) throws SQLException, Throwable
        {
-               ArrayList<Object> newList=new ArrayList<Object>();
+               ArrayList<Object> newList= new ArrayList<>();
                if(arguments != null && !arguments.isEmpty()) {
                        newList.addAll(arguments);
                }
@@ -95,7 +96,7 @@ public class DBLibConnection implements Connection {
 
        public CachedRowSet getData(String statement, ArrayList<String> arguments) throws SQLException, Throwable
        {
-               ArrayList<Object> newList=new ArrayList<Object>();
+               ArrayList<Object> newList= new ArrayList<>();
                if(arguments != null && !arguments.isEmpty()) {
                        newList.addAll(arguments);
                }
index 46c003a..ac67c3f 100644 (file)
@@ -38,9 +38,7 @@ import java.util.PriorityQueue;
 import java.util.Properties;
 import java.util.Queue;
 import java.util.Set;
-import java.util.Timer;
 import java.util.TimerTask;
-import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.sql.DataSource;
@@ -76,23 +74,22 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
        protected final AtomicBoolean dsSelector = new  AtomicBoolean();
 
 //     Queue<CachedDataSource> dsQueue = new ConcurrentLinkedQueue<CachedDataSource>();
-       Queue<CachedDataSource> dsQueue = new PriorityQueue<CachedDataSource>(4, new Comparator<CachedDataSource>(){
-
+       Queue<CachedDataSource> dsQueue = new PriorityQueue<>(4, new Comparator<CachedDataSource>() {
                @Override
                public int compare(CachedDataSource left, CachedDataSource right) {
                        try {
-                               if(!left.isSlave())
+                               if (!left.isSlave()) {
                                        return -1;
-                               if(!right.isSlave())
+                               }
+                               if (!right.isSlave()) {
                                        return 1;
-
+                               }
                        } catch (Throwable e) {
                                LOGGER.warn("", e);
                        }
                        return 0;
                }
-
-       });
+               });
        protected final Set<CachedDataSource> broken = Collections.synchronizedSet(new HashSet<CachedDataSource>());
        protected final Object monitor = new Object();
        protected final Properties configProps;
@@ -240,6 +237,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
 
        class RecoveryMgr extends Thread {
 
+               @Override
                public void run() {
                        while(!terminating)
                        {
@@ -295,7 +293,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
         */
        @Override
        public CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException {
-               ArrayList<Object> newList=new ArrayList<Object>();
+               ArrayList<Object> newList= new ArrayList<>();
                if(arguments != null && !arguments.isEmpty()) {
                        newList.addAll(arguments);
                }
@@ -310,7 +308,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
                CachedDataSource active = null;
 
                // test if there are any connection pools available
-               LinkedList<CachedDataSource> sources = new LinkedList<CachedDataSource>(this.dsQueue);
+               LinkedList<CachedDataSource> sources = new LinkedList<>(this.dsQueue);
                if(sources.isEmpty()){
                        LOGGER.error("Generated alarm: DBResourceManager.getData - No active DB connection pools are available.");
                        throw new DBLibException("No active DB connection pools are available in RequestDataWithRecovery call.");
@@ -356,7 +354,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
                                handleGetConnectionException(active, exc);
                        } finally {
                                if(LOGGER.isDebugEnabled()){
-                                       time = (System.currentTimeMillis() - time);
+                                       time = System.currentTimeMillis() - time;
                                        LOGGER.debug("getData processing time : "+ active.getDbConnectionName()+"  "+time+" miliseconds.");
                                }
                        }
@@ -410,7 +408,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
                        }
                } finally {
                        if(LOGGER.isDebugEnabled()){
-                               time = (System.currentTimeMillis() - time);
+                               time = System.currentTimeMillis() - time;
                                LOGGER.debug(">> getData : "+ active.getDbConnectionName()+"  "+time+" miliseconds.");
                        }
                }
@@ -423,7 +421,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
        @Override
        public boolean writeData(String statement, ArrayList<String> arguments, String preferredDS) throws SQLException
         {
-               ArrayList<Object> newList=new ArrayList<Object>();
+               ArrayList<Object> newList= new ArrayList<>();
                if(arguments != null && !arguments.isEmpty()) {
                        newList.addAll(arguments);
                }
@@ -498,7 +496,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
                                }
                        } finally {
                                if(LOGGER.isDebugEnabled()){
-                                       time = (System.currentTimeMillis() - time);
+                                       time = System.currentTimeMillis() - time;
                                        LOGGER.debug("writeData processing time : "+ active.getDbConnectionName()+"  "+time+" miliseconds.");
                                }
                        }
@@ -710,7 +708,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
        public String getDBStatus(boolean htmlFormat) {
                StringBuilder buffer = new StringBuilder();
 
-               ArrayList<CachedDataSource> list = new ArrayList<CachedDataSource>();
+               ArrayList<CachedDataSource> list = new ArrayList<>();
                list.addAll(dsQueue);
                list.addAll(broken);
                if (htmlFormat)
@@ -795,7 +793,7 @@ public class DBResourceManager implements DataSource, DataAccessor, DBResourceOb
 
        public String getPreferredDataSourceName(AtomicBoolean flipper) {
 
-               LinkedList<CachedDataSource> snapshot = new LinkedList<CachedDataSource>(dsQueue);
+               LinkedList<CachedDataSource> snapshot = new LinkedList<>(dsQueue);
                if(snapshot.size() > 1){
                        CachedDataSource first = snapshot.getFirst();
                        CachedDataSource last = snapshot.getLast();