1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 package org.melati.poem;
47
48 import java.sql.Date;
49 import java.sql.Timestamp;
50
51
52
53
54
55
56
57
58
59
60
61 public abstract class PoemTypeFactory {
62
63
64
65
66
67
68
69 final Integer code;
70
71
72
73
74
75 public PoemTypeFactory(int c) {
76 this.code = new Integer(c);
77 }
78
79
80
81
82
83 public interface Parameter {
84
85
86
87 boolean getNullable();
88
89
90
91 int getSize();
92 }
93
94 abstract <T>SQLPoemType<T> typeOf(Database database, Parameter info);
95
96
97
98
99 public Integer getCode() {
100 return code;
101 }
102
103
104
105
106 public abstract String getName();
107
108
109
110
111 public String getDisplayName() {
112 return getName();
113 }
114
115
116
117
118 public abstract String getDescription();
119
120
121 public static final PoemTypeFactory TROID;
122
123 public static final PoemTypeFactory DELETED;
124
125 public static final PoemTypeFactory TYPE;
126
127
128
129 public static final PoemTypeFactory BOOLEAN;
130
131 public static final PoemTypeFactory INTEGER;
132
133 public static final PoemTypeFactory DOUBLE;
134
135 public static final PoemTypeFactory LONG;
136
137 public static final PoemTypeFactory BIGDECIMAL;
138
139 public static final PoemTypeFactory STRING;
140
141 public static final PoemTypeFactory PASSWORD;
142
143 public static final PoemTypeFactory DATE;
144
145 public static final PoemTypeFactory TIMESTAMP;
146
147 public static final PoemTypeFactory BINARY;
148
149
150 public static final PoemTypeFactory DISPLAYLEVEL;
151
152 public static final PoemTypeFactory SEARCHABILITY;
153
154 public static final PoemTypeFactory INTEGRITYFIX;
155
156
157 public static final PoemTypeFactory TIME;
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173 private static int n = -1;
174 static final PoemTypeFactory[] atomTypeFactories =
175 {
176 TROID = new PoemTypeFactory(n--) {
177
178
179
180
181
182 @SuppressWarnings("unchecked")
183 public SQLPoemType<?> typeOf(Database database, Parameter info) {
184 return TroidPoemType.it;
185 }
186
187
188
189
190
191 public String getName() {
192 return "TROID";
193 }
194
195
196
197
198 public String getDescription() {
199 return "...";
200 }
201 }, DELETED = new PoemTypeFactory(n--) {
202
203
204
205
206 @SuppressWarnings("unchecked")
207 public SQLPoemType<?> typeOf(Database database, Parameter info) {
208 return DeletedPoemType.it;
209 }
210
211
212
213
214
215 public String getName() {
216 return "DELETED";
217 }
218
219
220
221
222
223 public String getDescription() {
224 return "...";
225 }
226 }, TYPE = new PoemTypeFactory(n--) {
227
228
229
230
231
232 @SuppressWarnings("unchecked")
233 public SQLPoemType<?> typeOf(Database database, Parameter info) {
234 return new ColumnTypePoemType(database);
235 }
236
237
238
239
240
241 public String getName() {
242 return "TYPE";
243 }
244
245
246
247
248
249 public String getDescription() {
250 return "...";
251 }
252 }, BOOLEAN = new PoemTypeFactory(n--) {
253
254
255
256
257
258 @SuppressWarnings("unchecked")
259 public SQLPoemType<?> typeOf(Database database, Parameter info) {
260 return new BooleanPoemType(info.getNullable());
261 }
262
263
264
265
266
267 public String getName() {
268 return "BOOLEAN";
269 }
270
271
272
273
274
275 public String getDescription() {
276 return "...";
277 }
278 }, INTEGER = new PoemTypeFactory(n--) {
279
280
281
282
283
284 @SuppressWarnings("unchecked")
285 public SQLPoemType<?> typeOf(Database database, Parameter info) {
286 return new IntegerPoemType(info.getNullable());
287 }
288
289
290
291
292 public String getName() {
293 return "INTEGER";
294 }
295
296
297
298
299 public String getDescription() {
300 return "...";
301 }
302 }, DOUBLE = new PoemTypeFactory(n--) {
303
304
305
306
307
308 @SuppressWarnings("unchecked")
309 public SQLPoemType<?> typeOf(Database database, Parameter info) {
310 return new DoublePoemType(info.getNullable());
311 }
312
313
314
315
316
317 public String getName() {
318 return "DOUBLE";
319 }
320
321
322
323
324
325 public String getDescription() {
326 return "...";
327 }
328 }, STRING = new PoemTypeFactory(n--) {
329
330
331
332
333
334 @SuppressWarnings("unchecked")
335 public SQLPoemType<?> typeOf(Database database, Parameter info) {
336 return new StringPoemType(info.getNullable(), info.getSize());
337 }
338
339
340
341
342
343 public String getName() {
344 return "STRING";
345 }
346
347
348
349
350
351 public String getDescription() {
352 return "...";
353 }
354 }, DATE = new PoemTypeFactory(n--) {
355
356
357
358
359 @SuppressWarnings("unchecked")
360 public SQLPoemType<Date> typeOf(Database database, Parameter info) {
361 return new DatePoemType(info.getNullable());
362 }
363
364
365
366
367
368 public String getName() {
369 return "DATE";
370 }
371
372
373
374
375
376 public String getDescription() {
377 return "...";
378 }
379 }, PASSWORD = new PoemTypeFactory(n--) {
380
381
382
383
384 @SuppressWarnings("unchecked")
385 public SQLPoemType<?> typeOf(Database database, Parameter info) {
386 return new PasswordPoemType(info.getNullable(), info.getSize());
387 }
388
389
390
391
392 public String getName() {
393 return "PASSWORD";
394 }
395
396
397
398
399
400 public String getDescription() {
401 return "...";
402 }
403 }, TIMESTAMP = new PoemTypeFactory(n--) {
404
405
406
407
408
409 @SuppressWarnings("unchecked")
410 public SQLPoemType<Timestamp> typeOf(Database database, Parameter info) {
411 return new TimestampPoemType(info.getNullable());
412 }
413
414
415
416
417 public String getName() {
418 return "TIMESTAMP";
419 }
420
421
422
423
424
425 public String getDescription() {
426 return "...";
427 }
428 }, DISPLAYLEVEL = new PoemTypeFactory(n--) {
429
430
431
432
433 @SuppressWarnings("unchecked")
434 public SQLPoemType<?> typeOf(Database database, Parameter info) {
435 return new DisplayLevelPoemType();
436 }
437
438
439
440
441
442 public String getName() {
443 return "DISPLAYLEVEL";
444 }
445
446
447
448
449
450 public String getDescription() {
451 return "...";
452 }
453 }, SEARCHABILITY = new PoemTypeFactory(n--) {
454
455
456
457
458
459 @SuppressWarnings("unchecked")
460 public SQLPoemType<?> typeOf(Database database, Parameter info) {
461 return new SearchabilityPoemType();
462 }
463
464
465
466
467
468 public String getName() {
469 return "SEARCHABILITY";
470 }
471
472
473
474
475 public String getDescription() {
476 return "...";
477 }
478 }, BINARY = new PoemTypeFactory(n--) {
479
480
481
482
483 @SuppressWarnings("unchecked")
484 public SQLPoemType<?> typeOf(Database database, Parameter info) {
485 return new BinaryPoemType(info.getNullable(), info.getSize());
486 }
487
488
489
490
491
492 public String getName() {
493 return "BINARY";
494 }
495
496
497
498
499
500 public String getDescription() {
501 return "...";
502 }
503 }, LONG = new PoemTypeFactory(n--) {
504
505
506
507
508
509 @SuppressWarnings("unchecked")
510 public SQLPoemType<?> typeOf(Database database, Parameter info) {
511 return new LongPoemType(info.getNullable());
512 }
513
514
515
516
517
518 public String getName() {
519 return "LONG";
520 }
521
522
523
524
525
526 public String getDescription() {
527 return "...";
528 }
529 }, INTEGRITYFIX = new PoemTypeFactory(n--) {
530
531
532
533
534
535 @SuppressWarnings("unchecked")
536 public SQLPoemType<?> typeOf(Database database, Parameter info) {
537 return new IntegrityFixPoemType(info.getNullable());
538 }
539
540
541
542
543 public String getName() {
544 return "INTEGRITYFIX";
545 }
546
547
548
549
550
551 public String getDescription() {
552 return "...";
553 }
554 }, BIGDECIMAL = new PoemTypeFactory(n--) {
555
556
557
558
559
560 @SuppressWarnings("unchecked")
561 public SQLPoemType<?> typeOf(Database database, Parameter info) {
562 return new BigDecimalPoemType(info.getNullable());
563 }
564
565
566
567
568
569 public String getName() {
570 return "BIGDECIMAL";
571 }
572
573
574
575
576
577 public String getDescription() {
578 return "...";
579 }
580 }, TIME = new PoemTypeFactory(n--) {
581
582
583
584
585
586 @SuppressWarnings("unchecked")
587 public SQLPoemType<?> typeOf(Database database, Parameter info) {
588 return new TimePoemType(info.getNullable());
589 }
590
591
592
593
594
595 public String getName() {
596 return "TIME";
597 }
598
599
600
601
602
603 public String getDescription() {
604 return "...";
605 }
606 },
607
608 };
609
610
611
612
613
614
615
616
617 public static PoemTypeFactory forCode(Database database, int code) {
618 if (code < 0)
619 return atomTypeFactories[(-code) - 1];
620 else {
621 final Table<?> table = database.tableWithTableInfoID(code);
622 return new PoemTypeFactory(code) {
623
624
625
626
627
628 @SuppressWarnings("unchecked")
629 public SQLPoemType<?> typeOf(Database db, Parameter info) {
630 return new ReferencePoemType(table, info.getNullable());
631 }
632
633
634
635
636
637 public String getName() {
638 return table.getName();
639 }
640
641
642
643
644
645 public String getDisplayName() {
646 return table.getDisplayName();
647 }
648
649
650
651
652
653 public String getDescription() {
654 return table.getDescription();
655 }
656 };
657 }
658 }
659 }