1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package tools.gsf.facade.sql.table;
18
19 import tools.gsf.facade.sql.table.TableColumn.Type;
20
21 import java.util.Collections;
22 import java.util.LinkedList;
23 import java.util.List;
24
25
26
27
28
29
30
31 public class TableDef {
32 private final String name;
33
34 private final String acl;
35
36 private final String type;
37
38 private final List<TableColumn> columns = new LinkedList<TableColumn>();
39
40
41
42
43
44
45 public TableDef(final String name, final String acl, final String type) {
46 super();
47 this.name = name;
48 this.acl = acl;
49 this.type = type;
50 }
51
52
53
54
55
56 public TableDef addColumn(TableColumn col) {
57 if (col.isPrimary()) {
58 for (TableColumn current : columns) {
59 if (current.isPrimary()) {
60 throw new IllegalStateException("Table has already have a primary column");
61 }
62 }
63 }
64 this.columns.add(col);
65 return this;
66 }
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
96 public TableColumn addColumn(final String name, final Type type) {
97
98 return addColumn(name, type, false);
99 }
100
101 public Iterable<TableColumn> getColumns() {
102 return Collections.unmodifiableCollection(columns);
103 }
104
105
106
107
108 public String getAcl() {
109 return acl;
110 }
111
112
113
114
115 public String getName() {
116 return name;
117 }
118
119
120
121
122 public String getType() {
123 return type;
124 }
125
126 }