View Javadoc
1   // Do not edit this file!  It was generated by Melati POEM's DSD preprocessor.
2   
3   package org.melati.poem.generated;
4   
5   
6   import org.melati.poem.AccessPoemException;
7   import org.melati.poem.Column;
8   import org.melati.poem.Database;
9   import org.melati.poem.DefinitionSource;
10  import org.melati.poem.DisplayLevel;
11  import org.melati.poem.Field;
12  import org.melati.poem.JdbcPersistent;
13  import org.melati.poem.PasswordPoemType;
14  import org.melati.poem.Persistent;
15  import org.melati.poem.PoemDatabaseTables;
16  import org.melati.poem.PoemException;
17  import org.melati.poem.PoemTable;
18  import org.melati.poem.Searchability;
19  import org.melati.poem.StringPoemType;
20  import org.melati.poem.TroidPoemType;
21  import org.melati.poem.User;
22  import org.melati.poem.ValidationPoemException;
23  
24  
25  /**
26   * Melati POEM generated base class for <code>Table</code> <code>user</code>.
27   *
28   * See org.melati.poem.prepro.TableDef#generateTableBaseJava 
29   */
30  
31  public class UserTableBase<T extends User> extends PoemTable<T> {
32  
33    private Column<Integer> col_id = null;
34    private Column<String> col_name = null;
35    private Column<String> col_login = null;
36    private Column<String> col_password = null;
37  
38   /**
39    * Constructor. 
40    * 
41    * See org.melati.poem.prepro.TableDef#generateTableBaseJava 
42    * @param database          the POEM database we are using
43    * @param name              the name of this <code>Table</code>
44    * @param definitionSource  which definition is being used
45    * @throws PoemException    if anything goes wrong
46    */
47  
48    public UserTableBase(
49        Database database, String name,
50        DefinitionSource definitionSource) throws PoemException {
51      super(database, name, definitionSource);
52    }
53  
54  
55   /**
56    * Get the database tables.
57    *
58    * See org.melati.poem.prepro.TableDef#generateTableBaseJava 
59    * @return the database tables
60    */
61    public PoemDatabaseTables getPoemDatabaseTables() {
62      return (PoemDatabaseTables)getDatabase();
63    }
64  
65  
66   /**
67    * Initialise this table by defining its columns.
68    *
69    * See org.melati.poem.prepro.TableDef#generateTableBaseJava 
70    */
71    public void init() throws PoemException {
72      super.init();
73      defineColumn(col_id =
74          new Column<Integer>(this, "id",
75                     new TroidPoemType(),
76                     DefinitionSource.dsd) { 
77            public Object getCooked(Persistent g)
78                throws AccessPoemException, PoemException {
79              return ((User)g).getId();
80            }
81  
82            public void setCooked(Persistent g, Object cooked)
83                throws AccessPoemException, ValidationPoemException {
84              ((User)g).setId((Integer)cooked);
85            }
86  
87            public Field<Integer> asField(Persistent g) {
88              return ((User)g).getIdField();
89            }
90  
91            public boolean defaultUserEditable() {
92              return false;
93            }
94  
95            public boolean defaultUserCreateable() {
96              return false;
97            }
98  
99            public DisplayLevel defaultDisplayLevel() {
100             return DisplayLevel.detail;
101           }
102 
103           public int defaultDisplayOrder() {
104             return 10;
105           }
106 
107           public String defaultDescription() {
108             return "The Table Row Object ID";
109           }
110 
111           public Object getRaw_unsafe(Persistent g)
112               throws AccessPoemException {
113             return ((User)g).getId_unsafe();
114           }
115 
116           public void setRaw_unsafe(Persistent g, Object raw)
117               throws AccessPoemException {
118             ((User)g).setId_unsafe((Integer)raw);
119           }
120 
121           public Object getRaw(Persistent g)
122               throws AccessPoemException {
123             return ((User)g).getId();
124           }
125 
126           public void setRaw(Persistent g, Object raw)
127               throws AccessPoemException {
128             ((User)g).setId((Integer)raw);
129           }
130         });
131 
132     defineColumn(col_name =
133         new Column<String>(this, "name",
134                    new StringPoemType(false, 60),
135                    DefinitionSource.dsd) { 
136           public Object getCooked(Persistent g)
137               throws AccessPoemException, PoemException {
138             return ((User)g).getName();
139           }
140 
141           public void setCooked(Persistent g, Object cooked)
142               throws AccessPoemException, ValidationPoemException {
143             ((User)g).setName((String)cooked);
144           }
145 
146           public Field<String> asField(Persistent g) {
147             return ((User)g).getNameField();
148           }
149 
150           public DisplayLevel defaultDisplayLevel() {
151             return DisplayLevel.primary;
152           }
153 
154           public Searchability defaultSearchability() {
155             return Searchability.primary;
156           }
157 
158           public Integer defaultDisplayOrderPriority() {
159             return new Integer(0);
160           }
161 
162           public String defaultDisplayName() {
163             return "Full name";
164           }
165 
166           public int defaultDisplayOrder() {
167             return 20;
168           }
169 
170           public String defaultDescription() {
171             return "The user's real name";
172           }
173 
174           public boolean defaultIndexed() {
175             return true;
176           }
177 
178           public Object getRaw_unsafe(Persistent g)
179               throws AccessPoemException {
180             return ((User)g).getName_unsafe();
181           }
182 
183           public void setRaw_unsafe(Persistent g, Object raw)
184               throws AccessPoemException {
185             ((User)g).setName_unsafe((String)raw);
186           }
187 
188           public Object getRaw(Persistent g)
189               throws AccessPoemException {
190             return ((User)g).getName();
191           }
192 
193           public void setRaw(Persistent g, Object raw)
194               throws AccessPoemException {
195             ((User)g).setName((String)raw);
196           }
197         });
198 
199     defineColumn(col_login =
200         new Column<String>(this, "login",
201                    new StringPoemType(false, 255),
202                    DefinitionSource.dsd) { 
203           public Object getCooked(Persistent g)
204               throws AccessPoemException, PoemException {
205             return ((User)g).getLogin();
206           }
207 
208           public void setCooked(Persistent g, Object cooked)
209               throws AccessPoemException, ValidationPoemException {
210             ((User)g).setLogin((String)cooked);
211           }
212 
213           public Field<String> asField(Persistent g) {
214             return ((User)g).getLoginField();
215           }
216 
217           public int defaultDisplayOrder() {
218             return 30;
219           }
220 
221           public String defaultDescription() {
222             return "The user's login name";
223           }
224 
225           public boolean defaultUnique() {
226             return true;
227           }
228 
229           public int defaultWidth() {
230             return 20;
231           }
232 
233           public Object getRaw_unsafe(Persistent g)
234               throws AccessPoemException {
235             return ((User)g).getLogin_unsafe();
236           }
237 
238           public void setRaw_unsafe(Persistent g, Object raw)
239               throws AccessPoemException {
240             ((User)g).setLogin_unsafe((String)raw);
241           }
242 
243           public Object getRaw(Persistent g)
244               throws AccessPoemException {
245             return ((User)g).getLogin();
246           }
247 
248           public void setRaw(Persistent g, Object raw)
249               throws AccessPoemException {
250             ((User)g).setLogin((String)raw);
251           }
252         });
253 
254     defineColumn(col_password =
255         new Column<String>(this, "password",
256                    new PasswordPoemType(false, 20),
257                    DefinitionSource.dsd) { 
258           public Object getCooked(Persistent g)
259               throws AccessPoemException, PoemException {
260             return ((User)g).getPassword();
261           }
262 
263           public void setCooked(Persistent g, Object cooked)
264               throws AccessPoemException, ValidationPoemException {
265             ((User)g).setPassword((String)cooked);
266           }
267 
268           public Field<String> asField(Persistent g) {
269             return ((User)g).getPasswordField();
270           }
271 
272           public DisplayLevel defaultDisplayLevel() {
273             return DisplayLevel.record;
274           }
275 
276           public Searchability defaultSearchability() {
277             return Searchability.no;
278           }
279 
280           public int defaultDisplayOrder() {
281             return 40;
282           }
283 
284           public String defaultDescription() {
285             return "The user's password";
286           }
287 
288           public int defaultWidth() {
289             return 10;
290           }
291 
292           public Object getRaw_unsafe(Persistent g)
293               throws AccessPoemException {
294             return ((User)g).getPassword_unsafe();
295           }
296 
297           public void setRaw_unsafe(Persistent g, Object raw)
298               throws AccessPoemException {
299             ((User)g).setPassword_unsafe((String)raw);
300           }
301 
302           public Object getRaw(Persistent g)
303               throws AccessPoemException {
304             return ((User)g).getPassword();
305           }
306 
307           public void setRaw(Persistent g, Object raw)
308               throws AccessPoemException {
309             ((User)g).setPassword((String)raw);
310           }
311         });
312   }
313 
314 
315  /**
316   * Retrieves the <code>Id</code> <code>Column</code> for this 
317   * <code>user</code> <code>Table</code>.
318   * 
319   * see org.melati.poem.prepro.FieldDef#generateColAccessor 
320   * @return the id <code>Column</code>
321   */
322   public final Column<Integer> getIdColumn() {
323     return col_id;
324   }
325 
326 
327  /**
328   * Retrieves the <code>Name</code> <code>Column</code> for this 
329   * <code>user</code> <code>Table</code>.
330   * 
331   * see org.melati.poem.prepro.FieldDef#generateColAccessor 
332   * @return the name <code>Column</code>
333   */
334   public final Column<String> getNameColumn() {
335     return col_name;
336   }
337 
338 
339  /**
340   * Retrieves the <code>Login</code> <code>Column</code> for this 
341   * <code>user</code> <code>Table</code>.
342   * 
343   * see org.melati.poem.prepro.FieldDef#generateColAccessor 
344   * @return the login <code>Column</code>
345   */
346   public final Column<String> getLoginColumn() {
347     return col_login;
348   }
349 
350 
351  /**
352   * Retrieves the <code>Password</code> <code>Column</code> for this 
353   * <code>user</code> <code>Table</code>.
354   * 
355   * see org.melati.poem.prepro.FieldDef#generateColAccessor 
356   * @return the password <code>Column</code>
357   */
358   public final Column<String> getPasswordColumn() {
359     return col_password;
360   }
361 
362 
363  /**
364   * Retrieve the <code>User</code> as a <code>User</code>.
365   *
366   * See org.melati.poem.prepro.TableDef#generateTableBaseJava 
367   * @param troid a Table Row Object ID
368   * @return the <code>Persistent</code> identified by the <code>troid</code>
369   */
370   public User getUserObject(Integer troid) {
371     return (User)getObject(troid);
372   }
373 
374 
375  /**
376   * Retrieve the <code>User</code> 
377   * as a <code>User</code>.
378   *
379   * See org.melati.poem.prepro.TableDef#generateTableBaseJava 
380   * @param troid a Table Row Object ID
381   * @return the <code>Persistent</code> identified   */
382   public User getUserObject(int troid) {
383     return (User)getObject(troid);
384   }
385 
386   protected JdbcPersistent _newPersistent() {
387     return new User();
388   }
389   public String defaultDescription() {
390     return "A registered User of the database";
391   }
392 
393   public boolean defaultRememberAllTroids() {
394     return true;
395   }
396 
397   public String defaultCategory() {
398     return "User";
399   }
400 
401   public int defaultDisplayOrder() {
402     return 2010;
403   }
404 
405   /**
406    * @return a newly created or existing User
407    **/
408   public User ensure(String name, String login, String password) {
409     User p = (User)getLoginColumn().firstWhereEq(login);
410     if (p == null) {
411       p = (User)newPersistent();
412       p.setName(name);
413       p.setLogin(login);
414       p.setPassword(password);
415     }
416     return (User)getLoginColumn().ensure(p);
417   }
418 }
419