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.IOException;
50 import java.io.Writer;
51
52
53
54
55 public class AtomFieldDef extends FieldDef {
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public AtomFieldDef(int lineNo, TableDef table, String name,
70 String type, int displayOrder, Vector<FieldQualifier> qualifiers)
71 throws IllegalityException {
72 super(lineNo, table, name, type, type, displayOrder, qualifiers);
73 table.addImport("org.melati.poem.ValidationPoemException",
74 "persistent");
75 }
76
77
78
79
80
81
82
83
84 protected void generateColRawAccessors(Writer w) throws IOException {
85 super.generateColRawAccessors(w);
86
87 w.write(
88 "\n" +
89 " public Object getRaw(Persistent g)\n" +
90 " throws AccessPoemException {\n" +
91 " return ((" + shortestUnambiguousClassname + ")g).get" + capitalisedName + "();\n" +
92 " }\n" +
93 "\n");
94 w.write(
95 " public void setRaw(Persistent g, Object raw)\n" +
96 " throws AccessPoemException {\n" +
97 " ((" + shortestUnambiguousClassname + ")g).set" + capitalisedName +
98 "((" + rawType + ")raw);\n" +
99 " }\n");
100 }
101
102
103
104
105
106
107 public void generateBaseMethods(Writer w) throws IOException {
108 super.generateBaseMethods(w);
109
110 w.write(
111 "\n /**\n"
112 + " * Retrieves the "
113 + capitalisedName
114 + " value, with locking, for this \n"
115 + " * <code>"
116 + table.nameFromDsd
117 + "</code> <code>Persistent</code>.\n"
118 + ((description != null) ? " * Field description: \n"
119 + DSD.javadocFormat(2, 3, description)
120 : "")
121 + " * \n"
122 + " * Generated by "
123 + "org.melati.poem.prepro.AtomFieldDef"
124 + "#generateBaseMethods \n"
125 + " * @throws AccessPoemException \n"
126 + " * if the current <code>AccessToken</code> \n"
127 + " * does not confer write access rights \n"
128 + " * @return the value of the field <code>"
129 + capitalisedName
130 + "</code> for this \n"
131 + " * <code>"
132 + table.nameFromDsd
133 + "</code> <code>Persistent</code> \n"
134 + " */\n");
135 w.write("\n" +
136 " public " + typeShortName + " get" + capitalisedName + "()\n" +
137 " throws AccessPoemException {\n" +
138 " readLock();\n" +
139 " return get" + capitalisedName + "_unsafe();\n" +
140 " }\n" +
141 "\n");
142
143 w.write(
144 "\n /**\n"
145 + " * Sets the <code>"
146 + capitalisedName
147 + "</code> value, with checking, for this \n"
148 + " * <code>"
149 + table.nameFromDsd
150 + "</code> <code>Persistent</code>.\n"
151 + (description != null ? " * Field description: \n"
152 + DSD.javadocFormat(2, 3, description)
153 : "")
154 + " * \n"
155 + " * Generated by "
156 + "org.melati.poem.prepro.AtomFieldDef"
157 + "#generateBaseMethods \n"
158 + " * @param cooked a validated <code>int</code> \n"
159 + " * @throws AccessPoemException \n"
160 + " * if the current <code>AccessToken</code> \n"
161 + " * does not confer write access rights\n"
162 + " * @throws ValidationPoemException \n"
163 + " * if the value is not valid\n"
164 + " */\n");
165 w.write(
166 " public void set" + capitalisedName + "(" + typeShortName + " cooked)\n" +
167 " throws AccessPoemException, ValidationPoemException {\n" +
168 " _" + tableAccessorMethod + "().get" + capitalisedName + "Column().\n" +
169 " getType().assertValidCooked(cooked);\n" +
170 " writeLock();\n" +
171 " set" + capitalisedName + "_unsafe(cooked);\n" +
172 " }\n");
173 }
174
175
176
177
178
179
180
181
182 public void generateJavaDeclaration(Writer w) throws IOException {
183 w.write(typeShortName + " " + name);
184 }
185
186
187 public String poemTypeJava() {
188 return "new " + typeShortName + "PoemType(" + isNullable() + ")";
189 }
190 }