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;h=d3cd91a6bd656bb5d92078092d9544bb4ae19eb6;hp=fbd818e63216c40e6c6cb3a053c214584a5bc248;hb=2727bea09c83646b6cbd2ef9672d0b7f6cf3b22f;hpb=ff2f98614e20366d532439b73d9a51470210ae61 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 index fbd818e632..d3cd91a6bd 100644 --- 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 @@ -1,20 +1,30 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ 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; +/** + * @author Sharon Aicler(saichler@gmail.com) + **/ 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 relations = new HashSet(); + private Set inheritingNodes = new HashSet(); private Set children = new HashSet(); private XSQLBluePrintNode parent = null; @@ -22,11 +32,33 @@ public class XSQLBluePrintNode implements Serializable { private transient Set parentHierarchySet = null; private String myInterfaceName = null; private Set columns = new HashSet(); + private Map origNameToColumn = new HashMap(); - private transient Object odlNode = null; + private transient Object[] odlSchemaNodes = null; private boolean module = false; private String bluePrintTableName = null; private String odlTableName = null; + private String origName = null; + + public void mergeAugmentation(XSQLBluePrintNode aug) { + this.relations.addAll(aug.relations); + this.inheritingNodes.addAll(aug.inheritingNodes); + this.children.addAll(aug.children); + this.columns.addAll(aug.columns); + this.origNameToColumn.putAll(aug.origNameToColumn); + if (aug.odlSchemaNodes != null) { + for (Object sn : aug.odlSchemaNodes) { + addToSchemaNodes(sn); + } + } + } + + 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 +67,41 @@ public class XSQLBluePrintNode implements Serializable { this.level = _level; } - public XSQLBluePrintNode(Object _odlNode, int _level,XSQLBluePrintNode _parent) { - this.odlNode = _odlNode; + public XSQLBluePrintNode(Object _odlNode, int _level, + XSQLBluePrintNode _parent) { + addToSchemaNodes(_odlNode); this.level = _level; this.module = XSQLODLUtils.isModule(_odlNode); this.parent = _parent; this.bluePrintTableName = XSQLODLUtils.getBluePrintName(_odlNode); + this.odlTableName = XSQLODLUtils + .getODLNodeName(getFirstFromSchemaNodes()); + } + + private void addToSchemaNodes(Object schemaObject) { + if (this.odlSchemaNodes == null) + this.odlSchemaNodes = new Object[1]; + else { + Object[] temp = new Object[this.odlSchemaNodes.length + 1]; + System.arraycopy(this.odlSchemaNodes, 0, temp, 0, + this.odlSchemaNodes.length); + this.odlSchemaNodes = temp; + } + this.odlSchemaNodes[this.odlSchemaNodes.length - 1] = schemaObject; + } + + public Object getFirstFromSchemaNodes() { + if (this.odlSchemaNodes == null) { + return null; + } + return this.odlSchemaNodes[0]; + } + public String getOrigName() { + return this.origName; } - public String getBluePrintNodeName(){ + public String getBluePrintNodeName() { return this.bluePrintTableName; } @@ -58,20 +115,17 @@ public class XSQLBluePrintNode implements Serializable { public String getODLTableName() { if (this.odlTableName == null) { - this.odlTableName = XSQLODLUtils.getODLNodeName(this.odlNode); + this.odlTableName = XSQLODLUtils + .getODLNodeName(getFirstFromSchemaNodes()); } return this.odlTableName; } - public Object getODLNode() { - return this.odlNode; - } - - public void AddChild(XSQLBluePrintNode ch) { + public void addChild(XSQLBluePrintNode ch) { this.children.add(ch); } - public boolean isModelChild(Class p) { + public boolean isModelChild(Class p) { if (this.relations.size() == 0) { return false; } @@ -82,10 +136,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 +164,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 +228,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 +249,7 @@ public class XSQLBluePrintNode implements Serializable { } public Set getClonedParents() { - Set result = - new HashSet(); + Set result = new HashSet(); result.addAll(this.relations); return result; } @@ -197,13 +258,16 @@ public class XSQLBluePrintNode implements Serializable { if (myInterfaceName != null) { return myInterfaceName; } - if (odlNode != null) { + if (this.odlSchemaNodes != null) { return getBluePrintNodeName(); } + if (odlTableName != null) { + return odlTableName; + } return "Unknown"; } - public Class getInterface() { + public Class getInterface() { return this.myInterface; } @@ -214,12 +278,15 @@ public class XSQLBluePrintNode implements Serializable { @Override public boolean equals(Object obj) { XSQLBluePrintNode other = (XSQLBluePrintNode) obj; - if (odlNode != null) { + if (this.odlSchemaNodes != null) { return getBluePrintNodeName().equals(other.getBluePrintNodeName()); - } else if (this.odlTableName != null) { - return this.odlTableName.equals(other.odlTableName); + } else if (this.odlTableName == null && other.odlTableName != null) { + return false; + } + if (this.odlTableName != null && other.odlTableName == null) { + return false; } else { - return other.myInterface.equals(myInterface); + return this.odlTableName.equals(other.odlTableName); } } @@ -227,7 +294,7 @@ public class XSQLBluePrintNode implements Serializable { public int hashCode() { if (myInterfaceString != null) { return myInterfaceString.hashCode(); - } else if (odlNode != null) { + } else if (this.odlSchemaNodes != null) { return bluePrintTableName.hashCode(); } return 0;