View Javadoc

1   package org.melati.example.contacts;
2   
3   import org.melati.example.contacts.generated.ContactTableBase;
4   import org.melati.poem.DefinitionSource;
5   import org.melati.poem.Database;
6   import org.melati.poem.PoemException;
7   
8   /**
9    * Melati POEM generated, programmer modifiable stub 
10   * for a <code>ContactTable</code> object.
11   * <p>
12   * Description: 
13   *   A Contact. 
14   * </p>
15   *
16   * 
17   * <table> 
18   * <tr><th colspan='3'>
19   * Field summary for SQL table <code>Contact</code>
20   * </th></tr>
21   * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
22   * <tr><td> id </td><td> Integer </td><td> &nbsp; </td></tr> 
23   * <tr><td> name </td><td> String </td><td> Contact Name </td></tr> 
24   * <tr><td> owner </td><td> Contact </td><td> Contact who owns this contact 
25   * </td></tr> 
26   * <tr><td> address </td><td> String </td><td> Contact Address </td></tr> 
27   * <tr><td> updates </td><td> Integer </td><td> How many times has this 
28   * record been updated? </td></tr> 
29   * <tr><td> lastupdated </td><td> Date </td><td> When was this last updated? 
30   * </td></tr> 
31   * <tr><td> lastupdateuser </td><td> User </td><td> Who last updated this? 
32   * </td></tr> 
33   * </table> 
34   * 
35   * @generator  org.melati.poem.prepro.TableDef#generateTableMainJava 
36   */
37  public class ContactTable extends ContactTableBase {
38  
39   /**
40    * Constructor.
41    * 
42    * @generator org.melati.poem.prepro.TableDef#generateTableMainJava 
43    * @param database          the POEM database we are using
44    * @param name              the name of this <code>Table</code>
45    * @param definitionSource  which definition is being used
46    * @throws PoemException    if anything goes wrong
47    */
48    public ContactTable(
49        Database database, String name,
50        DefinitionSource definitionSource) throws PoemException {
51      super(database, name, definitionSource);
52    }
53  
54    // programmer's domain-specific code here
55  
56    /**
57     * @return the existing or newly created Contact
58     */
59    public Contact ensure(String name, Contact owner, String address) {
60      Contact contact = (Contact)getNameColumn().firstWhereEq(name);
61      if (contact != null)
62        return contact;
63      else {
64        contact = (Contact)newPersistent();
65        contact.setName(name);
66        contact.setOwner(owner);
67        contact.setAddress(address);
68  
69        return (Contact)getNameColumn().ensure(contact);
70      }
71    }
72  
73  
74  }