diff options
author | surya-huawei <a.u.surya@huawei.com> | 2017-09-12 15:29:44 +0530 |
---|---|---|
committer | SURYA A U <a.u.surya@huawei.com> | 2017-09-13 09:52:19 +0000 |
commit | 1ed8c1f3b0345fe28c61844df2a189a8b9b53594 (patch) | |
tree | 84c0da584fd90d33f24ecfc591c0f825972f4d74 /dblib/provider | |
parent | 2b433d67493ee2afcce619cc0cf2707ba3152491 (diff) |
Fix Sonar Issues
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>
Diffstat (limited to 'dblib/provider')
-rw-r--r-- | dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java | 11 | ||||
-rw-r--r-- | dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java | 32 |
2 files changed, 21 insertions, 22 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java index 8181b1300..40d1a2382 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLibConnection.java @@ -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); } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java index 46c003a5a..ac67c3f94 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java @@ -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(); |