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.dbobj.SecuredDBObject; 70 import com.jcorporate.expresso.core.misc.StringUtil; 71 import org.apache.log4j.Logger; 72 73 74 81 public class ControllerDefault 82 extends SecuredDBObject { 83 private static Logger log = Logger.getLogger(ControllerDefault.class); 84 85 88 public ControllerDefault() 89 throws DBException { 90 super(); 91 } 92 93 97 public ControllerDefault(int uid) 98 throws DBException { 99 super(uid); 100 } 101 102 109 public ControllerDefault(ControllerRequest request) 110 throws DBException { 111 super(request); 112 } 113 114 117 public void add() 118 throws DBException { 119 String style = StringUtil.notNull(getField("Style")); 120 121 if (style.equals("")) { 122 setField("Style", "default"); 123 } 124 125 super.add(); 126 } 127 128 129 public synchronized void addDefault(String className, String stateCode, 130 String params) 131 throws DBException { 132 addDefault(className, "default", stateCode, params); 133 } 134 135 public synchronized void addDefault(String className, String style, 136 String stateCode, String params) 137 throws DBException { 138 ControllerDefault cd = new ControllerDefault(); 139 cd.setDataContext(getDataContext()); 140 cd.setField("ControllerClass", className); 141 cd.setField("Style", style); 142 cd.setField("StateCode", stateCode); 143 144 if (!cd.find()) { 145 cd.setField("ControllerClass", className); 146 cd.setField("Style", style); 147 cd.setField("StateCode", stateCode); 148 cd.setField("Params", params); 149 cd.add(); 150 } 151 152 log.info("Added default for controller '" + className + "', style '" + 153 style + "', state '" + stateCode + "' with parameters '" + 154 params + "'"); 155 } 156 157 public synchronized void populateDefaultValues() 158 throws DBException { 159 DBObjLimit dbl = new DBObjLimit(); 160 dbl.setDataContext(getDataContext()); 161 dbl.setField("DBObjectName", getClass().getName()); 162 163 if (!dbl.find()) { 164 dbl.setField("PageLimit", "50"); 165 dbl.setField("CacheSize", "50"); 166 dbl.add(); 167 } 168 } 169 170 175 public void setupFields() 176 throws DBException { 177 setTargetTable("CTLDEFAULT"); 178 setDescription("DBctlDefault"); 179 setCharset("ISO-8859-1"); 180 addField("ControllerClass", "char", 128, false, "controllerClass"); 181 addField("Style", "char", 20, false, "style"); 182 addField("StateCode", "char", 40, false, "state"); 183 addField("Params", "text", 0, true, "params"); 184 setStringFilter("Params", "rawFilter"); 185 addKey("ControllerClass"); 186 addKey("Style"); 187 addKey("StateCode"); 188 } 189 190 } 191 192 | Popular Tags |