1 22 23 package org.xquark.mapper.mapping; 24 25 import java.util.*; 26 27 import org.xml.sax.SAXException ; 28 import org.xquark.mapper.dbms.AbstractConnection; 29 import org.xquark.mapper.metadata.RepositoryConstants; 30 import org.xquark.schema.SchemaComponent; 31 import org.xquark.schema.SchemaConstants; 32 33 39 public abstract class BaseTableMappingImpl extends MappingImpl 40 implements TableMapping, MappingConstants, RepositoryConstants, SchemaConstants 41 { 42 private static final String RCSRevision = "$Revision: 1.2 $"; 43 private static final String RCSName = "$Name: $"; 44 45 protected ColumnMapping[] primaryKeyColumnMappings; 47 48 53 protected int keyColumnCount = 0; 54 55 56 protected ColumnMapping[] columnMappings; 57 58 61 protected List initialValues; 62 65 protected List finalValues; 66 67 68 protected String name; 69 70 protected RepositoryMapping colMapping; 71 protected int index; 72 73 74 protected TableMetaData tableMetaData; 75 76 protected Collection dependencies = null; 77 78 79 80 protected String insertStatement; 81 protected String joinCondition = ""; 83 protected String columnList = ""; 84 protected String namedColumnList = ""; 85 protected String wildcards = ""; 86 protected String joinColumnList = ""; 87 protected String joinWildcards = ""; 88 protected String joinColumnTypes = ""; 89 90 91 protected ColumnMapping[] updateColumnMappings; 92 protected ColumnMapping[] fetchColumnMappings; 93 protected ColumnMapping[] selectColumnMappings; 94 protected ColumnMapping[] OIDColumnMappings; 95 96 105 protected BaseTableMappingImpl(RepositoryMapping colMapping, SchemaComponent comp, AbstractConnection conn) throws SAXException 106 { 107 super(comp); 108 this.colMapping = colMapping; 109 initialValues = new ArrayList(5); 110 finalValues = new ArrayList(3); 111 } 112 113 116 117 public String toString() 118 { 119 return name; 120 132 } 133 134 138 public boolean equals(Object o) 139 { 140 boolean ret = false; 141 if (o instanceof TableMapping) 142 ret = (((TableMapping)o).getTableIndex() == getTableIndex()); 143 return ret; 144 } 145 148 public int hashCode() 149 { 150 return getTableName().hashCode(); 151 } 152 153 154 156 public int getColumnCount() 157 { 158 return columnMappings.length; 159 } 160 161 protected Iterator getColumnMappingIterator() 163 { 164 return new Iterator() 165 { 166 private int next = 0; 167 public boolean hasNext() 168 { 169 while (next < columnMappings.length && columnMappings[next] == null) 170 next++; 171 return next < columnMappings.length && columnMappings[next] != null; 172 } 173 174 public Object next() 175 { 176 ColumnMapping ret = null; 177 if (hasNext()) 178 ret = columnMappings[next++]; 179 return ret; 180 } 181 182 public void remove() 183 { 184 throw new UnsupportedOperationException (); 185 } 186 }; 187 } 188 189 public ColumnMapping getColumnMapping(String columnName) 190 { 191 Iterator it = getColumnMappingIterator(); 192 ColumnMappingImpl column; 193 while (it.hasNext()) 194 { 195 column = (ColumnMappingImpl)it.next(); 196 if (column.getColumnName().equalsIgnoreCase(columnName)) return column; } 198 return null; 199 } 200 201 public ColumnMapping getColumnMapping(int index) 202 { 203 return columnMappings[index]; 204 } 205 206 public ColumnMapping[] getPrimaryKey() 207 { 208 return this.primaryKeyColumnMappings; 209 } 210 211 public int getKeyColumnCount() 212 { return keyColumnCount;} 213 214 public List initParameters() 215 { return initialValues;} 216 217 public List finalParameters() 218 { return finalValues;} 219 220 public String getTableName() 221 { 222 return name; 223 } 224 225 public RepositoryMapping getRepositoryMapping() 226 { 227 return colMapping; 228 } 229 230 public TableMetaData getMetaData() 231 { 232 return tableMetaData; 233 } 234 235 public int getTableIndex() 236 { 237 return index; 238 } 239 240 public void setIndex(int index) 241 { 242 this.index = index; 243 } 244 245 249 public String getPathIDColumnName() 250 { 251 return "path"; } 253 254 258 public String getUOIDColumnName() 259 { 260 return "uoid"; } 262 263 public String getJoinCondition() 264 { 265 return joinCondition; 266 } 267 public String getColumnList() 268 { 269 return columnList; 270 } 271 public String getNamedColumnList() 272 { 273 return namedColumnList; 274 } 275 public String getWildcards() 276 { 277 return wildcards; 278 } 279 public String getJoinColumnList() 280 { 281 return joinColumnList; 282 } 283 public String getJoinWildcards() 284 { 285 return joinWildcards; 286 } 287 public String getJoinColumnTypes() 288 { 289 return joinColumnTypes; 290 } 291 292 public Collection getDependencies() 293 { 294 return dependencies; 295 } 296 297 public ColumnMapping[] getUpdateColumns() 298 { 299 return updateColumnMappings; 300 } 301 302 public ColumnMapping[] getFetchColumns() 303 { 304 return fetchColumnMappings; 305 } 306 307 public ColumnMapping[] getJoinColumns() 308 { 309 return OIDColumnMappings; 310 } 311 312 public ColumnMapping[] getSelectColumns() 313 { 314 return selectColumnMappings; 315 } 316 317 public boolean isShareable() 318 { 319 return tableMetaData.areStatementsShareable(); 320 } 321 322 public boolean isTableShared() 323 { 324 return tableMetaData.isShared(); 325 } 326 327 335 void addToInitialValues(ColumnMapping mapping) 336 { 337 initialValues.add(mapping); 338 } 339 340 345 void addToFinalValues(ColumnMapping mapping) 346 { 347 finalValues.add(mapping); 348 } 349 350 void setStatementsNotShareable() 351 { 352 tableMetaData.setStatementsNotShareable(); 353 } 354 355 void setTableShared() 356 { 357 tableMetaData.setShared(); 358 } 359 360 364 public String getInsertStatement() 365 { 366 return insertStatement; 367 } 368 369 public TableMapping getTableMapping() 370 { 371 return this; 372 } 373 } 374 | Popular Tags |