1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.jaggenerator;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23 import java.io.Serializable;
24
25 /***
26 *
27 * @author hillebrand
28 */
29 public class Column implements Serializable {
30 static Log log = LogFactory.getLog(Column.class);
31 /*** Holds value of property name. */
32 private String name;
33
34 /*** Holds value of property sqlType. */
35 private String sqlType;
36
37 /*** Holds value of property precision. */
38 private int precision;
39
40 /*** Holds value of property scale. */
41 private int scale;
42
43 /*** Holds value of property length. */
44 private int length;
45
46 /*** Set to true if columns is primary key column. */
47 private boolean primaryKey;
48
49 /*** True if the column may be null. */
50 private boolean nullable;
51
52
53 /*** Creates a new instance of Column */
54 public Column() {
55 }
56
57
58 /*** Getter for property name.
59 * @return Value of property name.
60 *
61 */
62 public String getName() {
63 return this.name;
64 }
65
66
67 /*** Setter for property name.
68 * @param name New value of property name.
69 *
70 */
71 public void setName(String name) {
72 this.name = name;
73 }
74
75
76 /*** Setter for property sqlType.
77 * @param sqlType New value of property sqlType.
78 *
79 */
80 public void setSqlType(String sqlType) {
81
82
83 if (sqlType != null) {
84 int index = sqlType.indexOf("(");
85 if (index != -1) {
86 this.sqlType = sqlType.substring(0, index);
87
88 int index2 = sqlType.indexOf(")");
89 if (index2 != -1) {
90
91 int index3 = sqlType.indexOf(",");
92 if (index3 != -1) {
93
94 String scale = sqlType.substring(index + 1, index3).trim();
95 String precision = sqlType.substring(index3 + 1, index2).trim();
96 int sc = 0;
97 int pr = 0;
98 try {
99 sc = Integer.parseInt(scale);
100 pr = Integer.parseInt(precision);
101 } catch (Exception e) {
102 log.warn("Error while parsing scale or precision for type " + sqlType);
103 }
104 setScale(sc);
105 setPrecision(pr);
106 } else {
107
108 String scale = sqlType.substring(index + 1, index2).trim();
109 int sc = 0;
110 try {
111 sc = Integer.parseInt(scale);
112 } catch (Exception e) {
113 log.warn("Error while parsing scale for type " + sqlType);
114 }
115 setScale(sc);
116
117 }
118 }
119 } else {
120 this.sqlType = sqlType;
121 }
122
123 }
124 }
125
126
127 /*** Getter for property precision.
128 * @return Value of property precision.
129 *
130 */
131 public int getPrecision() {
132 return this.precision;
133 }
134
135
136 /*** Setter for property precision.
137 * @param precision New value of property precision.
138 *
139 */
140 public void setPrecision(int precision) {
141 this.precision = precision;
142 }
143
144
145 /*** Getter for property scale.
146 * @return Value of property scale.
147 *
148 */
149 public int getScale() {
150 return this.scale;
151 }
152
153
154 /*** Setter for property scale.
155 * @param scale New value of property scale.
156 *
157 */
158 public void setScale(int scale) {
159 this.scale = scale;
160 }
161
162
163 /*** Getter for property length.
164 * @return Value of property length.
165 *
166 */
167 public int getLength() {
168 return this.length;
169 }
170
171
172 /*** Setter for property length.
173 * @param length New value of property length.
174 *
175 */
176 public void setLength(int length) {
177 this.length = length;
178 }
179
180
181 /*** Getter for property sqlType.
182 * @return Value of property sqlType.
183 *
184 */
185 public String getSqlType() {
186 return this.sqlType;
187 }
188
189
190 /*** Getter for property primary Key
191 * @return Value of primary key.
192 *
193 */
194 public boolean isPrimaryKey() {
195 return this.primaryKey;
196 }
197
198
199 /*** Setter for the primary key.
200 * @param value to true if column is a primary key column
201 *
202 */
203 public void setPrimaryKey(boolean value) {
204 this.primaryKey = value;
205 }
206
207 /***
208 * Gets the 'nullableString' property as a boolean.
209 *
210 * @return the boolean interpretation of the 'nullableString' property.
211 */
212 public boolean isNullable() {
213 return nullable;
214 }
215
216 /***
217 * Sets the 'nullable' property with a value from a database columns dumo.
218 * @param nullable set to <code>true</code> if the column is nullable.
219 */
220 public void setNullable(boolean nullable) {
221 this.nullable = nullable;
222 }
223
224 /*** @see {@link java.lang.Object#toString()}. */
225 public String toString() {
226 return "Column(name=" + name + ", sqlType=" + sqlType + ", precision=" + precision +
227 ", scale=" + scale + ", length=" + length + ", primaryKey=" + primaryKey + ", nullable=" + nullable + ")";
228 }
229
230
231 }