X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FEgressRoute.java;h=e766e7048e59374f29fde840874e86624c61f87f;hb=refs%2Fchanges%2F55%2F87355%2F1;hp=242c1053e54145715cb19c6cf7768f04308d956b;hpb=2db08f1dbee4981422a93d06950226cc749ab08a;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java index 242c1053..e766e704 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java @@ -33,7 +33,8 @@ import java.util.Objects; import java.util.SortedSet; import java.util.TreeSet; -import org.apache.log4j.Logger; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; @@ -44,35 +45,37 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; * @version $Id: EgressRoute.java,v 1.3 2013/12/16 20:30:23 eby Exp $ */ public class EgressRoute extends NodeClass implements Comparable { - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + + private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); + private static final String SQLEXCEPTION = "SQLException: "; private final int subid; private final int nodeid; /** - * Get a set of all Egress Routes in the DB. The set is sorted according to the natural sorting order - * of the routes (based on the subscription ID in each route). + * Get a set of all Egress Routes in the DB. The set is sorted according to the natural sorting order of the routes + * (based on the subscription ID in each route). * * @return the sorted set */ public static SortedSet getAllEgressRoutes() { - SortedSet set = new TreeSet(); + SortedSet set = new TreeSet<>(); try { DB db = new DB(); @SuppressWarnings("resource") Connection conn = db.getConnection(); - try( Statement stmt = conn.createStatement()) { - try(ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES")) { - while (rs.next()) { - int subid = rs.getInt("SUBID"); - int nodeid = rs.getInt("NODEID"); - set.add(new EgressRoute(subid, nodeid)); - } - } - } + try (Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES")) { + while (rs.next()) { + int subid = rs.getInt("SUBID"); + int nodeid = rs.getInt("NODEID"); + set.add(new EgressRoute(subid, nodeid)); + } + } + } db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error("PROV0008 EgressRoute.getAllEgressRoutes: " + e.getMessage(), e); } return set; } @@ -93,7 +96,7 @@ public class EgressRoute extends NodeClass implements Comparable { String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?"; ps = conn.prepareStatement(sql); ps.setInt(1, sub); - try(ResultSet rs = ps.executeQuery()) { + try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { int node = rs.getInt("NODEID"); v = new EgressRoute(sub, node); @@ -102,20 +105,20 @@ public class EgressRoute extends NodeClass implements Comparable { ps.close(); db.release(conn); } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error("PROV0009 EgressRoute.getEgressRoute: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return v; } - public EgressRoute(int subid, int nodeid) throws IllegalArgumentException { + public EgressRoute(int subid, int nodeid) { this.subid = subid; this.nodeid = nodeid; // Note: unlike for Feeds, it subscriptions can be removed from the tables, so it is @@ -124,7 +127,7 @@ public class EgressRoute extends NodeClass implements Comparable { // throw new IllegalArgumentException("No such subscription: "+subid); } - public EgressRoute(int subid, String node) throws IllegalArgumentException { + public EgressRoute(int subid, String node) { this(subid, lookupNodeName(node)); } @@ -139,15 +142,14 @@ public class EgressRoute extends NodeClass implements Comparable { ps.execute(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.error("PROV0007 doDelete: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -167,15 +169,14 @@ public class EgressRoute extends NodeClass implements Comparable { ps.close(); rv = true; } catch (SQLException e) { - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -193,15 +194,14 @@ public class EgressRoute extends NodeClass implements Comparable { ps.executeUpdate(); } catch (SQLException e) { rv = false; - intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - intlogger.error("SQLException " + e.getMessage()); + intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e); } finally { try { - if(ps!=null) { + if (ps != null) { ps.close(); } } catch (SQLException e) { - intlogger.error("SQLException " + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } } return rv; @@ -221,8 +221,9 @@ public class EgressRoute extends NodeClass implements Comparable { @Override public boolean equals(Object obj) { - if (!(obj instanceof EgressRoute)) + if (!(obj instanceof EgressRoute)) { return false; + } EgressRoute on = (EgressRoute) obj; return (subid == on.subid) && (nodeid == on.nodeid); }