1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.ExpressoSchema; 68 import com.jcorporate.expresso.core.cache.Cache; 69 import com.jcorporate.expresso.core.cache.CacheManager; 70 import com.jcorporate.expresso.core.cache.CacheSystem; 71 import com.jcorporate.expresso.core.db.DBException; 72 import com.jcorporate.expresso.core.dbobj.DBObject; 73 import com.jcorporate.expresso.core.dbobj.RequestContext; 74 import com.jcorporate.expresso.core.dbobj.Schema; 75 import com.jcorporate.expresso.core.dbobj.SchemaFactory; 76 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 77 import com.jcorporate.expresso.core.dbobj.ValidValue; 78 79 import java.util.Enumeration ; 80 import java.util.Iterator ; 81 import java.util.Vector ; 82 83 84 90 public class DBObjLimit 91 extends SecuredDBObject { 92 private Vector dbObjList = null; 93 94 public static final String TTL = "TTL"; 95 public static final String DB_OBJECT_NAME = "DBObjectName"; 96 public static final String PAGE_LIMIT = "PageLimit"; 97 public static final String CACHE_SIZE = "CacheSize"; 98 99 100 103 public DBObjLimit() 104 throws DBException { 105 super(); 106 } 107 108 109 112 public DBObjLimit(int uid) 113 throws DBException { 114 super(uid); 115 } 116 117 124 public DBObjLimit(RequestContext request) 125 throws DBException { 126 super(request); 127 } 128 129 134 private void doSchema(String schemaName, String schemaDescrip, 135 Vector oList) 136 throws DBException { 137 Schema oneSchema = SchemaFactory.getInstance().getSchema(schemaName); 138 139 if (oneSchema == null) { 140 throw new DBException("Error instantiating class '" + schemaName); 141 } 142 143 DBObject oneDBObj = null; 144 ValidValue oneVal = null; 145 146 147 for (Enumeration e = oneSchema.getMembers(); e.hasMoreElements();) { 148 oneDBObj = (DBObject) e.nextElement(); 149 oneVal = new ValidValue(oneDBObj.getClass().getName(), 150 schemaDescrip + ": " + 151 oneDBObj.getMetaData().getDescription(this.getLocale())); 152 oList.addElement(oneVal); 153 } 154 } 155 156 157 165 public synchronized Vector getValidValues(String fieldName) 166 throws DBException { 167 if (fieldName.equals(DB_OBJECT_NAME)) { 168 if (dbObjList == null) { 169 SchemaList myList = new SchemaList(SecuredDBObject.SYSTEM_ACCOUNT); 170 myList.setDataContext(getDataContext()); 171 172 SchemaList oneList = null; 173 dbObjList = new Vector (10); 174 175 176 177 178 DBOtherMap otherList = new DBOtherMap(); 179 otherList.setDataContext(getDataContext()); 180 181 DBOtherMap oneOther = null; 182 ValidValue oneVal; 183 184 for (Iterator e2 = otherList.searchAndRetrieveList().iterator(); 185 e2.hasNext();) { 186 oneOther = (DBOtherMap) e2.next(); 187 oneVal = new ValidValue(oneOther.getField(DBOtherMap.DB_OBJECT_NAME), 188 oneOther.getField(DBOtherMap.DESCRIP)); 189 dbObjList.addElement(oneVal); 190 } 191 192 doSchema(ExpressoSchema.class.getName(), "Expresso", dbObjList); 193 194 195 for (Iterator sl = myList.searchAndRetrieveList().iterator(); 196 sl.hasNext();) { 197 oneList = (SchemaList) sl.next(); 198 doSchema(oneList.getField(SchemaList.FLD_SCHEMA_CLASS), 199 oneList.getField(SchemaList.FLD_DESCRIP), dbObjList); 200 } 201 202 } 203 204 return dbObjList; 205 } 206 207 return super.getValidValues(fieldName); 208 } 209 210 211 214 public void setupFields() 215 throws DBException { 216 setTargetTable("DBOBJLIMIT"); 217 setDescription("DBobjLimit"); 218 setCharset("ISO-8859-1"); 219 addField(DB_OBJECT_NAME, "varchar", 80, false, "dbobjName"); 220 addField(PAGE_LIMIT, "int", 0, false, "numEntriesPerPage"); addField(CACHE_SIZE, "int", 0, false, "numEntriesCache"); 222 addField(TTL, "int", 0, true, "TTL (minutes)"); 223 setStringFilter(DB_OBJECT_NAME, "stripFilter"); 224 addKey(DB_OBJECT_NAME); 225 setMultiValued(DB_OBJECT_NAME); 226 } 227 228 229 232 public synchronized void populateDefaultValues() 233 throws DBException { 234 DBObjLimit oneLimit = new DBObjLimit(); 235 oneLimit.setDataContext(getDataContext()); 236 oneLimit.clear(); 237 oneLimit.setField(DB_OBJECT_NAME, DefaultUserInfo.class.getName()); 238 oneLimit.setField(PAGE_LIMIT, "20"); 239 oneLimit.setField(CACHE_SIZE, "5"); 240 oneLimit.setField(TTL, 30); 241 oneLimit.addIfNeeded(); 242 oneLimit.clear(); 243 oneLimit.setField(DB_OBJECT_NAME, Event.class.getName()); 244 oneLimit.setField(PAGE_LIMIT, "20"); 245 oneLimit.setField(CACHE_SIZE, "5"); 246 oneLimit.setField(TTL, 90); 247 oneLimit.addIfNeeded(); 248 oneLimit.clear(); 249 oneLimit.setField(DB_OBJECT_NAME, GroupMembers.class.getName()); 250 oneLimit.setField(PAGE_LIMIT, "20"); 251 oneLimit.setField(CACHE_SIZE, "10"); 252 oneLimit.setField(TTL, 10); 253 oneLimit.addIfNeeded(); 254 oneLimit.clear(); 255 oneLimit.setField(DB_OBJECT_NAME, RegistrationDomain.class.getName()); 256 oneLimit.setField(PAGE_LIMIT, "20"); 257 oneLimit.setField(CACHE_SIZE, "1"); 258 oneLimit.setField(TTL, 90); 259 oneLimit.addIfNeeded(); 260 oneLimit.clear(); 261 oneLimit.setField(DB_OBJECT_NAME, UserPreference.class.getName()); 262 oneLimit.setField(PAGE_LIMIT, "20"); 263 oneLimit.setField(CACHE_SIZE, "5"); 264 oneLimit.setField(TTL, 30); 265 oneLimit.addIfNeeded(); 266 } 267 268 273 public void update() throws DBException { 274 super.update(); 275 276 CacheSystem cs = CacheManager.getCacheSystem(this.getDataContext()); 277 Cache cache = cs.getCache(getField(DB_OBJECT_NAME)); 278 if (cache != null) { 279 int newCacheSize = getFieldInt(CACHE_SIZE); 280 cache.setMaxSize(newCacheSize); 281 282 DBObject dbobject; 283 try { 284 dbobject = (DBObject) Class.forName(getField(DB_OBJECT_NAME)).newInstance(); 285 } catch (Exception e) { 286 throw new DBException("DBObjLimit.update() Error instantiating class: " 287 + getField(DB_OBJECT_NAME)); 288 } 289 dbobject.getMetaData().setCacheSize(newCacheSize); 290 291 } 292 } 293 294 } 295 296 | Popular Tags |