1 21 package oracle.toplink.essentials.internal.helper; 23 24 import java.io.*; 25 import java.util.Vector ; 26 import java.util.Collection ; 27 import oracle.toplink.essentials.internal.databaseaccess.*; 28 29 38 public class DatabaseTable implements Cloneable , Serializable { 39 protected String name; 40 protected String tableQualifier; 41 protected String qualifiedName; 42 protected Vector uniqueConstraints; 43 44 48 public DatabaseTable() { 49 this("", ""); 50 } 51 52 public DatabaseTable(String possiblyQualifiedName) { 53 setPossiblyQualifiedName(possiblyQualifiedName); 54 uniqueConstraints = new Vector (); 55 } 56 57 public DatabaseTable(String tableName, String qualifier) { 58 this.name = tableName; 59 this.tableQualifier = qualifier; 60 uniqueConstraints = new Vector (); 61 } 62 63 66 public void addUniqueConstraint(String columnName) { 67 uniqueConstraints.add(columnName); 68 } 69 70 73 public void addUniqueConstraints(String [] columnNames) { 74 uniqueConstraints.add(columnNames); 75 } 76 77 82 public Object clone() { 83 try { 84 return super.clone(); 85 } catch (CloneNotSupportedException exception) { 86 } 87 88 return null; 89 } 90 91 96 public boolean equals(Object object) { 97 if (object instanceof DatabaseTable) { 98 return equals((DatabaseTable)object); 99 } 100 return false; 101 } 102 103 108 public boolean equals(DatabaseTable table) { 109 if (this == table) { 110 return true; 111 } 112 if (DatabasePlatform.shouldIgnoreCaseOnFieldComparisons()) { 113 if (getName().equalsIgnoreCase(table.getName())) { 114 if ((getTableQualifier().length() == 0) || (table.getTableQualifier().length() == 0) || (getTableQualifier().equalsIgnoreCase(table.getTableQualifier()))) { 115 return true; 116 } 117 } 118 } else { 119 if (getName().equals(table.getName())) { 120 if ((getTableQualifier().length() == 0) || (table.getTableQualifier().length() == 0) || (getTableQualifier().equals(table.getTableQualifier()))) { 121 return true; 122 } 123 } 124 } 125 126 return false; 127 } 128 129 132 public String getName() { 133 return name; 134 } 135 136 public String getQualifiedName() { 137 if (qualifiedName == null) { 138 if (tableQualifier.equals("")) { 139 qualifiedName = getName(); 140 } else { 141 qualifiedName = getTableQualifier() + "." + getName(); 142 } 143 } 144 145 return qualifiedName; 146 } 147 148 public String getTableQualifier() { 149 return tableQualifier; 150 } 151 152 156 public Vector getUniqueConstraints() { 157 return uniqueConstraints; 158 } 159 160 163 public int hashCode() { 164 return getName().hashCode(); 165 } 166 167 171 public boolean hasName() { 172 if ((getName().length() == 0) && (getTableQualifier().length() == 0)) { 173 return false; 174 } 175 176 return true; 177 } 178 179 185 public boolean isDecorated() { 186 return false; 187 } 188 189 protected void resetQualifiedName() { 190 this.qualifiedName = null; 191 } 192 193 199 public void setName(String name) { 200 this.name = name; 201 resetQualifiedName(); 202 } 203 204 211 public void setPossiblyQualifiedName(String possiblyQualifiedName) { 212 resetQualifiedName(); 213 214 int index = possiblyQualifiedName.lastIndexOf('.'); 215 216 if (index == -1) { 217 this.name = possiblyQualifiedName; 218 this.tableQualifier = ""; 219 } else { 220 this.name = possiblyQualifiedName.substring(index + 1, possiblyQualifiedName.length()); 221 this.tableQualifier = possiblyQualifiedName.substring(0, index); 222 } 223 } 224 225 public void setTableQualifier(String qualifier) { 226 this.tableQualifier = qualifier; 227 resetQualifiedName(); 228 } 229 230 public String toString() { 231 return "DatabaseTable(" + getQualifiedName() + ")"; 232 } 233 } 234 | Popular Tags |