1 package org.apache.torque.engine.database.model; 2 3 18 19 import org.apache.commons.lang.StringUtils; 20 import org.apache.torque.engine.platform.Platform; 21 import org.xml.sax.Attributes ; 22 23 29 public class Domain 30 { 31 private String name; 32 private String description; 33 private String size; 34 private String scale; 35 36 private SchemaType torqueType; 37 private String sqlType; 38 private String defaultValue; 39 40 43 public Domain() 44 { 45 this.name = null; 46 } 47 48 53 public Domain(String name) 54 { 55 this.name = name; 56 } 57 58 61 public Domain(SchemaType type) 62 { 63 this.name = null; 64 this.torqueType = type; 65 this.sqlType = type.getName(); 66 } 67 68 71 public Domain(SchemaType type, String sqlType) 72 { 73 this.name = null; 74 this.torqueType = type; 75 this.sqlType = sqlType; 76 } 77 78 81 public Domain(SchemaType type, String sqlType, String size, String scale) 82 { 83 this.name = null; 84 this.torqueType = type; 85 this.sqlType = sqlType; 86 this.size = size; 87 this.scale = scale; 88 } 89 90 93 public Domain(SchemaType type, String sqlType, String size) 94 { 95 this.name = null; 96 this.torqueType = type; 97 this.sqlType = sqlType; 98 this.size = size; 99 } 100 101 public Domain(Domain domain) 102 { 103 copy(domain); 104 } 105 106 public void copy(Domain domain) 107 { 108 this.defaultValue = domain.getDefaultValue(); 109 this.description = domain.getDescription(); 110 this.name = domain.getName(); 111 this.scale = domain.getScale(); 112 this.size = domain.getSize(); 113 this.sqlType = domain.getSqlType(); 114 this.torqueType = domain.getType(); 115 } 116 117 120 public void loadFromXML(Attributes attrib, Platform platform) 121 { 122 SchemaType schemaType = SchemaType.getEnum(attrib.getValue("type")); 123 copy(platform.getDomainForSchemaType(schemaType)); 124 name = attrib.getValue("name"); 126 defaultValue = attrib.getValue("default"); 128 size = attrib.getValue("size"); 129 scale = attrib.getValue("scale"); 130 131 description = attrib.getValue("description"); 132 } 133 134 137 public String getDescription() 138 { 139 return description; 140 } 141 142 145 public void setDescription(String description) 146 { 147 this.description = description; 148 } 149 150 153 public String getName() 154 { 155 return name; 156 } 157 158 161 public void setName(String name) 162 { 163 this.name = name; 164 } 165 166 169 public String getScale() 170 { 171 return scale; 172 } 173 174 177 public void setScale(String scale) 178 { 179 this.scale = scale; 180 } 181 182 187 public void replaceScale(String value) 188 { 189 this.scale = StringUtils.defaultString(value, getScale()); 190 } 191 192 195 public String getSize() 196 { 197 return size; 198 } 199 200 203 public void setSize(String size) 204 { 205 this.size = size; 206 } 207 208 213 public void replaceSize(String value) 214 { 215 this.size = StringUtils.defaultString(value, getSize()); 216 } 217 218 221 public SchemaType getType() 222 { 223 return torqueType; 224 } 225 226 229 public void setType(SchemaType torqueType) 230 { 231 this.torqueType = torqueType; 232 } 233 234 237 public void setType(String torqueType) 238 { 239 this.torqueType = SchemaType.getEnum(torqueType); 240 } 241 242 247 public void replaceType(String value) 248 { 249 this.torqueType = SchemaType.getEnum( 250 StringUtils.defaultString(value, getType().getName())); 251 } 252 253 256 public String getDefaultValue() 257 { 258 return defaultValue; 259 } 260 261 265 public String getDefaultSetting() 266 { 267 StringBuffer dflt = new StringBuffer (0); 268 if (getDefaultValue() != null) 269 { 270 dflt.append("default "); 271 if (TypeMap.isTextType(getType())) 272 { 273 dflt.append('\'').append(getDefaultValue()).append('\''); 275 } 276 else 277 { 278 dflt.append(getDefaultValue()); 279 } 280 } 281 return dflt.toString(); 282 } 283 284 287 public void setDefaultValue(String defaultValue) 288 { 289 this.defaultValue = defaultValue; 290 } 291 292 297 public void replaceDefaultValue(String value) 298 { 299 this.defaultValue = StringUtils.defaultString(value, getDefaultValue()); 300 } 301 302 305 public String getSqlType() 306 { 307 return sqlType; 308 } 309 310 313 public void setSqlType(String sqlType) 314 { 315 this.sqlType = sqlType; 316 } 317 318 324 public String printSize() 325 { 326 if (size != null && scale != null) 327 { 328 return '(' + size + ',' + scale + ')'; 329 } 330 else if (size != null) 331 { 332 return '(' + size + ')'; 333 } 334 else 335 { 336 return ""; 337 } 338 } 339 340 } 341 | Popular Tags |