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 COM.FutureTense.Interfaces.FTValList;
20 import COM.FutureTense.Interfaces.ICS;
21 import tools.gsf.runtime.CSRuntimeException;
22
23
24
25
26
27
28
29 public class TableCreator {
30
31 private final ICS ics;
32
33 public TableCreator(final ICS ics) {
34 super();
35 this.ics = ics;
36 }
37
38
39
40
41
42
43 public void delteTable(String name) {
44 ics.ClearErrno();
45 final FTValList list = new FTValList();
46
47 list.setValString("ftcmd", "deletetable");
48 list.setValString("tablename", name);
49 if (!ics.CatalogManager(list)) {
50 throw new CSRuntimeException("Error deleting table " + name, ics.GetErrno());
51 }
52
53 }
54
55
56
57
58
59
60 public void createTable(TableDef table) {
61 ics.ClearErrno();
62 final FTValList list = new FTValList();
63
64 list.setValString("ftcmd", "createtable");
65 list.setValString("tablename", table.getName());
66 list.setValString("systable", table.getType());
67 list.setValString("aclList", table.getAcl());
68 int i = 0;
69 for (TableColumn col : table.getColumns()) {
70
71 list.setValString("colname" + i, col.getName());
72 StringBuilder val = new StringBuilder();
73 val.append(ics.GetProperty(col.getType().getProperty()));
74 switch (col.getType()) {
75 case ccdouble:
76 case ccchar:
77 case ccnumeric:
78 case ccvarchar:
79 case ccdatetime:
80 if (col.getLength() > 0) {
81 val.append(" (");
82 val.append(Integer.toString(col.getLength()));
83 switch (col.getType()) {
84 case ccdouble:
85 val.append(",").append(Integer.toString(col.getDecimal()));
86 break;
87 default:
88 break;
89 }
90
91 val.append(")");
92 }
93 break;
94 default:
95 break;
96
97 }
98 if (col.isPrimary()) {
99 val.append(" ");
100 val.append(ics.GetProperty("cc.primary"));
101 } else if (col.isNullable()) {
102 val.append(" ");
103 val.append(ics.GetProperty("cc.null"));
104 } else {
105 val.append(" NOT NULL");
106 }
107
108 list.setValString("colvalue" + i, val.toString());
109 i++;
110 }
111
112 if (!ics.CatalogManager(list)) {
113 throw new CSRuntimeException("Error creating table " + table.getName(), ics.GetErrno());
114 }
115
116 }
117
118 }