Fix checkstyle if-statements must use braces sal-dom-xsql
[controller.git] / opendaylight / md-sal / sal-dom-xsql / src / main / java / org / opendaylight / controller / md / sal / dom / xsql / XSQLBluePrintNode.java
index fbd818e63216c40e6c6cb3a053c214584a5bc248..4a565452388648b14719df92e97ec5e412c3d416 100644 (file)
@@ -3,7 +3,9 @@ package org.opendaylight.controller.md.sal.dom.xsql;
 import java.io.Serializable;
 import java.sql.SQLException;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 public class XSQLBluePrintNode implements Serializable {
@@ -11,10 +13,8 @@ public class XSQLBluePrintNode implements Serializable {
     private static final long serialVersionUID = 1L;
     private Class<?> myInterface = null;
     private String myInterfaceString = null;
-    private Set<XSQLBluePrintRelation> relations =
-        new HashSet<XSQLBluePrintRelation>();
-    private Set<XSQLBluePrintNode> inheritingNodes =
-        new HashSet<XSQLBluePrintNode>();
+    private Set<XSQLBluePrintRelation> relations = new HashSet<XSQLBluePrintRelation>();
+    private Set<XSQLBluePrintNode> inheritingNodes = new HashSet<XSQLBluePrintNode>();
     private Set<XSQLBluePrintNode> children = new HashSet<XSQLBluePrintNode>();
     private XSQLBluePrintNode parent = null;
 
@@ -22,11 +22,20 @@ public class XSQLBluePrintNode implements Serializable {
     private transient Set<String> parentHierarchySet = null;
     private String myInterfaceName = null;
     private Set<XSQLColumn> columns = new HashSet<XSQLColumn>();
+    private Map<String, XSQLColumn> origNameToColumn = new HashMap<String, XSQLColumn>();
 
     private transient Object odlNode = null;
     private boolean module = false;
     private String bluePrintTableName = null;
     private String odlTableName = null;
+    private String origName = null;
+
+    public XSQLBluePrintNode(String name, String _origName, int _level) {
+        this.level = _level;
+        this.odlTableName = name;
+        this.bluePrintTableName = name;
+        this.origName = _origName;
+    }
 
     public XSQLBluePrintNode(Class<?> _myInterface, int _level) {
         this.myInterface = _myInterface;
@@ -35,16 +44,21 @@ public class XSQLBluePrintNode implements Serializable {
         this.level = _level;
     }
 
-    public XSQLBluePrintNode(Object _odlNode, int _level,XSQLBluePrintNode _parent) {
+    public XSQLBluePrintNode(Object _odlNode, int _level,
+            XSQLBluePrintNode _parent) {
         this.odlNode = _odlNode;
         this.level = _level;
         this.module = XSQLODLUtils.isModule(_odlNode);
         this.parent = _parent;
         this.bluePrintTableName = XSQLODLUtils.getBluePrintName(_odlNode);
+        this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode);
+    }
 
+    public String getOrigName() {
+        return this.origName;
     }
 
-    public String getBluePrintNodeName(){
+    public String getBluePrintNodeName() {
         return this.bluePrintTableName;
     }
 
@@ -71,7 +85,7 @@ public class XSQLBluePrintNode implements Serializable {
         this.children.add(ch);
     }
 
-    public boolean isModelChild(Class p) {
+    public boolean isModelChild(Class<?> p) {
         if (this.relations.size() == 0) {
             return false;
         }
@@ -82,10 +96,11 @@ public class XSQLBluePrintNode implements Serializable {
         }
         for (XSQLBluePrintRelation dtr : this.relations) {
             XSQLBluePrintNode parent = dtr.getParent();
-            if (!parent.getInterface().equals(this.getInterface()) && !parent
-                .getInterface().isAssignableFrom(this.getInterface()) &&
-                this.getInterface().isAssignableFrom(parent.getInterface())
-                && parent.isModelChild(p)) {
+            if (!parent.getInterface().equals(this.getInterface())
+                    && !parent.getInterface().isAssignableFrom(
+                            this.getInterface())
+                    && this.getInterface().isAssignableFrom(
+                            parent.getInterface()) && parent.isModelChild(p)) {
                 return true;
             }
         }
@@ -109,8 +124,16 @@ public class XSQLBluePrintNode implements Serializable {
     }
 
     public void addColumn(Object node, String tableName) {
-        XSQLColumn c = new XSQLColumn(node,getBluePrintNodeName(), this);
+        XSQLColumn c = new XSQLColumn(node, getBluePrintNodeName(), this);
+        this.columns.add(c);
+    }
+
+    public XSQLColumn addColumn(String name, String tableName, String origName,
+            String origTableName) {
+        XSQLColumn c = new XSQLColumn(name, tableName, origName, origTableName);
         this.columns.add(c);
+        this.origNameToColumn.put(origName, c);
+        return c;
     }
 
     public void addColumn(String methodName) {
@@ -165,17 +188,16 @@ public class XSQLBluePrintNode implements Serializable {
         throw new SQLException("Unknown field name '" + name + "'");
     }
 
-
     public void addParent(XSQLBluePrintNode parent, String property) {
         try {
             if (property.equals("ContainingTPs")) {
                 return;
             }
-            //Method m = parent.getInterface().getMethod("get"+property, null);
-            //if(!m.getDeclaringClass().equals(parent.getInterface()))
-            //return;
-            XSQLBluePrintRelation rel =
-                new XSQLBluePrintRelation(parent, property, myInterface);
+            // Method m = parent.getInterface().getMethod("get"+property, null);
+            // if(!m.getDeclaringClass().equals(parent.getInterface()))
+            // return;
+            XSQLBluePrintRelation rel = new XSQLBluePrintRelation(parent,
+                    property, myInterface);
             relations.add(rel);
         } catch (Exception err) {
             err.printStackTrace();
@@ -187,8 +209,7 @@ public class XSQLBluePrintNode implements Serializable {
     }
 
     public Set<XSQLBluePrintRelation> getClonedParents() {
-        Set<XSQLBluePrintRelation> result =
-            new HashSet<XSQLBluePrintRelation>();
+        Set<XSQLBluePrintRelation> result = new HashSet<XSQLBluePrintRelation>();
         result.addAll(this.relations);
         return result;
     }
@@ -200,10 +221,13 @@ public class XSQLBluePrintNode implements Serializable {
         if (odlNode != null) {
             return getBluePrintNodeName();
         }
+        if (odlTableName != null) {
+            return odlTableName;
+        }
         return "Unknown";
     }
 
-    public Class getInterface() {
+    public Class<?> getInterface() {
         return this.myInterface;
     }
 
@@ -216,10 +240,14 @@ public class XSQLBluePrintNode implements Serializable {
         XSQLBluePrintNode other = (XSQLBluePrintNode) obj;
         if (odlNode != null) {
             return getBluePrintNodeName().equals(other.getBluePrintNodeName());
-        } else if (this.odlTableName != null) {
+        } else if (this.odlTableName == null && other.odlTableName != null) {
+            return false;
+        }
+        if (this.odlTableName != null && other.odlTableName == null) {
+            return false;
+        }
+        else {
             return this.odlTableName.equals(other.odlTableName);
-        } else {
-            return other.myInterface.equals(myInterface);
         }
     }