1 package org.paneris.bibliomania;
2
3 import java.util.Enumeration;
4
5 import org.paneris.bibliomania.generated.AuthorWebSiteTableBase;
6 import org.melati.poem.DefinitionSource;
7 import org.melati.poem.Database;
8 import org.melati.poem.Persistent;
9 import org.melati.poem.PoemException;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class AuthorWebSiteTable<T extends AuthorWebSite> extends AuthorWebSiteTableBase<AuthorWebSite> {
38
39
40
41
42
43
44
45
46
47
48 public AuthorWebSiteTable(
49 Database database, String name,
50 DefinitionSource definitionSource) throws PoemException {
51 super(database, name, definitionSource);
52 }
53
54
55
56 public AuthorWebSite ensure(Author a, String url, String name, String description) {
57 System.err.println("Entering Ensure for " + name);
58
59 AuthorWebSite criteria = (AuthorWebSite)newPersistent();
60 criteria.setAuthor(a);
61 Enumeration<AuthorWebSite> existing = selection(criteria, "displayorder");
62 System.err.println("Got existing");
63 int order = 1;
64 while (existing.hasMoreElements()) {
65 System.err.println("Order:" + order);
66 existing.nextElement();
67 order++;
68 }
69 criteria.setUrl(url);
70 criteria.setDisplayname(name);
71 criteria.setDescription(description);
72
73 Enumeration<AuthorWebSite> some = selection(criteria);
74 if (some.hasMoreElements()) {
75 return some.nextElement();
76 } else {
77 criteria.setDisplayorder(order);
78 create(criteria);
79 return criteria;
80 }
81 }
82
83 public void ensureStillValid() {
84 Enumeration them = selection();
85 while(them.hasMoreElements()) {
86 ((AuthorWebSite)them.nextElement()).isStillLive();
87 }
88 }
89 }
90