1 21 package oracle.toplink.essentials.internal.helper; 23 24 import java.io.*; 25 import oracle.toplink.essentials.internal.databaseaccess.*; 26 27 36 public class DatabaseField implements Cloneable , Serializable { 37 38 protected int scale; 39 protected int length; 40 protected int precision; 41 protected boolean isUnique; 42 protected boolean isNullable; 43 protected boolean isUpdatable; 44 protected boolean isInsertable; 45 protected String columnDefinition; 46 47 48 protected String name; 49 50 51 protected DatabaseTable table; 52 53 54 public transient Class type; 55 56 60 public int sqlType; 61 62 63 protected int index; 64 65 public DatabaseField() { 66 this("", new DatabaseTable()); 67 } 68 69 public DatabaseField(String qualifiedName) { 70 this.index = -1; 71 this.sqlType = -1; 72 int index = qualifiedName.lastIndexOf('.'); 73 74 if (index == -1) { 75 this.name = qualifiedName; 76 this.table = new DatabaseTable(); 77 } else { 78 this.name = qualifiedName.substring(index + 1, qualifiedName.length()); 79 this.table = new DatabaseTable(qualifiedName.substring(0, index)); 80 } 81 82 initDDLFields(); 83 } 84 85 public DatabaseField(String fieldName, String tableName) { 86 this(fieldName, new DatabaseTable(tableName)); 87 } 88 89 public DatabaseField(String fieldName, DatabaseTable databaseTable) { 90 this.index = -1; 91 this.sqlType = -1; 92 this.name = fieldName; 93 this.table = databaseTable; 94 initDDLFields(); 95 } 96 97 101 public void initDDLFields() { 102 scale = 0; 103 length = 255; 104 precision = 0; 105 isUnique = false; 106 isNullable = true; 107 isUpdatable = true; 108 isInsertable = true; 109 columnDefinition = ""; 110 } 111 112 115 public Object clone() { 116 try { 117 return super.clone(); 118 } catch (CloneNotSupportedException exception) { 119 } 120 121 return null; 122 } 123 124 130 public boolean equals(DatabaseField field) { 131 if (this == field) { 132 return true; 133 } 134 135 if (field != null) { 136 if (DatabasePlatform.shouldIgnoreCaseOnFieldComparisons()) { 137 if (getName().equalsIgnoreCase(field.getName())) { 138 if ((getTableName().length() == 0) || (field.getTableName().length() == 0)) { 139 return true; 140 } 141 return (getTable().equals(field.getTable())); 142 } 143 } else { 144 if (getName().equals(field.getName())) { 145 if ((getTableName().length() == 0) || (field.getTableName().length() == 0)) { 146 return true; 147 } 148 return (getTable().equals(field.getTable())); 149 } 150 } 151 } 152 153 return false; 154 } 155 156 162 public boolean equals(Object object) { 163 if (!(object instanceof DatabaseField)) { 164 return false; 165 } 166 167 return equals((DatabaseField)object); 168 } 169 170 173 public String getColumnDefinition() { 174 return this.columnDefinition; 175 } 176 177 181 public int getIndex() { 182 return index; 183 } 184 185 188 public int getLength() { 189 return this.length; 190 } 191 192 195 public String getName() { 196 return name; 197 } 198 199 202 public int getPrecision() { 203 return this.precision; 204 } 205 206 209 public String getQualifiedName() { 210 if (hasTableName()) { 211 return getTable().getQualifiedName() + "." + getName(); 212 } else { 213 return getName(); 214 } 215 } 216 217 220 public int getScale() { 221 return this.scale; 222 } 223 224 231 public int getSqlType() { 232 return sqlType; 233 } 234 235 238 public DatabaseTable getTable() { 239 return table; 240 } 241 242 245 public String getTableName() { 246 return getTable().getName(); 247 } 248 249 252 public Class getType() { 253 return type; 254 } 255 256 259 public int hashCode() { 260 return getName().hashCode(); 261 } 262 263 public boolean hasTableName() { 264 if (getTable() == null) { 265 return false; 266 } 267 if (getTable().getName() == null) { 268 return false; 269 } 270 return !(getTable().getName().equals("")); 271 } 272 273 277 public boolean isInsertable() { 278 return this.isInsertable; 279 } 280 281 285 public boolean isNullable() { 286 return this.isNullable; 287 } 288 289 292 public boolean isUnique() { 293 return this.isUnique; 294 } 295 296 299 public boolean isReadOnly() { 300 return (! isUpdatable && ! isInsertable); 301 } 302 303 307 public boolean isUpdatable() { 308 return this.isUpdatable; 309 } 310 311 314 public void resetQualifiedName(String qualifiedName) { 315 setIndex(-1); 316 int index = qualifiedName.lastIndexOf('.'); 317 318 if (index == -1) { 319 setName(qualifiedName); 320 getTable().setName(""); 321 getTable().setTableQualifier(""); 322 } else { 323 setName(qualifiedName.substring(index + 1, qualifiedName.length())); 324 getTable().setPossiblyQualifiedName(qualifiedName.substring(0, index)); 325 } 326 } 327 328 331 public void setColumnDefinition(String columnDefinition) { 332 this.columnDefinition = columnDefinition; 333 } 334 335 339 public void setIndex(int index) { 340 this.index = index; 341 } 342 343 347 public void setInsertable(boolean isInsertable) { 348 this.isInsertable = isInsertable; 349 } 350 351 354 public void setLength(int length) { 355 this.length = length; 356 } 357 358 361 public void setName(String name) { 362 this.name = name; 363 } 364 365 369 public void setNullable(boolean isNullable) { 370 this.isNullable = isNullable; 371 } 372 373 376 public void setPrecision(int precision) { 377 this.precision = precision; 378 } 379 380 383 public void setScale(int scale) { 384 this.scale = scale; 385 } 386 387 394 public void setSqlType(int sqlType) { 395 this.sqlType = sqlType; 396 } 397 398 401 public void setTable(DatabaseTable table) { 402 this.table = table; 403 } 404 405 408 public void setTableName(String tableName) { 409 setTable(new DatabaseTable(tableName)); 410 } 411 412 417 public void setType(Class type) { 418 this.type = type; 419 } 420 421 424 public void setUnique(boolean isUnique) { 425 this.isUnique = isUnique; 426 } 427 428 432 public void setUpdatable(boolean isUpdatable) { 433 this.isUpdatable = isUpdatable; 434 } 435 436 public String toString() { 437 return this.getQualifiedName(); 438 } 439 } 440 | Popular Tags |