1 19 20 package org.netbeans.modules.dbschema; 21 22 import java.sql.Types ; 23 24 import org.netbeans.modules.dbschema.util.SQLTypeUtil; 25 26 28 public class ColumnElement extends DBMemberElement { 29 31 public ColumnElement () { 32 this(new Memory(), null); 33 } 34 35 39 public ColumnElement (Impl impl, TableElement declaringTable) { 40 super(impl, declaringTable); 41 } 42 43 47 public boolean equals(Object obj) { 48 Integer iThis, iArg; 49 50 if(!(obj instanceof ColumnElement)) 51 return false; 52 53 ColumnElement ce = (ColumnElement) obj; 54 if(!getName().getFullName().equals(ce.getName().getFullName())) 55 return false; 56 57 if(getType() != ce.getType()) 58 return false; 59 60 if(isNullable() != ce.isNullable()) 61 return false; 62 63 iThis = getLength(); 65 iArg = ce.getLength(); 66 if (iThis != null ^ iArg != null) 67 return false; 69 70 if (iThis != null && iArg != null && iThis.compareTo(iArg) != 0) 71 return false; 73 74 iThis = getScale(); 76 iArg = ce.getScale(); 77 if (iThis != null ^ iArg != null) 78 return false; 80 81 if (iThis != null && iArg != null && iThis.compareTo(iArg) != 0) 82 return false; 84 85 iThis = getPrecision(); 87 iArg = ce.getPrecision(); 88 if (iThis != null ^ iArg != null) 89 return false; 91 92 if (iThis != null && iArg != null && iThis.compareTo(iArg) != 0) 93 return false; 95 96 return true; 97 } 98 99 102 public Object clone () { 103 return new ColumnElement(new Memory(this), null); 104 } 105 106 109 final Impl getColumnImpl() { 110 return (Impl)getElementImpl(); 111 } 112 113 116 public int getType () { 117 return getColumnImpl().getType(); 118 } 119 120 124 public void setType (int type) throws DBException { 125 getColumnImpl().setType(type); 126 } 127 128 130 133 public boolean isNumericType () { 134 return SQLTypeUtil.isNumeric(getType()); 135 } 136 137 140 public boolean isCharacterType () { 141 return SQLTypeUtil.isCharacter(getType()); 142 } 143 144 147 public boolean isBlobType () { 148 return SQLTypeUtil.isBlob(getType()); 149 } 150 152 155 public boolean isNullable () { 156 return getColumnImpl().isNullable(); 157 } 158 159 163 public void setNullable (boolean flag) throws DBException { 164 getColumnImpl().setNullable(flag); 165 } 166 167 171 public Integer getLength () { 172 if (isCharacterType() || isBlobType()) 173 return getColumnImpl().getLength(); 174 else 175 return null; 176 } 177 178 182 public void setLength (Integer length) throws DBException { 183 if (isCharacterType() || isBlobType()) 184 getColumnImpl().setLength(length); 185 } 186 187 191 public Integer getPrecision () { 192 if (isNumericType()) 193 return getColumnImpl().getPrecision(); 194 else 195 return null; 196 } 197 198 202 public void setPrecision (Integer precision) throws DBException { 203 if (isNumericType()) 204 getColumnImpl().setPrecision(precision); 205 } 206 207 211 public Integer getScale () { 212 if (isNumericType()) 213 return getColumnImpl().getScale(); 214 else 215 return null; 216 } 217 218 222 public void setScale (Integer scale) throws DBException { 223 if (isNumericType()) 224 getColumnImpl().setScale(scale); 225 } 226 227 230 public String toString() { 231 return getName().toString(); 232 } 233 234 237 public interface Impl extends DBMemberElement.Impl { 238 241 public int getType (); 242 243 247 public void setType (int type) throws DBException; 248 249 252 public boolean isNullable (); 253 254 258 public void setNullable (boolean flag) throws DBException; 259 260 264 public Integer getLength (); 265 266 270 public void setLength (Integer length) throws DBException; 271 272 276 public Integer getPrecision (); 277 278 282 public void setPrecision (Integer precision) throws DBException; 283 284 288 public Integer getScale (); 289 290 294 public void setScale (Integer scale) throws DBException; 295 } 296 297 static class Memory extends DBMemberElement.Memory implements Impl { 298 299 private int _type; 300 301 302 private boolean _nullable; 303 304 305 private Integer _length; 306 307 308 private Integer _precision; 309 310 311 private Integer _scale; 312 313 315 Memory () { 316 super(); 317 _type = Types.NULL; 318 } 319 320 323 Memory (ColumnElement column) { 324 super(column); 325 _type = column.getType(); 326 _nullable = column.isNullable(); 327 _length = column.getLength(); 328 _precision = column.getPrecision(); 329 _scale = column.getScale(); 330 } 331 332 335 public int getType () { 336 return _type; 337 } 338 339 342 public void setType (int type) { 343 int old = _type; 344 345 _type = type; 346 firePropertyChange (PROP_TYPE, new Integer (old), new Integer (type)); 347 } 348 349 352 public boolean isNullable () { 353 return _nullable; 354 } 355 356 360 public void setNullable (boolean flag) throws DBException { 361 boolean old = _nullable; 362 363 _nullable = flag; 364 firePropertyChange (PROP_NULLABLE, Boolean.valueOf(old), Boolean.valueOf(flag)); 365 } 366 367 371 public Integer getLength () { 372 return _length; 373 } 374 375 379 public void setLength (Integer length) throws DBException { 380 Integer old = _length; 381 382 _length = length; 383 firePropertyChange (PROP_LENGTH, old, length); 384 } 385 386 390 public Integer getPrecision () { 391 return _precision; 392 } 393 394 398 public void setPrecision (Integer precision) throws DBException { 399 Integer old = _precision; 400 401 _precision = precision; 402 firePropertyChange (PROP_PRECISION, old, precision); 403 } 404 405 409 public Integer getScale () { 410 return _scale; 411 } 412 413 417 public void setScale (Integer scale) throws DBException { 418 Integer old = _scale; 419 420 _scale = scale; 421 firePropertyChange (PROP_SCALE, old, scale); 422 } 423 } 424 } 425 | Popular Tags |