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