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