From 9eb50a48faf45d5f1dc01b1209778c1c1d5ed0ae Mon Sep 17 00:00:00 2001 From: surya-huawei Date: Mon, 11 Sep 2017 16:36:49 +0530 Subject: Fix Sonar issues Few major issues in sli/core module Issue-id: CCSDK-67 Change-Id: Iad65b30a6b27814c1984d8db42d36f8569c5cb3f Signed-off-by: surya-huawei --- .../ccsdk/sli/core/dblib/CachedDataSource.java | 37 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'dblib') diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java index 1729bcec..ee8ab2f3 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java @@ -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 arguments) throws SQLException, Throwable + public CachedRowSet getData(String statement, ArrayList 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 arguments) throws SQLException, Throwable + public boolean writeData(String statement, ArrayList 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 arguments, boolean close) throws SQLException, Throwable + CachedRowSet executePreparedStatement(Connection conn, String statement, + ArrayList 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 unwrap(Class 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); -- cgit 1.2.3-korg