From 66221823c8cb131b8cea03c4d011ddd728608451 Mon Sep 17 00:00:00 2001 From: "Magnusen, Drew (dm741q)" Date: Fri, 4 Aug 2017 12:51:14 -0500 Subject: [POLICY-96] Resolved sonar blockers in im/ia. Resolved 7 sonar blockers in the integrity monitor and integrity audit projects. Change-Id: I7bba7619d3b71f7aebcc2642d07a64876ee7aea0 Signed-off-by: Magnusen, Drew (dm741q) --- .../main/java/org/onap/policy/common/ia/DbDAO.java | 52 ++++++++++++++++------ 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'integrity-audit/src/main/java') diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java index 64c01931..0db43bbc 100644 --- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java +++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDAO.java @@ -709,21 +709,45 @@ public class DbDAO { * two or three milliseconds) */ } catch (LockTimeoutException e) { - em.getTransaction().rollback(); - String msg = "DbDAO: " + "changeDesignated() " - + "caught LockTimeoutException, message=" + e.getMessage(); - logger.error(msg + e); - System.out.println(new Date()); - e.printStackTrace(); - throw new DbDaoTransactionException(msg, e); + if (em != null) { + em.getTransaction().rollback(); + + String msg = "DbDAO: " + "changeDesignated() " + + "caught LockTimeoutException, message=" + e.getMessage(); + logger.error(msg + e); + System.out.println(new Date()); + e.printStackTrace(); + throw new DbDaoTransactionException(msg, e); + } + else { + String msg = "DbDAO: " + "changeDesignated() " + + "caught LockTimeoutException, message=" + e.getMessage() + + ". Error rolling back transaction."; + logger.error(msg + e); + System.out.println(new Date()); + e.printStackTrace(); + throw new DbDaoTransactionException(msg, e); + } } catch (Exception e) { - em.getTransaction().rollback(); - String msg = "DbDAO: " + "changeDesignated() " - + "caught Exception, message=" + e.getMessage(); - logger.error(msg + e); - System.out.println(new Date()); - e.printStackTrace(); - throw new DbDaoTransactionException(msg, e); + if (em != null) { + em.getTransaction().rollback(); + + String msg = "DbDAO: " + "changeDesignated() " + + "caught Exception, message=" + e.getMessage(); + logger.error(msg + e); + System.out.println(new Date()); + e.printStackTrace(); + throw new DbDaoTransactionException(msg, e); + } + else { + String msg = "DbDAO: " + "changeDesignated() " + + "caught LockTimeoutException, message=" + e.getMessage() + + ". Error rolling back transaction."; + logger.error(msg + e); + System.out.println(new Date()); + e.printStackTrace(); + throw new DbDaoTransactionException(msg, e); + } } } // end synchronized block -- cgit 1.2.3-korg