1 package org.melati.example.contacts;
2
3
4 import org.melati.example.contacts.generated.CategoryTableBase;
5 import org.melati.poem.Database;
6 import org.melati.poem.DefinitionSource;
7 import org.melati.poem.PoemException;
8
9 /**
10 * Melati POEM generated, programmer modifiable stub
11 * for a <code>CategoryTable</code> object.
12 * <p>
13 * Description:
14 * A Category for Contacts.
15 * </p>
16 * <p>
17 * <p>
18 * <table>
19 * <caption>
20 * Field summary for SQL table <code>Category</code>
21 * </caption>
22 * <tr><th>Name</th><th>Type</th><th>Description</th></tr>
23 * <tr><td> id </td><td> Integer </td><td> </td></tr>
24 * <tr><td> name </td><td> String </td><td> Category Name </td></tr>
25 * </table>
26 * <p>
27 * See org.melati.poem.prepro.TableDef#generateTableJava
28 *
29 * @author timp
30 * @since 2017-10-18
31 */
32 public class CategoryTable<T extends Category> extends CategoryTableBase<Category> {
33
34 /**
35 * Constructor.
36 * <p>
37 * See org.melati.poem.prepro.TableDef#generateTableJava
38 *
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 CategoryTable(
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 Category ensure(String name) {
53 Category it = (Category) getNameColumn().firstWhereEq(name);
54 if (it != null) {
55 return it;
56 } else {
57 it = (Category) newPersistent();
58 it.setName(name);
59 return (Category) getNameColumn().ensure(it);
60 }
61 }
62
63 }
64