1 // Do not edit this file! It was generated by Melati POEM's DSD preprocessor.
2
3 package org.melati.admin.test.generated;
4
5
6 import java.util.Collections;
7 import java.util.Enumeration;
8 import java.util.List;
9 import org.melati.admin.test.AdminTestDatabaseTables;
10 import org.melati.admin.test.Child;
11 import org.melati.admin.test.Parent;
12 import org.melati.admin.test.ParentTable;
13 import org.melati.admin.test.UploadedImage;
14 import org.melati.poem.AccessPoemException;
15 import org.melati.poem.CachedSelection;
16 import org.melati.poem.Column;
17 import org.melati.poem.Field;
18 import org.melati.poem.JdbcPersistent;
19 import org.melati.poem.NoSuchRowPoemException;
20 import org.melati.poem.ValidationPoemException;
21 import org.melati.poem.util.EmptyEnumeration;
22
23
24 /**
25 * Melati POEM generated abstract base class for a <code>Persistent</code>
26 * <code>Parent</code> Object.
27 *
28 * See org.melati.poem.prepro.TableDef#generatePersistentBaseJava
29 */
30 public abstract class ParentBase extends JdbcPersistent {
31
32
33 /**
34 * Retrieves the Database object.
35 *
36 * See org.melati.poem.prepro.TableDef#generatePersistentBaseJava
37 * @return the database
38 */
39 public AdminTestDatabaseTables getAdminTestDatabaseTables() {
40 return (AdminTestDatabaseTables)getDatabase();
41 }
42
43
44 /**
45 * Retrieves the <code>ParentTable</code> table
46 * which this <code>Persistent</code> is from.
47 *
48 * See org.melati.poem.prepro.TableDef#generatePersistentBaseJava
49 * @return the ParentTable
50 */
51 @SuppressWarnings("unchecked")
52 public ParentTable<Parent> getParentTable() {
53 return (ParentTable<Parent>)getTable();
54 }
55
56 @SuppressWarnings("unchecked")
57 private ParentTable<Parent> _getParentTable() {
58 return (ParentTable<Parent>)getTable();
59 }
60
61 // Fields in this table
62 /**
63 * id
64 */
65 protected Integer id;
66 /**
67 * name - The name
68 */
69 protected String name;
70 /**
71 * image - The image
72 */
73 protected Integer image;
74
75
76 /**
77 * Retrieves the <code>Id</code> value, without locking,
78 * for this <code>Parent</code> <code>Persistent</code>.
79 *
80 * see org.melati.poem.prepro.FieldDef#generateBaseMethods
81 * @return the Integer id
82 */
83 public Integer getId_unsafe() {
84 return id;
85 }
86
87
88 /**
89 * Sets the <code>Id</code> value directly, without checking,
90 * for this Parent <code>Persistent</code>.
91 *
92 * see org.melati.poem.prepro.FieldDef#generateBaseMethods
93 * @param cooked the pre-validated value to set
94 */
95 public void setId_unsafe(Integer cooked) {
96 id = cooked;
97 }
98
99 /**
100 * Retrieves the Id value, with locking, for this
101 * <code>Parent</code> <code>Persistent</code>.
102 *
103 * Generated by org.melati.poem.prepro.AtomFieldDef#generateBaseMethods
104 * @throws AccessPoemException
105 * if the current <code>AccessToken</code>
106 * does not confer write access rights
107 * @return the value of the field <code>Id</code> for this
108 * <code>Parent</code> <code>Persistent</code>
109 */
110
111 public Integer getId()
112 throws AccessPoemException {
113 readLock();
114 return getId_unsafe();
115 }
116
117
118 /**
119 * Sets the <code>Id</code> value, with checking, for this
120 * <code>Parent</code> <code>Persistent</code>.
121 *
122 * Generated by org.melati.poem.prepro.AtomFieldDef#generateBaseMethods
123 * @param cooked a validated <code>int</code>
124 * @throws AccessPoemException
125 * if the current <code>AccessToken</code>
126 * does not confer write access rights
127 * @throws ValidationPoemException
128 * if the value is not valid
129 */
130 public void setId(Integer cooked)
131 throws AccessPoemException, ValidationPoemException {
132 _getParentTable().getIdColumn().
133 getType().assertValidCooked(cooked);
134 writeLock();
135 setId_unsafe(cooked);
136 }
137
138 /**
139 * Sets the <code>Id</code> value, with checking, for this
140 * <code>Parent</code> <code>Persistent</code>.
141 *
142 * Generated by org.melati.poem.prepro.IntegerFieldDef#generateBaseMethods
143 * @param cooked a validated <code>int</code>
144 * @throws AccessPoemException
145 * if the current <code>AccessToken</code>
146 * does not confer write access rights
147 * @throws ValidationPoemException
148 * if the value is not valid
149 */
150
151 public final void setId(int cooked)
152 throws AccessPoemException, ValidationPoemException {
153 setId(new Integer(cooked));
154 }
155
156
157 /**
158 * Retrieves the <code>Id</code> value as a <code>Field</code>
159 * from this <code>Parent</code> <code>Persistent</code>.
160 *
161 * see org.melati.poem.prepro.FieldDef#generateFieldCreator
162 * @throws AccessPoemException
163 * if the current <code>AccessToken</code>
164 * does not confer write access rights
165 * @return the Integer id
166 */
167 public Field<Integer> getIdField() throws AccessPoemException {
168 Column<Integer> c = _getParentTable().getIdColumn();
169 return new Field<Integer>((Integer)c.getRaw(this), c);
170 }
171
172
173 /**
174 * Retrieves the <code>Name</code> value, without locking,
175 * for this <code>Parent</code> <code>Persistent</code>.
176 *
177 * see org.melati.poem.prepro.FieldDef#generateBaseMethods
178 * @return the String name
179 */
180 public String getName_unsafe() {
181 return name;
182 }
183
184
185 /**
186 * Sets the <code>Name</code> value directly, without checking,
187 * for this Parent <code>Persistent</code>.
188 *
189 * see org.melati.poem.prepro.FieldDef#generateBaseMethods
190 * @param cooked the pre-validated value to set
191 */
192 public void setName_unsafe(String cooked) {
193 name = cooked;
194 }
195
196 /**
197 * Retrieves the Name value, with locking, for this
198 * <code>Parent</code> <code>Persistent</code>.
199 * Field description:
200 * The name
201 *
202 * Generated by org.melati.poem.prepro.AtomFieldDef#generateBaseMethods
203 * @throws AccessPoemException
204 * if the current <code>AccessToken</code>
205 * does not confer write access rights
206 * @return the value of the field <code>Name</code> for this
207 * <code>Parent</code> <code>Persistent</code>
208 */
209
210 public String getName()
211 throws AccessPoemException {
212 readLock();
213 return getName_unsafe();
214 }
215
216
217 /**
218 * Sets the <code>Name</code> value, with checking, for this
219 * <code>Parent</code> <code>Persistent</code>.
220 * Field description:
221 * The name
222 *
223 * Generated by org.melati.poem.prepro.AtomFieldDef#generateBaseMethods
224 * @param cooked a validated <code>int</code>
225 * @throws AccessPoemException
226 * if the current <code>AccessToken</code>
227 * does not confer write access rights
228 * @throws ValidationPoemException
229 * if the value is not valid
230 */
231 public void setName(String cooked)
232 throws AccessPoemException, ValidationPoemException {
233 _getParentTable().getNameColumn().
234 getType().assertValidCooked(cooked);
235 writeLock();
236 setName_unsafe(cooked);
237 }
238
239
240 /**
241 * Retrieves the <code>Name</code> value as a <code>Field</code>
242 * from this <code>Parent</code> <code>Persistent</code>.
243 *
244 * see org.melati.poem.prepro.FieldDef#generateFieldCreator
245 * @throws AccessPoemException
246 * if the current <code>AccessToken</code>
247 * does not confer write access rights
248 * @return the String name
249 */
250 public Field<String> getNameField() throws AccessPoemException {
251 Column<String> c = _getParentTable().getNameColumn();
252 return new Field<String>((String)c.getRaw(this), c);
253 }
254
255
256 /**
257 * Retrieves the <code>Image</code> value, without locking,
258 * for this <code>Parent</code> <code>Persistent</code>.
259 *
260 * see org.melati.poem.prepro.FieldDef#generateBaseMethods
261 * @return the Integer image
262 */
263 public Integer getImage_unsafe() {
264 return image;
265 }
266
267
268 /**
269 * Sets the <code>Image</code> value directly, without checking,
270 * for this Parent <code>Persistent</code>.
271 *
272 * see org.melati.poem.prepro.FieldDef#generateBaseMethods
273 * @param cooked the pre-validated value to set
274 */
275 public void setImage_unsafe(Integer cooked) {
276 image = cooked;
277 }
278
279 /**
280 * Retrieves the Table Row Object ID.
281 *
282 * Generated by org.melati.poem.prepro.ReferenceFieldDef#generateBaseMethods
283 * @throws AccessPoemException
284 * if the current <code>AccessToken</code>
285 * does not confer read access rights
286 * @return the TROID as an <code>Integer</code>
287 */
288
289 public Integer getImageTroid()
290 throws AccessPoemException {
291 readLock();
292 return getImage_unsafe();
293 }
294
295
296 /**
297 * Sets the Table Row Object ID.
298 *
299 * Generated by org.melati.poem.prepro.ReferenceFieldDef#generateBaseMethods
300 * @param raw a Table Row Object Id
301 * @throws AccessPoemException
302 * if the current <code>AccessToken</code>
303 * does not confer write access rights
304 */
305 public void setImageTroid(Integer raw)
306 throws AccessPoemException {
307 setImage(raw == null ? null :
308 getAdminTestDatabaseTables().getUploadedImageTable().getUploadedImageObject(raw));
309 }
310
311
312 /**
313 * Retrieves the <code>Image</code> object referred to.
314 *
315 * Generated by org.melati.poem.prepro.ReferenceFieldDef#generateBaseMethods
316 * @throws AccessPoemException
317 * if the current <code>AccessToken</code>
318 * does not confer read access rights
319 * @throws NoSuchRowPoemException
320 * if the <code>Persistent</code> has yet to be allocated a TROID
321 * @return the <code>Image</code> as a <code>UploadedImage</code>
322 */
323 public UploadedImage getImage()
324 throws AccessPoemException, NoSuchRowPoemException {
325 Integer troid = getImageTroid();
326 return troid == null ? null :
327 getAdminTestDatabaseTables().getUploadedImageTable().getUploadedImageObject(troid);
328 }
329
330
331 /**
332 * Set the Image.
333 *
334 * Generated by org.melati.poem.prepro.ReferenceFieldDef#generateBaseMethods
335 * @param cooked a validated <code>UploadedImage</code>
336 * @throws AccessPoemException
337 * if the current <code>AccessToken</code>
338 * does not confer write access rights
339 */
340 public void setImage(UploadedImage cooked)
341 throws AccessPoemException {
342 _getParentTable().
343 getImageColumn().
344 getType().assertValidCooked(cooked);
345 writeLock();
346 if (cooked == null)
347 setImage_unsafe(null);
348 else {
349 cooked.existenceLock();
350 setImage_unsafe(cooked.troid());
351 }
352 }
353
354
355 /**
356 * Retrieves the <code>Image</code> value as a <code>Field</code>
357 * from this <code>Parent</code> <code>Persistent</code>.
358 *
359 * see org.melati.poem.prepro.FieldDef#generateFieldCreator
360 * @throws AccessPoemException
361 * if the current <code>AccessToken</code>
362 * does not confer write access rights
363 * @return the Integer image
364 */
365 public Field<Integer> getImageField() throws AccessPoemException {
366 Column<Integer> c = _getParentTable().getImageColumn();
367 return new Field<Integer>((Integer)c.getRaw(this), c);
368 }
369
370 private CachedSelection<Child> parentChilds = null;
371 /** References to this Parent in the Child table via its parent field.*/
372 @SuppressWarnings("unchecked")
373 public Enumeration<Child> getParentChilds() {
374 if (getTroid() == null)
375 return new EmptyEnumeration<Child>();
376 else {
377 if (parentChilds == null)
378 parentChilds =
379 getAdminTestDatabaseTables().getChildTable().getParentColumn().cachedSelectionWhereEq(getTroid());
380 return parentChilds.objects();
381 }
382 }
383
384
385 /** References to this Parent in the Child table via its parent field, as a List.*/
386 public List<Child> getParentChildList() {
387 return Collections.list(getParentChilds());
388 }
389
390
391
392 }
393