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.prepro;
47
48 import java.util.Vector;
49 import java.io.Writer;
50 import java.io.IOException;
51
52
53
54
55
56
57
58 public class ColumnTypeFieldDef extends FieldDef {
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public ColumnTypeFieldDef(int lineNo, TableDef table, String name, int displayOrder,
73 Vector<FieldQualifier> qualifiers) throws IllegalityException {
74 super(lineNo, table, name, "PoemTypeFactory", "Integer", displayOrder, qualifiers);
75 table.addImport("org.melati.poem.PoemTypeFactory",
76 "persistent");
77 table.addImport("org.melati.poem.PoemTypeFactory",
78 "table");
79 table.addImport("org.melati.poem.ColumnTypePoemType",
80 "table");
81 }
82
83
84
85
86
87
88 protected void generateColRawAccessors(Writer w) throws IOException {
89 super.generateColRawAccessors(w);
90
91 w.write(
92 "\n" +
93 " public Object getRaw(Persistent g)\n" +
94 " throws AccessPoemException {\n" +
95 " return ((" + shortestUnambiguousClassname + ")g).get" + capitalisedName + "Code();\n" +
96 " }\n" +
97 "\n");
98 w.write(
99 " public void setRaw(Persistent g, Object raw)\n" +
100 " throws AccessPoemException {\n" +
101 " ((" + shortestUnambiguousClassname + ")g).set" + capitalisedName + "Code((" +
102 rawType + ")raw);\n" +
103 " }\n");
104 }
105
106
107
108
109
110
111 public void generateBaseMethods(Writer w) throws IOException {
112 super.generateBaseMethods(w);
113
114
115
116
117 w.write(
118 "\n /**\n"
119 + " * Retrieves the <code>"
120 + capitalisedName
121 + "</code> value as an <code>Integer</code> for this "
122 + "<code>Column</code> of the <code>"
123 + table.nameFromDsd
124 + "</code> <code>Table</code>.\n"
125 + ((description != null) ? " * Field description: \n"
126 + DSD.javadocFormat(2, 3, description)
127 + " * \n"
128 : "")
129 + " * \n"
130 + " * Generated by "
131 + "org.melati.poem.prepro.ColumnTypeFieldDef"
132 + "#generateBaseMethods \n"
133 + " * @throws AccessPoemException \n"
134 + " * if the current <code>AccessToken</code> \n"
135 + " * does not confer read access rights\n"
136 + " * @return the <code>" + capitalisedName
137 + "</code> value of this <code>Column</code>\n"
138 + " */\n");
139 w.write("\n" +
140 " public Integer get" + capitalisedName + "Code()\n" +
141 " throws AccessPoemException {\n" +
142 " readLock();\n" +
143 " return get" + capitalisedName + "_unsafe();\n" +
144 " }\n");
145 w.write(
146 "\n /**\n"
147 + " * Sets the <code>Integer</code> <code>"
148 + capitalisedName
149 + "</code> value for this <code>"
150 + table.nameFromDsd
151 + "</code> <code>Column</code> of the <code>"
152 + table.nameFromDsd
153 + "</code> <code>Table</code>.\n"
154 + ((description != null) ? " * Field description: \n"
155 + DSD.javadocFormat(2, 3, description)
156 + " * \n"
157 : "")
158 + " * \n"
159 + " * Generated by "
160 + "org.melati.poem.prepro.ColumnTypeFieldDef"
161 + "#generateBaseMethods \n"
162 + " * @param raw the value to set \n"
163 + " * @throws AccessPoemException \n"
164 + " * if the current <code>AccessToken</code> \n"
165 + " * does not confer write access rights\n"
166 + " */\n");
167 w.write("\n" +
168 " public void set" + capitalisedName + "Code(Integer raw)\n" +
169 " throws AccessPoemException {\n" +
170 " " + rootTableAccessorMethod + "().get" + capitalisedName + "Column()." +
171 "getType().assertValidRaw(raw);\n" +
172 " writeLock();\n" +
173 " set" + capitalisedName + "_unsafe(raw);\n" +
174 " }\n" +
175 "\n");
176 w.write(
177 "\n /**\n"
178 + " * Retrieves the <code>"
179 + capitalisedName
180 + "</code> value as an <code>" + typeShortName + "</code> for this "
181 + "<code>Column</code> of the <code>"
182 + table.nameFromDsd
183 + "</code> <code>Table</code>.\n"
184 + ((description != null) ? " * Field description: \n"
185 + DSD.javadocFormat(2, 3, description)
186 + " * \n"
187 : "")
188 + " * \n"
189 + " * Generated by "
190 + "org.melati.poem.prepro.ColumnTypeFieldDef"
191 + "#generateBaseMethods \n"
192 + " * @throws AccessPoemException \n"
193 + " * if the current <code>AccessToken</code> \n"
194 + " * does not confer read access rights\n"
195 + " * @return the <code>" + capitalisedName
196 + "</code> value of this <code>Column</code>\n"
197 + " */\n");
198 w.write(" public " + typeShortName + " get" + capitalisedName + "()\n" +
199 " throws AccessPoemException {\n" +
200 " Integer code = get" + capitalisedName + "Code();\n" +
201 " return code == null ? null :\n" +
202 " PoemTypeFactory.forCode(getDatabase(), " +
203 "code.intValue());\n" +
204 " }\n" +
205 "\n");
206 w.write(
207 "\n /**\n"
208 + " * Sets the <code>" + typeShortName + "</code> <code>"
209 + capitalisedName
210 + "</code> value for this <code>"
211 + table.nameFromDsd
212 + "</code> <code>Column</code> of the <code>"
213 + table.nameFromDsd
214 + "</code> <code>Table</code>.\n"
215 + ((description != null) ? " * Field description: \n"
216 + DSD.javadocFormat(2, 3, description)
217 + " * \n"
218 : "")
219 + " * \n"
220 + " * Generated by "
221 + "org.melati.poem.prepro.ColumnTypeFieldDef"
222 + "#generateBaseMethods \n"
223 + " * @param cooked the value to set \n"
224 + " * @throws AccessPoemException \n"
225 + " * if the current <code>AccessToken</code> \n"
226 + " * does not confer write access rights\n"
227 + " */\n");
228 w.write(" public void set" + capitalisedName + "(" + typeShortName + " cooked)\n" +
229 " throws AccessPoemException {\n" +
230 " set" + capitalisedName + "Code(cooked == null ? null : " +
231 "cooked.getCode());\n" +
232 " }\n");
233 }
234
235
236
237
238
239
240 public void generateJavaDeclaration(Writer w) throws IOException {
241 w.write("Integer " + name);
242 }
243
244
245 public String poemTypeJava() {
246 return "new ColumnTypePoemType(getDatabase())";
247 }
248 }