X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-xsql%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fxsql%2FXSQLBluePrintNode.java;fp=opendaylight%2Fmd-sal%2Fsal-dom-xsql%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fxsql%2FXSQLBluePrintNode.java;h=fbd818e63216c40e6c6cb3a053c214584a5bc248;hp=0000000000000000000000000000000000000000;hb=800c476b2210456c33e4950cf345144cba02a4cd;hpb=73bda4f755598599f45cc46cd51c652c0a36e532 diff --git a/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java new file mode 100644 index 0000000000..fbd818e632 --- /dev/null +++ b/opendaylight/md-sal/sal-dom-xsql/src/main/java/org/opendaylight/controller/md/sal/dom/xsql/XSQLBluePrintNode.java @@ -0,0 +1,236 @@ +package org.opendaylight.controller.md.sal.dom.xsql; + +import java.io.Serializable; +import java.sql.SQLException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +public class XSQLBluePrintNode implements Serializable { + + private static final long serialVersionUID = 1L; + private Class myInterface = null; + private String myInterfaceString = null; + private Set relations = + new HashSet(); + private Set inheritingNodes = + new HashSet(); + private Set children = new HashSet(); + private XSQLBluePrintNode parent = null; + + private int level = -1; + private transient Set parentHierarchySet = null; + private String myInterfaceName = null; + private Set columns = new HashSet(); + + private transient Object odlNode = null; + private boolean module = false; + private String bluePrintTableName = null; + private String odlTableName = null; + + public XSQLBluePrintNode(Class _myInterface, int _level) { + this.myInterface = _myInterface; + this.myInterfaceString = _myInterface.getName(); + this.myInterfaceName = myInterface.getSimpleName(); + this.level = _level; + } + + 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); + + } + + public String getBluePrintNodeName(){ + return this.bluePrintTableName; + } + + public boolean isModule() { + return this.module; + } + + public Set getChildren() { + return this.children; + } + + public String getODLTableName() { + if (this.odlTableName == null) { + this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode); + } + return this.odlTableName; + } + + public Object getODLNode() { + return this.odlNode; + } + + public void AddChild(XSQLBluePrintNode ch) { + this.children.add(ch); + } + + public boolean isModelChild(Class p) { + if (this.relations.size() == 0) { + return false; + } + for (XSQLBluePrintRelation parentRelation : this.relations) { + if (parentRelation.getParent().getInterface().equals(p)) { + return true; + } + } + 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)) { + return true; + } + } + return false; + } + + public Set getRelations() { + return this.relations; + } + + public String getClassName() { + return this.myInterfaceString; + } + + public void addInheritingNode(XSQLBluePrintNode node) { + this.inheritingNodes.add(node); + } + + public Set getInheritingNodes() { + return this.inheritingNodes; + } + + public void addColumn(Object node, String tableName) { + XSQLColumn c = new XSQLColumn(node,getBluePrintNodeName(), this); + this.columns.add(c); + } + + public void addColumn(String methodName) { + if (methodName.startsWith("get")) { + methodName = methodName.substring(3); + } else if (methodName.startsWith("is")) { + methodName = methodName.substring(2); + } + XSQLColumn c = new XSQLColumn(methodName, myInterfaceName, null); + this.columns.add(c); + } + + public Collection getColumns() { + return this.columns; + } + + public XSQLColumn findColumnByName(String name) throws SQLException { + + XSQLColumn exactMatch = null; + XSQLColumn indexOfMatch = null; + XSQLColumn exactLowercaseMatch = null; + XSQLColumn indexOfLowerCaseMatch = null; + + for (XSQLColumn col : columns) { + if (col.getName().equals(name)) { + exactMatch = col; + } + if (col.getName().indexOf(name) != -1) { + indexOfMatch = col; + } + if (col.getName().toLowerCase().equals(name.toLowerCase())) { + exactLowercaseMatch = col; + } + if (col.getName().toLowerCase().indexOf(name.toLowerCase()) != -1) { + indexOfLowerCaseMatch = col; + } + } + + if (exactMatch != null) { + return exactMatch; + } + if (exactLowercaseMatch != null) { + return exactLowercaseMatch; + } + if (indexOfMatch != null) { + return indexOfMatch; + } + if (indexOfLowerCaseMatch != null) { + return indexOfLowerCaseMatch; + } + + 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); + relations.add(rel); + } catch (Exception err) { + err.printStackTrace(); + } + } + + public XSQLBluePrintNode getParent() { + return this.parent; + } + + public Set getClonedParents() { + Set result = + new HashSet(); + result.addAll(this.relations); + return result; + } + + public String toString() { + if (myInterfaceName != null) { + return myInterfaceName; + } + if (odlNode != null) { + return getBluePrintNodeName(); + } + return "Unknown"; + } + + public Class getInterface() { + return this.myInterface; + } + + public int getLevel() { + return this.level; + } + + @Override + public boolean equals(Object obj) { + XSQLBluePrintNode other = (XSQLBluePrintNode) obj; + if (odlNode != null) { + return getBluePrintNodeName().equals(other.getBluePrintNodeName()); + } else if (this.odlTableName != null) { + return this.odlTableName.equals(other.odlTableName); + } else { + return other.myInterface.equals(myInterface); + } + } + + @Override + public int hashCode() { + if (myInterfaceString != null) { + return myInterfaceString.hashCode(); + } else if (odlNode != null) { + return bluePrintTableName.hashCode(); + } + return 0; + } + +}