1
2 package net.sourceforge.jdbdump.dump;
3
4 import java.io.Serializable;
5
6 /***
7 * Represents a single column of a table in the database, with all its parameters.
8 *
9 * @author jsuder
10 */
11
12 public class Column implements Serializable {
13
14 /*** ID used in serialization process. */
15 private static final long serialVersionUID = 8100923642828414845L;
16
17 /*** The column's name. */
18 private String name;
19
20 /*** Column's type name (e.g. 'varchar', 'timestamp', etc.). */
21 private String type = null;
22
23 /*** Column's length - number of characters for string types, number of digits
24 for decimal types, irrelevant for most other types. */
25 private int length;
26
27 /*** Maximum number of digits after the dot or comma. */
28 private int decimalDigits;
29
30 /*** Can it store null values - according to Java API docs for DatabaseMetaData:
31 * <pre>
32 * - columnNoNulls - might not allow NULL values
33 * - columnNullable - definitely allows NULL values
34 * - columnNullableUnknown - nullability unknown
35 * </pre>
36 */
37 private int nullable;
38
39 /*** Can it store null values - according to Java API docs for DatabaseMetaData:
40 * <pre>
41 * - "NO" means column definitely does not allow NULL values;
42 * - "YES" means the column might allow NULL values.
43 * - An empty string means nobody knows.
44 * </pre>
45 */
46 private String nullable2 = null;
47
48 /*** The default column value, used when no value is given in an insert query. */
49 private String defaultValue = null;
50
51 /*** Some non-standard keywords - e.g. "auto_increment" in MySQL. */
52 private String remarks = null;
53
54 /*** A constraint assigned to this column, if it has one
55 * (e.g. that it is a primary key, etc.). */
56 private Constraint constraint = null;
57
58 /***
59 * Creates a new table column with specified name.
60 * @param name column name
61 */
62
63 public Column(String name) {
64 this.name = name;
65 }
66
67 /***
68 * Returns the column's name.
69 * @return column name
70 */
71
72 public String getName() {
73 return name;
74 }
75
76 /***
77 * Sets the column's name.
78 * @param name new column name
79 */
80
81 public void setName(String name) {
82 this.name = name;
83 }
84
85 /***
86 * Returns the column's type name.
87 * @return column type
88 */
89
90 public String getType() {
91 return type;
92 }
93
94 /***
95 * Sets the column's type.
96 * @param type new column type name
97 */
98
99 public void setType(String type) {
100 this.type = type;
101 }
102
103 /***
104 * Returns the column's length in characters.
105 * @return column length
106 */
107
108 public int getLength() {
109 return length;
110 }
111
112 /***
113 * Sets the column's length in characters.
114 * @param length column length
115 */
116
117 public void setLength(int length) {
118 this.length = length;
119 }
120
121 /***
122 * Returns the number of possible digits after a dot/comma, if the column
123 * stores decimal numbers.
124 * @return number of characters reserved for decimal digits
125 */
126
127 public int getDecimalDigits() {
128 return decimalDigits;
129 }
130
131 /***
132 * Sets the number of column's decimal digits.
133 * @param decimalDigits number of column's decimal digits
134 */
135
136 public void setDecimalDigits(int decimalDigits) {
137 this.decimalDigits = decimalDigits;
138 }
139
140 /***
141 * Tells if NULL values are allowed to be stored in this column. Possible values:
142 * <ul>
143 * <li>DatabaseMetaData.columnNoNulls - might not allow NULL values</li>
144 * <li>DatabaseMetaData.columnNullable - definitely allows NULL values</li>
145 * <li>DatabaseMetaData.columnNullableUnknown - nullability unknown</li>
146 * </ul>
147 * See also: getNullable2().
148 * @return a constant specifying if the field is nullable
149 */
150
151 public int getNullable() {
152 return nullable;
153 }
154
155 /***
156 * Sets the column's nullability (DatabaseMetaData.columnNoNulls,
157 * DatabaseMetaData.columnNullable or DatabaseMetaData.columnNullableUnknown).
158 * @param nullable a constant specifying column's nullability
159 */
160
161 public void setNullable(int nullable) {
162 this.nullable = nullable;
163 }
164
165 /***
166 * Tells if NULL values are allowed to be stored in this column. Possible values:
167 * <ul>
168 * <li>"YES" - the column might allow NULL values</li>
169 * <li>"NO" - means column definitely does not allow NULL values</li>
170 * <li>an empty string - nobody knows</li>
171 * </ul>
172 * See also: getNullable().
173 * @return a string specifying if the field is nullable
174 */
175
176 public String getNullable2() {
177 return nullable2;
178 }
179
180 /***
181 * Sets the column's nullability ("YES", "NO" or "").
182 * @param nullable2 a string specifying column's nullability
183 */
184
185 public void setNullable2(String nullable2) {
186 this.nullable2 = nullable2;
187 }
188
189 /***
190 * Returns the default value used for column's fields if no value is specified.
191 * @return column fields' default value
192 */
193
194 public String getDefault() {
195 return defaultValue;
196 }
197
198 /***
199 * Sets the column's default value.
200 * @param defaultValue column's new default value
201 */
202
203 public void setDefault(String defaultValue) {
204 this.defaultValue = defaultValue;
205 }
206
207 /***
208 * Returns the column's remarks, i.e. some non-standard keywords. For example,
209 * for MySQL it can be "auto_increment".
210 * @return column's remarks
211 */
212
213 public String getRemarks() {
214 return remarks;
215 }
216
217 /***
218 * Sets the column's remarks.
219 * @param name column's new remarks string
220 */
221
222 public void setRemarks(String remarks) {
223 this.remarks = remarks;
224 }
225
226 /***
227 * Assigns a constraint to this table column.
228 * @param a constraint to be set as this column's constraint
229 */
230
231 public void setConstraint(Constraint constraint) {
232 this.constraint = constraint;
233 }
234
235 /***
236 * Returns this column's constraint (e.g. PRIMARY KEY, or CHECK).
237 * @return a constraint assigned to this column
238 */
239
240 public Constraint getConstraint() {
241 return constraint;
242 }
243 }