View Javadoc

1   package org.paneris.bibliomania;
2   
3   import java.sql.ResultSet;
4   import java.util.Enumeration;
5   
6   import org.melati.poem.Column;
7   import org.melati.poem.Database;
8   import org.melati.poem.DefinitionSource;
9   import org.melati.poem.PoemException;
10  import org.melati.poem.util.ArrayEnumeration;
11  import org.paneris.bibliomania.generated.UserTableBase;
12  
13  public class UserTable<T extends User> extends UserTableBase<User> {
14  
15  
16    // programmer's domain-specific code here
17    protected User boardManager;
18  
19    public UserTable(
20        Database database, String name,
21        DefinitionSource definitionSource) throws PoemException {
22  
23      super(database, name, definitionSource);
24    }
25  
26    public void init() throws PoemException {
27      super.init();
28  
29      // We can't put this in the constructor because the email
30      // column isn't defined until we've called UserTableBase.init()
31      getFulltimeeducationColumn().setRaw_unsafe(guestUser, Boolean.FALSE);
32      getFulltimeeducationColumn().setRaw_unsafe(administratorUser, Boolean.FALSE);
33  
34      getWantemailalertsColumn().setRaw_unsafe(guestUser, Boolean.FALSE);
35      getWantemailalertsColumn().setRaw_unsafe(administratorUser, Boolean.FALSE);
36  
37      getWantspamColumn().setRaw_unsafe(guestUser, Boolean.FALSE);
38      getWantspamColumn().setRaw_unsafe(administratorUser, Boolean.FALSE);
39  
40      getDodgeyemailColumn().setRaw_unsafe(guestUser, Boolean.FALSE);
41      getDodgeyemailColumn().setRaw_unsafe(administratorUser, Boolean.FALSE);
42  
43    }
44  
45    public synchronized void unifyWithDB(ResultSet colDescs)
46        throws PoemException {
47      super.unifyWithDB(colDescs, "id");
48    }
49  
50  
51    public User ensure(String login, String password, String email, String name) {
52      User u = (User)newPersistent();
53      u.setLogin(login);
54      u.setPassword(password);
55      u.setEmail(email);
56      u.setName(name);
57      u.setFulltimeeducation(false);
58      u.setWantspam(false);
59      u.setWantemailalerts(false);
60      u.setDodgeyemail(false);
61      
62      return (User)getLoginColumn().ensure(u);
63    }
64  
65  
66  
67    public User boardManager() {
68      return boardManager;
69    }
70    
71    /**
72     * An enumeration of columns that the user can edit.
73     */
74    public Enumeration getUserDetailsColumns() {
75      Column[] cols = {getNameColumn(),
76                       getEmailColumn(),
77                       getPasswordColumn(),
78                       getAgeColumn(),
79                       getTelColumn(),
80                       getAddressColumn(),
81                       getTownColumn(),
82                       getCountyColumn(),
83                       getRegionColumn(),
84                       getCountryColumn(),
85                       getFulltimeeducationColumn(),
86                       getWantspamColumn()};
87      return new ArrayEnumeration(cols);
88    }
89  
90    public void setBoardManager(User boardManager) {
91      this.boardManager = boardManager;
92    }
93  
94  }
95  
96  
97  
98  
99  
100