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