1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.sql.table;
18
19 import java.util.Collections;
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import com.fatwire.gst.foundation.facade.sql.table.TableColumn.Type;
24
25
26
27
28
29
30
31
32 public class TableDef {
33 private final String name;
34
35 private final String acl;
36
37 private final String type;
38
39 private final List<TableColumn> columns = new LinkedList<TableColumn>();
40
41
42
43
44
45
46 public TableDef(final String name, final String acl, final String type) {
47 super();
48 this.name = name;
49 this.acl = acl;
50 this.type = type;
51 }
52
53
54
55
56
57 public TableDef addColumn(TableColumn col) {
58 if (col.isPrimary()) {
59 for (TableColumn current : columns) {
60 if (current.isPrimary()) {
61 throw new IllegalStateException("Table has already have a primary column");
62 }
63 }
64 }
65 this.columns.add(col);
66 return this;
67 }
68
69
70
71
72
73
74
75
76 public TableColumn addColumn(final String name, final Type type, final boolean primary) {
77 TableColumn col = new TableColumn(name, type, primary);
78 if (col.isPrimary()) {
79 for (TableColumn current : columns) {
80 if (current.isPrimary()) {
81 throw new IllegalStateException("Table has already have a primary column");
82 }
83 }
84 }
85 this.columns.add(col);
86 return col;
87 }
88
89
90
91
92
93
94
95 public TableColumn addColumn(final String name, final Type type) {
96
97 return addColumn(name, type, false);
98 }
99
100 public Iterable<TableColumn> getColumns() {
101 return Collections.unmodifiableCollection(columns);
102 }
103
104
105
106
107 public String getAcl() {
108 return acl;
109 }
110
111
112
113
114 public String getName() {
115 return name;
116 }
117
118
119
120
121 public String getType() {
122 return type;
123 }
124
125 }