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 | 2 | super(database, name, definitionSource); |
52 | 2 | } |
53 | |
|
54 | |
|
55 | |
|
56 | |
public AuthorWebSite ensure(Author a, String url, String name, String description) { |
57 | 1 | System.err.println("Entering Ensure for " + name); |
58 | |
|
59 | 1 | AuthorWebSite criteria = (AuthorWebSite)newPersistent(); |
60 | 1 | criteria.setAuthor(a); |
61 | 1 | Enumeration<AuthorWebSite> existing = selection(criteria, "displayorder"); |
62 | 1 | System.err.println("Got existing"); |
63 | 1 | int order = 1; |
64 | 19 | while (existing.hasMoreElements()) { |
65 | 18 | System.err.println("Order:" + order); |
66 | 18 | existing.nextElement(); |
67 | 18 | order++; |
68 | |
} |
69 | 1 | criteria.setUrl(url); |
70 | 1 | criteria.setDisplayname(name); |
71 | 1 | criteria.setDescription(description); |
72 | |
|
73 | 1 | Enumeration<AuthorWebSite> some = selection(criteria); |
74 | 1 | if (some.hasMoreElements()) { |
75 | 1 | return some.nextElement(); |
76 | |
} else { |
77 | 0 | criteria.setDisplayorder(order); |
78 | 0 | create(criteria); |
79 | 0 | return criteria; |
80 | |
} |
81 | |
} |
82 | |
|
83 | |
public void ensureStillValid() { |
84 | 0 | Enumeration them = selection(); |
85 | 0 | while(them.hasMoreElements()) { |
86 | 0 | ((AuthorWebSite)them.nextElement()).isStillLive(); |
87 | |
} |
88 | 0 | } |
89 | |
} |
90 | |
|