1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 25 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 27 28 import org.apache.derby.iapi.error.StandardException; 29 30 import org.apache.derby.iapi.services.sanity.SanityManager; 31 32 import org.apache.derby.iapi.reference.Property; 33 import org.apache.derby.iapi.reference.SQLState; 34 35 42 43 public class TableName extends QueryTreeNode 44 { 45 48 String tableName; 49 String schemaName; 50 private boolean hasSchema; 51 52 58 59 public void init(Object schemaName, Object tableName) 60 { 61 hasSchema = schemaName != null; 62 this.schemaName = (String ) schemaName; 63 this.tableName = (String ) tableName; 64 } 65 66 76 public void init 77 ( 78 Object schemaName, 79 Object tableName, 80 Object tokBeginOffset, 81 Object tokEndOffset 82 ) 83 { 84 init(schemaName, tableName); 85 this.setBeginOffset(((Integer ) tokBeginOffset).intValue()); 86 this.setEndOffset(((Integer ) tokEndOffset).intValue()); 87 } 88 89 94 95 public String getTableName() 96 { 97 return tableName; 98 } 99 100 105 106 public boolean hasSchema(){ 107 return hasSchema; 108 } 109 110 115 116 public String getSchemaName() 117 { 118 return schemaName; 119 } 120 121 126 127 public void setSchemaName(String schemaName) 128 { 129 this.schemaName = schemaName; 130 } 131 132 138 139 public String getFullTableName() 140 { 141 if (schemaName != null) 142 return schemaName + "." + tableName; 143 else 144 return tableName; 145 } 146 147 153 154 public String toString() 155 { 156 if (hasSchema) 157 return getFullTableName(); 158 else 159 return tableName; 160 } 161 162 172 public boolean equals(TableName otherTableName) 173 { 174 if( otherTableName == null) 175 return false; 176 177 String fullTableName = getFullTableName(); 178 if (fullTableName == null) 179 { 180 return true; 181 } 182 else if ((schemaName == null) || 183 (otherTableName.getSchemaName() == null)) 184 { 185 return tableName.equals(otherTableName.getTableName()); 186 } 187 else 188 { 189 return fullTableName.equals(otherTableName.getFullTableName()); 190 } 191 } 192 193 204 public boolean equals(String otherSchemaName, String otherTableName) 205 { 206 String fullTableName = getFullTableName(); 207 if (fullTableName == null) 208 { 209 return true; 210 } 211 else if ((schemaName == null) || 212 (otherSchemaName == null)) 213 { 214 return tableName.equals(otherTableName); 215 } 216 else 217 { 218 return fullTableName.equals(otherSchemaName+"."+otherTableName); 219 } 220 } 221 222 228 236 public void bind( DataDictionary dataDictionary ) 237 throws StandardException 238 { 239 schemaName = getSchemaDescriptor(schemaName).getSchemaName(); 240 } 241 242 248 254 public int hashCode() 255 { 256 return getFullTableName().hashCode(); 257 } 258 259 264 public boolean equals( Object other ) 265 { 266 if ( !( other instanceof TableName ) ) { return false; } 267 268 TableName that = (TableName) other; 269 270 return this.getFullTableName().equals( that.getFullTableName() ); 271 } 272 273 } 274 | Popular Tags |