summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-analytics
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-analytics')
-rw-r--r--ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/DbUtils.java63
1 files changed, 28 insertions, 35 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/DbUtils.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/DbUtils.java
index 1ce53c71..e179d388 100644
--- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/DbUtils.java
+++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/system/DbUtils.java
@@ -66,17 +66,18 @@ public class DbUtils {
public static Connection getConnection() throws ReportSQLException {
try {
- return AppUtils.getDatasource().getConnection();
+ return AppUtils.getDatasource().getConnection();
} catch(SQLException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
return null;
} // getConnection
public static void clearConnection(Connection con) throws ReportSQLException {
try {
- if ((con != null) && !con.isClosed())
- Globals.getDbUtils().clearConnection(con);
+ if ((con != null) && !con.isClosed()) {
+ Globals.getDbUtils().clearConnection(con);
+ }
} catch (SQLException ex) {
throw new ReportSQLException(ex.getMessage(), ex.getCause());
} catch (Exception ex2 ) {
@@ -123,16 +124,16 @@ public class DbUtils {
String result = null;
try {
- if(con.isClosed()) con = getConnection();
+ if(con.isClosed()) con = getConnection();
logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL Call] " + sql));
- CallableStatement stmt = con.prepareCall(sql);
- if (expectResult)
- stmt.registerOutParameter(1, Types.CHAR);
- stmt.executeUpdate();
- if (expectResult)
- result = stmt.getString(1);
- stmt.close();
- con.commit();
+ try(CallableStatement stmt = con.prepareCall(sql)){
+ if (expectResult)
+ stmt.registerOutParameter(1, Types.CHAR);
+ stmt.executeUpdate();
+ if (expectResult)
+ result = stmt.getString(1);
+ con.commit();
+ }
} catch (SQLException e) {
throw new ReportSQLException(e.getMessage(), sql);
} finally {
@@ -152,20 +153,18 @@ public class DbUtils {
} // executeCall
public static int executeUpdate(Connection con, String sql) throws ReportSQLException {
- int rcode = -1;
- try {
- Statement stmt = con.createStatement();
+ int rcode = -1;
+ try(Statement stmt = con.createStatement()) {
logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL Update] " + sql));
rcode = stmt.executeUpdate(sql);
- stmt.close();
- //con.commit();
+ //con.commit();
} catch (SQLException e) {
//e.printStackTrace();
throw new ReportSQLException(e.getMessage(), sql);
- }
- return rcode;
+ }
+ return rcode;
} // executeUpdate
-
+
public static int executeUpdate(String sql) throws ReportSQLException {
Connection con = null;
try {
@@ -189,23 +188,17 @@ public class DbUtils {
public static DataSet executeQuery(Connection con, String sql, int maxRowLimit)
throws ReportSQLException {
try {
- if(con.isClosed()) con = getConnection();
+ if(con.isClosed()) con = getConnection();
//con.
- Statement stmt = con.createStatement();
-
- logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL] " + sql));
- ResultSet rs = stmt.executeQuery(sql);
- DataSet ds = new DataSet(rs, maxRowLimit);
-
- if(rs!=null)
- rs.close();
- if(stmt!=null)
- stmt.close();
-
- return ds;
+ try(Statement stmt = con.createStatement();
+ ResultSet rs = stmt.executeQuery(sql))
+ {
+ logger.debug(EELFLoggerDelegate.debugLogger, ("[SQL CALL FROM RAPTOR] [SQL] " + sql));
+ return new DataSet(rs, maxRowLimit);
+ }
} catch (SQLException e) {
throw new ReportSQLException(e.getMessage(), sql);
- }
+ }
} // executeQuery
public static DataSet executeQuery(String sql) throws ReportSQLException {