1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.cache.CacheException; 68 import com.jcorporate.expresso.core.cache.CacheManager; 69 import com.jcorporate.expresso.core.cache.CacheSystem; 70 import com.jcorporate.expresso.core.db.DBException; 71 import com.jcorporate.expresso.core.dbobj.RequestContext; 72 import com.jcorporate.expresso.core.dbobj.Schema; 73 import com.jcorporate.expresso.core.dbobj.SchemaFactory; 74 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 75 import com.jcorporate.expresso.core.dbobj.ValidValue; 76 import com.jcorporate.expresso.core.misc.StringUtil; 77 import org.apache.log4j.Logger; 78 79 import java.util.Vector ; 80 81 82 92 public class SchemaList 93 extends SecuredDBObject { 94 95 static private final transient Logger log = Logger.getLogger(SchemaList.class); 96 97 100 static private final long CACHE_TTY = 60 * 30 * 1000; 101 102 105 static public final String FLD_SCHEMA_CLASS = "SchemaClass"; 106 107 110 static public final String FLD_DESCRIP = "Descrip"; 111 112 115 static public final String FLD_COMPONENT_CODE = "ComponentCode"; 116 117 120 static public final String FLD_VERSION_NUMBER = "VersionNumber"; 121 122 123 126 public SchemaList() 127 throws DBException { 128 super(); 129 } 130 131 132 139 public SchemaList(int uid) 140 throws DBException { 141 super(uid); 142 } 143 144 151 public SchemaList(RequestContext request) 152 throws DBException { 153 super(request); 154 } 155 156 157 163 public Vector getValues() 164 throws DBException { 165 166 String cacheName = this.getClass().getName() + ".validValues"; 167 CacheSystem cs = CacheManager.getCacheSystem(this.getDataContext()); 168 boolean cacheError = false; 169 try { 170 if (!cs.existsCache(cacheName)) { 171 cs.createCache(cacheName, true); 172 } 173 } catch (CacheException ex) { 174 log.error("Error getting cached valid values", ex); 175 cacheError = true; 176 } 177 178 Vector v = null; 179 if (!cacheError && (localConnection == null || localConnection.getAutoCommit() == false)) { 183 java.util.List temp = cs.getItems(cacheName); 184 if (temp != null) { 185 if (temp instanceof Vector ) { 186 v = (Vector ) temp; 187 } else { 188 v = new Vector (temp); 189 } 190 } 191 } 192 193 if (v == null) { 194 v = getValuesDefault("SchemaClass", "Descrip"); 195 v.addElement(new ValidValue("com.jcorporate.expresso.core.ExpressoSchema", 196 "Expresso")); 197 198 if (!cacheError) { 199 try { 200 cs.setItems(cacheName, v, CACHE_TTY); 201 } catch (CacheException ex) { 202 log.error("Error setting cached valid values", ex); 203 } 204 } 205 } 206 207 208 return v; 209 } 210 211 212 220 public String getField(String fieldName) 221 throws DBException { 222 if (fieldName.equals("VersionNumber")) { 223 String schemaClass = StringUtil.notNull(getField("SchemaClass")); 224 225 if (!schemaClass.equals("")) { 226 Schema oneSchema = null; 227 228 oneSchema = SchemaFactory.getInstance().getSchema(schemaClass); 229 230 if (oneSchema == null) { 231 return "N/A"; 232 } 233 234 235 return oneSchema.getVersion(); 236 } 237 238 return ""; 239 } 240 241 return super.getField(fieldName); 242 } 243 244 245 248 public void setupFields() 249 throws DBException { 250 setTargetTable("SCHEMALIST"); 251 setDescription("DBschemaList"); 252 setCharset("ISO-8859-1"); 253 addField(FLD_SCHEMA_CLASS, "char", 128, false, "schemaClassFile"); 254 addField(FLD_DESCRIP, "char", 80, false, "schemaDescription"); 255 addField(FLD_COMPONENT_CODE, "char", 80, true, "componentCode"); 256 addVirtualField(FLD_VERSION_NUMBER, "char", 10, "version"); 257 addKey("SchemaClass"); 258 } 259 260 261 } 262 263 | Popular Tags |