1 package net.sumaris.core.dao.technical.schema;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import java.sql.DatabaseMetaData;
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.util.Objects;
30 import java.util.StringTokenizer;
31
32
33
34
35 public class SumarisColumnMetadata {
36
37 protected final String catalog;
38 protected final String schema;
39 protected final String table;
40 protected final String name;
41 protected final boolean nullable;
42
43 protected final String defaultValue;
44
45
46 protected final int columnSize;
47 protected final int decimalDigits;
48 protected final int typeCode;
49 protected final String typeName;
50 protected final boolean isNullable;
51 protected final String description;
52
53 public SumarisColumnMetadata(ResultSet rs) throws SQLException {
54 this(rs, null);
55 }
56
57 public SumarisColumnMetadata(ResultSet rs, String defaultValue) throws SQLException {
58 this.defaultValue = defaultValue;
59
60
61
62 this.catalog = rs.getString("TABLE_CAT");
63 this.schema = rs.getString("TABLE_SCHEM");
64 this.table = rs.getString("TABLE_NAME");
65 this.name = rs.getString("COLUMN_NAME");
66 this.nullable = rs.getInt("NULLABLE") == DatabaseMetaData.columnNullable;
67 this.columnSize = rs.getInt("COLUMN_SIZE");
68 this.decimalDigits = rs.getInt("DECIMAL_DIGITS");
69 this.typeCode = rs.getInt("DATA_TYPE");
70 this.isNullable = "YES".equalsIgnoreCase(rs.getString("IS_NULLABLE"));
71 this.typeName = (new StringTokenizer(rs.getString("TYPE_NAME"), "() ")).nextToken();
72 this.description = rs.getString("REMARKS");
73 }
74
75 public int hashCode() {
76 return this.name.hashCode();
77 }
78
79 public String getName() {
80 return this.name;
81 }
82
83 public String getNullable() {
84 return nullable ? "YES": "NO";
85 }
86
87 public boolean isNullable() {
88 return nullable;
89 }
90
91 public String getTypeName() {
92 return typeName;
93 }
94
95 public int getColumnSize() {
96 return columnSize;
97 }
98
99 public int getDecimalDigits() {
100 return decimalDigits;
101 }
102
103 public int getTypeCode() {
104 return typeCode;
105 }
106
107 public String getDefaultValue() {
108 return defaultValue;
109 }
110
111 public String getDescription() {
112 return description;
113 }
114
115
116 public String toString() {
117 return new StringBuilder()
118 .append(catalog).append('.')
119 .append(schema).append('.')
120 .append(table).append('.')
121 .append(name)
122 .toString();
123 }
124
125 public boolean equals(Object other) {
126
127 if (this == other) return true;
128 if ( !(other instanceof SumarisColumnMetadata) ) return false;
129
130 final SumarisColumnMetadata./../net/sumaris/core/dao/technical/schema/SumarisColumnMetadata.html#SumarisColumnMetadata">SumarisColumnMetadata bean = (SumarisColumnMetadata) other;
131
132 if (!Objects.equals(bean.catalog, catalog) ||
133 !Objects.equals(bean.schema, schema) ||
134 !Objects.equals(bean.table, table) ||
135 !Objects.equals(bean.name, name)) return false;
136
137 return true;
138 }
139
140
141 }