Merge "Fix raw references to Promise"
[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     private String origName = null;
12     private String origTableName = null;
13
14     public XSQLColumn(Object odlNode, String _tableName, Object _bluePrintNode) {
15         this.name = XSQLODLUtils.getNodeNameFromDSN(odlNode);
16         this.tableName = _tableName;
17         this.bluePrintNode = _bluePrintNode;
18         this.type = XSQLODLUtils.getTypeForODLColumn(odlNode);
19     }
20
21     public XSQLColumn(String _name, String _tableName,String _origName, String _origTableName){
22         this.name = _name;
23         this.tableName = _tableName;
24         this.origName = _origName;
25         this.origTableName = _origTableName;
26     }
27
28     public String getName() {
29         return name;
30     }
31
32     public String getTableName() {
33         return tableName;
34     }
35
36     public void setCharWidth(int i) {
37         if (this.charWidth < i) {
38             this.charWidth = i;
39         }
40     }
41
42     public int getCharWidth() {
43         return this.charWidth;
44     }
45
46     @Override
47     public int hashCode() {
48         return this.name.hashCode() + this.tableName.hashCode();
49     }
50
51     @Override
52     public boolean equals(Object obj) {
53         if (!(obj instanceof XSQLColumn)) {
54             return false;
55         }
56         XSQLColumn other = (XSQLColumn) obj;
57         return tableName.equals(other.tableName) && name.equals(other.name);
58     }
59
60     public Object getBluePrintNode() {
61         return this.bluePrintNode;
62     }
63
64     @Override
65     public String toString() {
66         return tableName + "." + name;
67     }
68
69     @Override
70     public int compareTo(Object o) {
71         return this.toString().compareTo(o.toString());
72     }
73
74     public Object getResultSetValue(Object obj){
75         if(this.type.equals(String.class)){
76             return obj.toString();
77         }else
78         if(this.type.equals(int.class)){
79             return Integer.parseInt(obj.toString());
80         }else
81         if(this.type.equals(long.class)){
82             return Long.parseLong(obj.toString());
83         }else
84         if(this.type.equals(byte.class)){
85             return Byte.parseByte(obj.toString());
86         }
87         return null;
88     }
89 }