1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.controller.ControllerRequest; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.security.User; 70 import com.jcorporate.expresso.core.security.UserListener; 71 72 import java.util.Iterator ; 73 74 75 82 public class UserPreference 83 extends SecurityDBObject 84 implements UserListener { 85 86 87 public static final String PREF_CODE = "PrefCode"; 88 public static final String PREF_VALUE = "PrefValue"; 89 public static final String CLASS_NAME = "ClassName"; 90 public static final String EXPUID = "ExpUid"; 91 92 static { 93 try { 94 User.addListener(new UserPreference()); 95 } catch (Exception e) { 96 e.printStackTrace(); 97 System.err.println(e.getMessage()); 98 } 99 100 } 101 102 105 public UserPreference() 106 throws DBException { 107 } 108 109 116 public UserPreference(int uid) 117 throws DBException { 118 super(uid); 119 } 120 121 127 public UserPreference(ControllerRequest request) 128 throws DBException { 129 super(request); 130 } 131 132 public void addedUser(User user) 133 throws DBException { 134 } 135 136 141 protected void checkAllRefs() 142 throws DBException { 143 checkRef("ClassName;PrefCode", new UserPreferenceDef(), 144 "Invalid Preference Code"); 145 } 146 147 148 public void deletedUser(User user) 149 throws DBException { 150 UserPreference u = new UserPreference(); 151 u.setDataContext(user.getDataContext()); 152 u.setField(EXPUID, user.getUid()); 153 154 UserPreference onePreference = null; 155 156 for (Iterator e = u.searchAndRetrieveList().iterator(); 157 e.hasNext();) { 158 onePreference = (UserPreference) e.next(); 159 onePreference.delete(); 160 } 161 } 162 163 public void loggedOffUser(User user) 164 throws DBException { 165 } 166 167 public void loggedOnUser(User user) 168 throws DBException { 169 } 170 171 public void modifiedUser(User user) 172 throws DBException { 173 } 174 175 180 public void setupFields() 181 throws DBException { 182 setTargetTable("USERPREF"); 183 setDescription("DBuserPref"); 184 setCharset("ISO-8859-1"); 185 addField(EXPUID, "int", 0, false, "userId"); 186 addVirtualField("LoginName", "char", 30, "loginName"); 187 addField(CLASS_NAME, "varchar", 128, false, "className"); 188 addField(PREF_CODE, "varchar", 30, false, "prefCode"); 189 addField(PREF_VALUE, "varchar", 80, false, "prefValue"); 190 setStringFilter(CLASS_NAME, "stripFilter"); 191 setStringFilter(PREF_CODE, "stripFilter"); 192 setStringFilter("PrefValue", "rawFilter"); 193 194 addKey(EXPUID); 195 addKey(CLASS_NAME); 196 addKey(PREF_CODE); 197 198 setLookupObject(EXPUID, "com.jcorporate.expresso.core.security.User"); 199 } 200 201 202 public String getField(String fieldName) 203 throws DBException { 204 if (fieldName.equals("LoginName")) { 205 User u = new User(); 206 u.setUid(getFieldInt(EXPUID)); 207 u.setDataContext(this.getDataContext()); 208 209 if (u.find()) { 210 return u.getLoginName(); 211 } 212 213 return "No such user"; 214 } 215 216 return super.getField(fieldName); 217 } 218 } 219 | Popular Tags |