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