Fix Sonar issues
authorsurya-huawei <a.u.surya@huawei.com>
Mon, 11 Sep 2017 11:06:49 +0000 (16:36 +0530)
committerSURYA A U <a.u.surya@huawei.com>
Tue, 12 Sep 2017 03:42:43 +0000 (03:42 +0000)
Few major issues in sli/core module

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

index 1729bce..ee8ab2f 100644 (file)
@@ -92,12 +92,14 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
        /* (non-Javadoc)
         * @see javax.sql.DataSource#getConnection()
         */
+       @Override
        public Connection getConnection() throws SQLException
        {
                return ds.getConnection();
        }
 
-       public CachedRowSet getData(String statement, ArrayList<Object> arguments) throws SQLException, Throwable
+       public CachedRowSet getData(String statement, ArrayList<Object> arguments)
+                       throws SQLException, Throwable
        {
                TestObject testObject = null;
                testObject = monitor.registerRequest();
@@ -126,7 +128,8 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                }
        }
 
-       public boolean writeData(String statement, ArrayList<Object> arguments) throws SQLException, Throwable
+       public boolean writeData(String statement, ArrayList<Object> arguments)
+                       throws SQLException, Throwable
        {
                TestObject testObject = null;
                testObject = monitor.registerRequest();
@@ -155,7 +158,8 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                }
        }
 
-       CachedRowSet executePreparedStatement(Connection conn, String statement, ArrayList<Object> arguments, boolean close) throws SQLException, Throwable
+       CachedRowSet executePreparedStatement(Connection conn, String statement,
+                       ArrayList<Object> arguments, boolean close) throws SQLException, Throwable
        {
                long time = System.currentTimeMillis();
 
@@ -168,9 +172,10 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                }
 
                ResultSet rs = null;
+               PreparedStatement ps = null;
                try {
                        data = RowSetProvider.newFactory().createCachedRowSet();
-                       PreparedStatement ps = conn.prepareStatement(statement);
+                       ps = conn.prepareStatement(statement);
                        if(arguments != null)
                        {
                                for(int i = 0, max = arguments.size(); i < max; i++){
@@ -220,6 +225,13 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                                }
                        } catch(Exception exc){
 
+                       }
+                       try {
+                               if (ps != null){
+                                       ps.close();
+                               }
+                       } catch (Exception exc){
+
                        }
                }
 
@@ -296,6 +308,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
        /* (non-Javadoc)
         * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
         */
+       @Override
        public Connection getConnection(String username, String password)
                        throws SQLException
        {
@@ -305,6 +318,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
        /* (non-Javadoc)
         * @see javax.sql.DataSource#getLogWriter()
         */
+       @Override
        public PrintWriter getLogWriter() throws SQLException
        {
                return ds.getLogWriter();
@@ -313,6 +327,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
        /* (non-Javadoc)
         * @see javax.sql.DataSource#getLoginTimeout()
         */
+       @Override
        public int getLoginTimeout() throws SQLException
        {
                return ds.getLoginTimeout();
@@ -321,6 +336,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
        /* (non-Javadoc)
         * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
         */
+       @Override
        public void setLogWriter(PrintWriter out) throws SQLException
        {
                ds.setLogWriter(out);
@@ -329,12 +345,14 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
        /* (non-Javadoc)
         * @see javax.sql.DataSource#setLoginTimeout(int)
         */
+       @Override
        public void setLoginTimeout(int seconds) throws SQLException
        {
                ds.setLoginTimeout(seconds);
        }
 
 
+       @Override
        public final String getDbConnectionName(){
                return connectionName;
        }
@@ -418,10 +436,12 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                return true;
        }
 
+       @Override
        public boolean isWrapperFor(Class<?> iface) throws SQLException {
                return false;
        }
 
+       @Override
        public <T> T unwrap(Class<T> iface) throws SQLException {
                return null;
        }
@@ -445,34 +465,42 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                monitor.deleteObserver(observer);
        }
 
+       @Override
        public long getInterval() {
                return interval;
        }
 
+       @Override
        public long getInitialDelay() {
                return initialDelay;
        }
 
+       @Override
        public void setInterval(long value) {
                interval = value;
        }
 
+       @Override
        public void setInitialDelay(long value) {
                initialDelay = value;
        }
 
+       @Override
        public long getExpectedCompletionTime() {
                return expectedCompletionTime;
        }
 
+       @Override
        public void setExpectedCompletionTime(long value) {
                expectedCompletionTime = value;
        }
 
+       @Override
        public long getUnprocessedFailoverThreshold() {
                return unprocessedFailoverThreshold;
        }
 
+       @Override
        public void setUnprocessedFailoverThreshold(long value) {
                this.unprocessedFailoverThreshold = value;
        }
@@ -485,6 +513,7 @@ public abstract class CachedDataSource implements DataSource, SQLExecutionMonito
                canTakeOffLine = false;
                final Thread offLineTimer = new Thread()
                {
+                       @Override
                        public void run(){
                                try {
                                        Thread.sleep(30000L);