1 package org.melati.example.contacts;
2
3 import org.melati.example.contacts.generated.ContactCategoryTableBase;
4 import org.melati.poem.Database;
5 import org.melati.poem.DefinitionSource;
6 import org.melati.poem.PoemException;
7
8 /**
9 * Melati POEM generated, programmer modifiable stub
10 * for a <code>ContactCategoryTable</code> object.
11 * <p>
12 * Description:
13 * Contacts Categories.
14 * </p>
15 *
16 *
17 * <table>
18 * <caption>
19 * Field summary for SQL table <code>ContactCategory</code>
20 * </caption>
21 * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
22 * <tr><td> id </td><td> Integer </td><td> </td></tr>
23 * <tr><td> category </td><td> Category </td><td> Category </td></tr>
24 * <tr><td> contact </td><td> Contact </td><td> Contact </td></tr>
25 * </table>
26 *
27 * See org.melati.poem.prepro.TableDef#generateTableJava
28 *
29 * @author timp
30 * @since 2017-10-18
31 *
32 */
33 public class ContactCategoryTable<T extends ContactCategory> extends ContactCategoryTableBase<ContactCategory> {
34
35 /**
36 * Constructor.
37 *
38 * See org.melati.poem.prepro.TableDef#generateTableJava
39 * @param database the POEM database we are using
40 * @param name the name of this <code>Table</code>
41 * @param definitionSource which definition is being used
42 * @throws PoemException if anything goes wrong
43 */
44 public ContactCategoryTable(
45 Database database, String name,
46 DefinitionSource definitionSource) throws PoemException {
47 super(database, name, definitionSource);
48 }
49
50 // programmer's domain-specific code here
51
52 public ContactCategory ensure(Contact contact, Category c) {
53 ContactCategory it = (ContactCategory) newPersistent();
54 it.setCategory(c);
55 it.setContact(contact);
56 ContactCategory found = maybeFirst(selection(it));
57 if (found != null) {
58 return found;
59 } else {
60 it.makePersistent();
61 return it;
62 }
63 }
64 }
65