| 1 | |
package org.apache.torque.engine.database.model; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
import org.apache.commons.lang.StringUtils; |
| 17 | |
import org.apache.torque.engine.platform.Platform; |
| 18 | |
import org.xml.sax.Attributes; |
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
public class Domain { |
| 27 | |
private String name; |
| 28 | |
private String description; |
| 29 | |
private String size; |
| 30 | |
private String scale; |
| 31 | |
|
| 32 | |
private SchemaType torqueType; |
| 33 | |
private String sqlType; |
| 34 | |
private String defaultValue; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public Domain() { |
| 40 | 0 | this.name = null; |
| 41 | 0 | } |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public Domain(String name) { |
| 50 | 0 | this.name = name; |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | 0 | public Domain(SchemaType type) { |
| 57 | 0 | this.name = null; |
| 58 | 0 | this.torqueType = type; |
| 59 | 0 | this.sqlType = type.getName(); |
| 60 | 0 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | 0 | public Domain(SchemaType type, String sqlType) { |
| 66 | 0 | this.name = null; |
| 67 | 0 | this.torqueType = type; |
| 68 | 0 | this.sqlType = sqlType; |
| 69 | 0 | } |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | 0 | public Domain(SchemaType type, String sqlType, String size, String scale) { |
| 75 | 0 | this.name = null; |
| 76 | 0 | this.torqueType = type; |
| 77 | 0 | this.sqlType = sqlType; |
| 78 | 0 | this.size = size; |
| 79 | 0 | this.scale = scale; |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | 0 | public Domain(SchemaType type, String sqlType, String size) { |
| 86 | 0 | this.name = null; |
| 87 | 0 | this.torqueType = type; |
| 88 | 0 | this.sqlType = sqlType; |
| 89 | 0 | this.size = size; |
| 90 | 0 | } |
| 91 | |
|
| 92 | 0 | public Domain(Domain domain) { |
| 93 | 0 | copy(domain); |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
public void copy(Domain domain) { |
| 97 | 0 | this.defaultValue = domain.getDefaultValue(); |
| 98 | 0 | this.description = domain.getDescription(); |
| 99 | 0 | this.name = domain.getName(); |
| 100 | 0 | this.scale = domain.getScale(); |
| 101 | 0 | this.size = domain.getSize(); |
| 102 | 0 | this.sqlType = domain.getSqlType(); |
| 103 | 0 | this.torqueType = domain.getType(); |
| 104 | 0 | } |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public void loadFromXML(Attributes attrib, Platform platform) { |
| 110 | 0 | SchemaType schemaType = SchemaType.getEnum(attrib.getValue("type")); |
| 111 | 0 | copy(platform.getDomainForSchemaType(schemaType)); |
| 112 | |
|
| 113 | 0 | name = attrib.getValue("name"); |
| 114 | |
|
| 115 | 0 | defaultValue = attrib.getValue("default"); |
| 116 | 0 | size = attrib.getValue("size"); |
| 117 | 0 | scale = attrib.getValue("scale"); |
| 118 | |
|
| 119 | 0 | description = attrib.getValue("description"); |
| 120 | 0 | } |
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
public String getDescription() { |
| 126 | 0 | return description; |
| 127 | |
} |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public void setDescription(String description) { |
| 134 | 0 | this.description = description; |
| 135 | 0 | } |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
public String getName() { |
| 141 | 0 | return name; |
| 142 | |
} |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
public void setName(String name) { |
| 149 | 0 | this.name = name; |
| 150 | 0 | } |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
public String getScale() { |
| 156 | 0 | return scale; |
| 157 | |
} |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
public void setScale(String scale) { |
| 164 | 0 | this.scale = scale; |
| 165 | 0 | } |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
public void replaceScale(String value) { |
| 174 | 0 | this.scale = StringUtils.defaultString(value, getScale()); |
| 175 | 0 | } |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public String getSize() { |
| 181 | 0 | return size; |
| 182 | |
} |
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public void setSize(String size) { |
| 189 | 0 | this.size = size; |
| 190 | 0 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
public void replaceSize(String value) { |
| 199 | 0 | this.size = StringUtils.defaultString(value, getSize()); |
| 200 | 0 | } |
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
public SchemaType getType() { |
| 206 | 0 | return torqueType; |
| 207 | |
} |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
public void setType(SchemaType torqueType) { |
| 214 | 0 | this.torqueType = torqueType; |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
public void setType(String torqueType) { |
| 222 | 0 | this.torqueType = SchemaType.getEnum(torqueType); |
| 223 | 0 | } |
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
public void replaceType(String value) { |
| 232 | 0 | this.torqueType = SchemaType.getEnum(StringUtils.defaultString(value, getType().getName())); |
| 233 | 0 | } |
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
public String getDefaultValue() { |
| 239 | 0 | return defaultValue; |
| 240 | |
} |
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
public String getDefaultSetting() { |
| 248 | 0 | StringBuffer dflt = new StringBuffer(0); |
| 249 | 0 | if (getDefaultValue() != null) { |
| 250 | 0 | dflt.append("default "); |
| 251 | 0 | if (TypeMap.isTextType(getType())) { |
| 252 | |
|
| 253 | 0 | dflt.append('\'').append(getDefaultValue()).append('\''); |
| 254 | |
} else { |
| 255 | 0 | dflt.append(getDefaultValue()); |
| 256 | |
} |
| 257 | |
} |
| 258 | 0 | return dflt.toString(); |
| 259 | |
} |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
public void setDefaultValue(String defaultValue) { |
| 266 | 0 | this.defaultValue = defaultValue; |
| 267 | 0 | } |
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
public void replaceDefaultValue(String value) { |
| 276 | 0 | this.defaultValue = StringUtils.defaultString(value, getDefaultValue()); |
| 277 | 0 | } |
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
public String getSqlType() { |
| 283 | 0 | return sqlType; |
| 284 | |
} |
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
public void setSqlType(String sqlType) { |
| 291 | 0 | this.sqlType = sqlType; |
| 292 | 0 | } |
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
public String printSize() { |
| 300 | 0 | if (size != null && scale != null) { |
| 301 | 0 | return '(' + size + ',' + scale + ')'; |
| 302 | 0 | } else if (size != null) { |
| 303 | 0 | return '(' + size + ')'; |
| 304 | |
} else { |
| 305 | 0 | return ""; |
| 306 | |
} |
| 307 | |
} |
| 308 | |
|
| 309 | |
} |