Merge "Fixed for bug : 1171 - issue while creating subnet"
[controller.git] / opendaylight / md-sal / sal-dom-xsql / src / main / java / org / opendaylight / controller / md / sal / dom / xsql / XSQLColumn.java
1 package org.opendaylight.controller.md.sal.dom.xsql;
2
3 import java.io.Serializable;
4
5 public class XSQLColumn implements Serializable, Comparable {
6     private String name = null;
7     private String tableName = null;
8     private int charWidth = -1;
9     private Class type = null;
10     private transient Object bluePrintNode = null;
11
12     public XSQLColumn(Object odlNode, String _tableName, Object _bluePrintNode) {
13         this.name = XSQLODLUtils.getNodeNameFromDSN(odlNode);
14         this.tableName = _tableName;
15         this.bluePrintNode = _bluePrintNode;
16         this.type = XSQLODLUtils.getTypeForODLColumn(odlNode);
17     }
18
19     public String getName() {
20         return name;
21     }
22
23     public String getTableName() {
24         return tableName;
25     }
26
27     public void setCharWidth(int i) {
28         if (this.charWidth < i) {
29             this.charWidth = i;
30         }
31     }
32
33     public int getCharWidth() {
34         return this.charWidth;
35     }
36
37     @Override
38     public int hashCode() {
39         return this.name.hashCode() + this.tableName.hashCode();
40     }
41
42     @Override
43     public boolean equals(Object obj) {
44         if (!(obj instanceof XSQLColumn)) {
45             return false;
46         }
47         XSQLColumn other = (XSQLColumn) obj;
48         return tableName.equals(other.tableName) && name.equals(other.name);
49     }
50
51     public Object getBluePrintNode() {
52         return this.bluePrintNode;
53     }
54
55     @Override
56     public String toString() {
57         return tableName + "." + name;
58     }
59
60     @Override
61     public int compareTo(Object o) {
62         return this.toString().compareTo(o.toString());
63     }
64
65     public Object getResultSetValue(Object obj){
66         if(this.type.equals(String.class)){
67             return obj.toString();
68         }else
69         if(this.type.equals(int.class)){
70             return Integer.parseInt(obj.toString());
71         }else
72         if(this.type.equals(long.class)){
73             return Long.parseLong(obj.toString());
74         }else
75         if(this.type.equals(byte.class)){
76             return Byte.parseByte(obj.toString());
77         }
78         return null;
79     }
80 }