1
2
3
4
5
6
7 package org.asyrinx.joey.gen.model.rdb;
8
9 import java.util.ArrayList;
10 import java.util.Iterator;
11 import java.util.List;
12
13 import org.asyrinx.brownie.core.lang.NumberUtils;
14 import org.asyrinx.joey.gen.jdbc.JdbcUtils;
15 import org.asyrinx.joey.gen.model.Element;
16
17 /***
18 * @author akima
19 */
20 public class Column extends Element {
21
22 /***
23 */
24 public Column() {
25 this(null, null, null);
26 }
27
28 /***
29 * @param table
30 * @param name
31 * @param type
32 */
33 public Column(Table parent, String name, String type) {
34 super(parent, name);
35 this.type = type;
36 }
37
38 /***
39 * @param table
40 * @param name
41 * @param type
42 * @param size
43 */
44 public Column(Table parent, String name, String type, String size) {
45 this(parent, name, type, size, false, false);
46 }
47
48 /***
49 * @param table
50 * @param name
51 * @param type
52 * @param size
53 * @param required
54 */
55 public Column(Table parent, String name, String type, String size, boolean required) {
56 this(parent, name, type, size, required, false, null);
57 }
58
59 /***
60 * @param table
61 * @param name
62 * @param type
63 * @param size
64 * @param required
65 * @param primaryKey
66 */
67 public Column(Table parent, String name, String type, String size, boolean required, boolean primaryKey) {
68 this(parent, name, type, size, required, primaryKey, null);
69 }
70
71 /***
72 * @param table
73 * @param name
74 * @param type
75 * @param size
76 * @param required
77 * @param primaryKey
78 * @param defaultValue
79 */
80 public Column(Table parent, String name, String type, String size, boolean required, boolean primaryKey,
81 String defaultValue) {
82 super(parent, name);
83 this.type = type;
84 this.size = size;
85 this.required = required;
86 this.primaryKey = primaryKey;
87 this.defaultValue = defaultValue;
88 }
89
90
91
92
93
94
95 public Table getParent() {
96 return (Table) super.getParentElement();
97 }
98
99 private String type = null;
100
101 private String size = null;
102
103 private String decimalSize = null;
104
105 private boolean required = false;
106
107 private boolean primaryKey = false;
108
109 private String defaultValue = null;
110
111 private String enum = null;
112
113 private boolean autoIncrement = false;
114
115 private String idMethod = null;
116
117 private String fk = null;
118
119 private String fkCascade = ForeignKey.CASCADE_NONE;
120
121 private String indexed = null;
122
123 private boolean extended = false;
124
125 private boolean caption = false;
126
127 /***
128 * @return Returns the defaultValue.
129 */
130 public String getDefault() {
131 return getDefaultValue();
132 }
133
134 public int getSizeAsInt() {
135 return NumberUtils.toInt(getSize(), 0);
136 }
137
138 public int getDeciamlSizeAsInt() {
139 return NumberUtils.toInt(getDecimalSize(), 0);
140 }
141
142 /***
143 * @param defaultValue
144 * The defaultValue to set.
145 */
146 public void setDefault(String defaultValue) {
147 this.setDefaultValue(defaultValue);
148 }
149
150 /***
151 * @return Returns the defaultValue.
152 */
153 public String getDefaultValue() {
154 return defaultValue;
155 }
156
157 /***
158 * @param defaultValue
159 * The defaultValue to set.
160 */
161 public void setDefaultValue(String defaultValue) {
162 this.defaultValue = defaultValue;
163 }
164
165 /***
166 * @return Returns the primaryKey.
167 */
168 public boolean isPrimaryKey() {
169 return primaryKey;
170 }
171
172 /***
173 * @param primaryKey
174 * The primaryKey to set.
175 */
176 public void setPrimaryKey(boolean primaryKey) {
177 this.primaryKey = primaryKey;
178 }
179
180 /***
181 * @return Returns the required.
182 */
183 public boolean isRequired() {
184 return required;
185 }
186
187 /***
188 * @param required
189 * The required to set.
190 */
191 public void setRequired(boolean required) {
192 this.required = required;
193 }
194
195 /***
196 * @return Returns the size.
197 */
198 public String getSize() {
199 return size;
200 }
201
202 /***
203 * @param size
204 * The size to set.
205 */
206 public void setSize(String size) {
207 this.size = size;
208 }
209
210 /***
211 * @return Returns the type.
212 */
213 public String getType() {
214 return type;
215 }
216
217 /***
218 * @param type
219 * The type to set.
220 */
221 public void setType(String type) {
222 this.type = type;
223 }
224
225 public int getJdbcType() {
226 return JdbcUtils.toJdbcType(this.getType());
227 }
228
229 /***
230 * @return Returns the enum.
231 */
232 public String getEnum() {
233 return enum;
234 }
235
236 /***
237 * @param enum
238 * The enum to set.
239 */
240 public void setEnum(String enum) {
241 this.enum = enum;
242 }
243
244 public RdbEnumeration getEnumeration() {
245 final Table table = getParent();
246 if (table == null)
247 return null;
248 final Database database = table.getParent();
249 return database.getEnumerations().getEnumeration(getEnum());
250 }
251
252 /***
253 * @return Returns the autoIncrement.
254 */
255 public boolean isAutoIncrement() {
256 return autoIncrement;
257 }
258
259 /***
260 * @param autoIncrement
261 * The autoIncrement to set.
262 */
263 public void setAutoIncrement(boolean autoIncrement) {
264 this.autoIncrement = autoIncrement;
265 }
266
267 /***
268 * @return Returns the idMethod.
269 */
270 public String getIdMethod() {
271 return idMethod;
272 }
273
274 /***
275 * @param idMethod
276 * The idMethod to set.
277 */
278 public void setIdMethod(String idMethod) {
279 this.idMethod = idMethod;
280 }
281
282 /***
283 * @return Returns the fk.
284 */
285 public String getFk() {
286 return fk;
287 }
288
289 /***
290 * @param fk
291 * The fk to set.
292 */
293 public void setFk(String fk) {
294 this.fk = fk;
295 }
296
297 /***
298 * @return Returns the indexed.
299 */
300 public String getIndexed() {
301 return indexed;
302 }
303
304 /***
305 * @param indexed
306 * The indexed to set.
307 */
308 public void setIndexed(String indexed) {
309 this.indexed = indexed;
310 }
311
312 /***
313 * @return Returns the extended.
314 */
315 public boolean isExtended() {
316 return extended;
317 }
318
319 /***
320 * @param extended
321 * The extended to set.
322 */
323 public void setExtended(boolean extended) {
324 this.extended = extended;
325 }
326
327 public List getForeignKeysContainsAsLocal() {
328 final List result = new ArrayList();
329 final Table table = this.getParent();
330 if (table == null)
331 return result;
332 for (Iterator i = table.getForeignKeys().iterator(); i.hasNext();) {
333 final ForeignKey fk = (ForeignKey) i.next();
334 if (fk.containsAsLocal(this))
335 result.add(fk);
336 }
337 return result;
338 }
339
340 public String getDecimalSize() {
341 return decimalSize;
342 }
343
344 public void setDecimalSize(String decimalSize) {
345 this.decimalSize = decimalSize;
346 }
347
348 public boolean isCaption() {
349 return caption;
350 }
351
352 public void setCaption(boolean caption) {
353 this.caption = caption;
354 }
355
356 public String getFkCascade() {
357 return fkCascade;
358 }
359
360 public void setFkCascade(String fkcascade) {
361 this.fkCascade = fkcascade;
362 }
363 }