| 1 21 22 package org.webdocwf.util.loader; 23 24 import java.util.Hashtable ; 25 import java.util.Enumeration ; 26 import java.util.Vector ; 27 import org.w3c.dom.Document ; 28 import org.w3c.dom.NodeList ; 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.NamedNodeMap ; 32 import java.sql.Connection ; 33 import java.math.BigDecimal ; 34 import java.sql.Statement ; 35 import java.sql.SQLException ; 36 import java.sql.ResultSet ; 37 import org.webdocwf.util.loader.logging.Logger; 38 39 43 public class CounterColumns { 44 45 private String counterTableName = null; 46 private String counterNameColumn = null; 47 private String counterValueColumn = null; 48 49 private Hashtable counterName; 50 private Hashtable counterStartValue; 51 private Hashtable counterIncrement; 52 private Hashtable targetColumnName; 53 private Hashtable valueMode; 54 private Hashtable counterStartValueReset; 55 private Hashtable targetColumnTyp; 56 57 private Hashtable subCounterName; 59 private Hashtable subCounterStartValue; 60 private Hashtable subCounterIncrement; 61 private Hashtable subTargetColumnName; 62 private Hashtable subValueMode; 63 private Hashtable subCounterKeyColumns; 64 private Hashtable subCounterKeyValues; 65 private Hashtable subCounterKeyColumnsTyp; 66 private Hashtable subTargetColumnTyp; 67 68 private Vector vecCounterName = new Vector (); 69 private Vector vecCounterIncrement = new Vector (); 70 private Vector vecCounterStartValue = new Vector (); 71 private Vector vecTargetColumnName = new Vector (); 72 private Vector vecValueMode = new Vector (); 73 private Vector vecCounterStartValueReset = new Vector (); 74 private Vector vecTargetTableName = new Vector (); 75 private Vector vecTargetTableID = new Vector (); 76 77 private Vector vecSubCounterName = new Vector (); 78 private Vector vecSubCounterIncrement = new Vector (); 79 private Vector vecSubCounterStartValue = new Vector (); 80 private Vector vecSubTargetTableName = new Vector (); 81 private Vector vecSubTargetTableID = new Vector (); 82 private Vector vecSubTargetColumnName = new Vector (); 83 private Vector vecSubValueMode = new Vector (); 84 private Vector vecSubKeyColumns = new Vector (); 85 private Vector vecSubKeyColumnsTyp = new Vector (); 86 87 private Hashtable currentCounterValue; 88 89 private Hashtable subCounterCache = new Hashtable (); 91 private Logger logger; 92 93 96 public CounterColumns() { 97 98 this.counterTableName = null; 99 this.counterNameColumn = null; 100 this.counterValueColumn = null; 101 this.counterName = new Hashtable (); 102 this.counterStartValue = new Hashtable (); 103 this.counterIncrement = new Hashtable (); 104 this.targetColumnName = new Hashtable (); 105 this.targetColumnTyp = new Hashtable (); 106 this.valueMode = new Hashtable (); 107 this.counterStartValueReset = new Hashtable (); 108 109 this.subCounterName = new Hashtable (); 110 this.subCounterStartValue = new Hashtable (); 111 this.subCounterIncrement = new Hashtable (); 112 this.subTargetColumnName = new Hashtable (); 113 this.subValueMode = new Hashtable (); 114 this.subCounterKeyColumns = new Hashtable (); 115 this.subCounterKeyValues = new Hashtable (); 116 this.subCounterKeyColumnsTyp = new Hashtable (); 117 this.subTargetColumnTyp = new Hashtable (); 118 119 this.vecCounterName = new Vector (); 120 this.vecCounterIncrement = new Vector (); 121 this.vecCounterStartValue = new Vector (); 122 this.vecTargetColumnName = new Vector (); 123 this.vecValueMode = new Vector (); 124 this.vecCounterStartValueReset = new Vector (); 125 this.vecTargetTableName = new Vector (); 126 this.vecTargetTableID = new Vector (); 127 this.currentCounterValue = new Hashtable (); 128 129 this.vecSubCounterName = new Vector (); 130 this.vecSubCounterIncrement = new Vector (); 131 this.vecSubCounterStartValue = new Vector (); 132 this.vecSubTargetTableName = new Vector (); 133 this.vecSubTargetTableID = new Vector (); 134 this.vecSubTargetColumnName = new Vector (); 135 this.vecSubValueMode = new Vector (); 136 this.vecSubKeyColumns = new Vector (); 137 this.vecSubKeyColumnsTyp = new Vector (); 138 } 139 140 143 public void setLogger(Logger logger) { 144 this.logger = logger; 145 } 146 147 151 public String getCounterTableName() { 152 return this.counterTableName; 153 } 154 155 159 public String getCounterValueColumn() { 160 return this.counterValueColumn; 161 } 162 163 167 public String getCounterNameColumn() { 168 return this.counterNameColumn; 169 } 170 171 175 public void setCounterNameColumn(String nameColumn) { 176 this.counterNameColumn = nameColumn; 177 } 178 179 183 public void setCounterValueColumn(String valueColumn) { 184 this.counterValueColumn = valueColumn; 185 } 186 187 191 public void setCounterTableName(String tableName) { 192 this.counterTableName = tableName; 193 } 194 195 201 public void readConstantColumnAttributes(Document doc, int importJob) { 202 this.counterTableName = importAttributeValue(doc, "counterColumns", "counterTableName", 203 importJob); 204 this.counterNameColumn = importAttributeValue(doc, "counterColumns", "counterNameColumn", 205 importJob); 206 this.counterValueColumn = importAttributeValue(doc, "counterColumns", "counterValueColumn", 207 importJob); 208 } 209 210 220 public void readConstantColumnsParameters(Document doc, int importJob) { 221 this.vecCounterName = importValue(doc, "counterColumn", "counterName", importJob, null); 222 this.vecCounterIncrement = importValue(doc, "counterColumn", "counterIncrement", importJob, "1"); 223 this.vecCounterStartValue = importValue(doc, "counterColumn", "counterStartValue", importJob, 224 "0"); 225 this.vecTargetColumnName = importValue(doc, "counterColumn", "targetColumnName", importJob, null); 226 this.vecValueMode = importValue(doc, "counterColumn", "valueMode", importJob, "setIfCreated"); 227 this.vecCounterStartValueReset = importValue(doc, "counterColumn", "counterStartValueReset", 228 importJob, (new Boolean (false)).toString()); 229 this.vecTargetTableName = importValue(doc, "counterColumn", "targetTableName", importJob, null); 230 this.vecTargetTableID = importValue(doc, "counterColumn", "targetTableID", importJob, null); 231 232 this.vecSubCounterName = importValue(doc, "subCounterColumn", "counterName", importJob, null); 233 this.vecSubCounterIncrement = importValue(doc, "subCounterColumn", "counterIncrement", 234 importJob, "1"); 235 this.vecSubCounterStartValue = importValue(doc, "subCounterColumn", "counterStartValue", 236 importJob, "0"); 237 this.vecSubTargetTableName = importValue(doc, "subCounterColumn", "targetTableName", importJob, null); 238 this.vecSubTargetTableID = importValue(doc, "subCounterColumn", "targetTableID", importJob, null); 239 this.vecSubTargetColumnName = importValue(doc, "subCounterColumn", "targetColumnName", 240 importJob, null); 241 this.vecSubValueMode = importValue(doc, "subCounterColumn", "valueMode", importJob, 242 "setIfCreated"); 243 244 for (int i = 0; i < this.vecSubCounterName.size(); i++) { 245 this.vecSubKeyColumns.addElement(importSubCounterKeyValue(doc, "keyColumnName", importJob, i)); 246 } 247 248 } 249 250 255 public void setConstantColumnsParameters(String tableName, String tableID) { 256 257 Vector targetCounterName = new Vector (); 258 Vector targetCounterIncrement = new Vector (); 259 Vector targetCounterStartValue = new Vector (); 260 Vector targetTargetColumnName = new Vector (); 261 Vector targetValueMode = new Vector (); 262 Vector targetCounterStartValueReset = new Vector (); 263 264 Vector targetSubCounterName = new Vector (); 265 Vector targetSubCounterIncrement = new Vector (); 266 Vector targetSubCounterStartValue = new Vector (); 267 Vector targetSubTargetColumnName = new Vector (); 268 Vector targetSubValueMode = new Vector (); 269 Vector targetSubKeyColumns = new Vector (); 270 Vector subKeyColumnsKey = new Vector (); 271 272 for (int i = 0; i < this.vecTargetTableName.size(); i++) { 273 if (tableName.equalsIgnoreCase(this.vecTargetTableName.get(i).toString()) && 274 tableID.equalsIgnoreCase(this.vecTargetTableID.get(i).toString())) { 275 if (this.vecCounterName.get(i) != null) 276 targetCounterName.addElement(this.vecCounterName.get(i).toString()); 277 else 278 targetCounterName.addElement(null); 279 280 if (this.vecCounterStartValue.get(i) != null) 281 targetCounterStartValue.addElement(this.vecCounterStartValue.get(i).toString()); 282 else 283 targetCounterStartValue.addElement(null); 284 285 if (this.vecCounterIncrement.get(i) != null) 286 targetCounterIncrement.addElement(this.vecCounterIncrement.get(i).toString()); 287 else 288 targetCounterIncrement.addElement(null); 289 290 if (this.vecTargetColumnName.get(i) != null) 291 targetTargetColumnName.addElement(this.vecTargetColumnName.get(i).toString()); 292 else 293 targetTargetColumnName.addElement(null); 294 295 if (this.vecValueMode.get(i) != null) 296 targetValueMode.addElement(this.vecValueMode.get(i).toString()); 297 else 298 targetValueMode.addElement(null); 299 300 if (this.vecCounterStartValueReset.get(i) != null) 301 targetCounterStartValueReset.addElement(this.vecCounterStartValueReset.get(i).toString()); 302 else 303 targetCounterStartValueReset.addElement(null); 304 305 } 307 } 308 for (int i = 0; i < this.vecSubTargetTableName.size(); i++) { 309 if (tableName.equalsIgnoreCase(this.vecSubTargetTableName.get(i).toString()) && 310 tableID.equalsIgnoreCase(this.vecSubTargetTableID.get(i).toString())) { 311 if (this.vecSubCounterName.get(i) != null) { 312 targetSubCounterName.addElement(this.vecSubCounterName.get(i).toString()); 313 } else 314 targetSubCounterName.addElement(null); 315 if (this.vecSubCounterStartValue.get(i) != null) 316 targetSubCounterStartValue.addElement(this.vecSubCounterStartValue.get(i).toString()); 317 else 318 targetSubCounterStartValue.addElement(null); 319 if (this.vecSubCounterIncrement.get(i) != null) 320 targetSubCounterIncrement.addElement(this.vecSubCounterIncrement.get(i).toString()); 321 else 322 targetSubCounterIncrement.addElement(null); 323 if (this.vecSubTargetColumnName.get(i) != null) 324 targetSubTargetColumnName.addElement(this.vecSubTargetColumnName.get(i).toString()); 325 else 326 targetSubTargetColumnName.addElement(null); 327 if (this.vecSubValueMode.get(i) != null) 328 targetSubValueMode.addElement(this.vecSubValueMode.get(i).toString()); 329 else 330 targetSubValueMode.addElement(null); 331 if (this.vecSubKeyColumns.get(i) != null) 332 targetSubKeyColumns.addElement(this.vecSubKeyColumns.get(i)); 333 else 334 targetSubKeyColumns.addElement(null); 335 336 } 337 } 338 this.counterName.put(tableName + "_" + tableID, targetCounterName); 339 this.counterIncrement.put(tableName + "_" + tableID, targetCounterIncrement); 340 this.counterStartValue.put(tableName + "_" + tableID, targetCounterStartValue); 341 this.targetColumnName.put(tableName + "_" + tableID, targetTargetColumnName); 342 this.valueMode.put(tableName + "_" + tableID, targetValueMode); 343 this.counterStartValueReset.put(tableName + "_" + tableID, targetCounterStartValueReset); 344 345 this.subCounterName.put(tableName + "_" + tableID, targetSubCounterName); 347 this.subCounterIncrement.put(tableName + "_" + tableID, targetSubCounterIncrement); 348 this.subCounterStartValue.put(tableName + "_" + tableID, targetSubCounterStartValue); 349 this.subTargetColumnName.put(tableName + "_" + tableID, targetSubTargetColumnName); 350 this.subValueMode.put(tableName + "_" + tableID, targetSubValueMode); 351 this.subCounterKeyColumns.put(tableName + "_" + tableID, targetSubKeyColumns); 352 353 } 354 355 private int getVectorsSize() { 356 if (this.vecCounterName != null) 357 return this.vecCounterName.size(); 358 else 359 return 0; 360 } 361 362 368 public Vector getCounterName(String tableName, String tableID) { 369 return (Vector )this.counterName.get(tableName + "_" + tableID); 370 } 371 372 378 public Vector getCounterIncrement(String tableName, String tableID) { 379 return (Vector )this.counterIncrement.get(tableName + "_" + tableID); 380 } 381 382 388 public Vector getCounterStartValue(String tableName, String tableID) { 389 return (Vector )this.counterStartValue.get(tableName + "_" + tableID); 390 } 391 392 398 public Vector getTargetColumnName(String tableName, String tableID) { 399 return (Vector )this.targetColumnName.get(tableName + "_" + tableID); 400 401 } 402 403 409 public Vector getTargetColumnTyp(String tableName, String tableID) { 410 return (Vector )this.targetColumnTyp.get(tableName + "_" + tableID); 411 412 } 413 414 420 public Vector getValueMode(String tableName, String tableID) { 421 return (Vector )this.valueMode.get(tableName + "_" + tableID); 422 } 423 424 430 public Vector getCounterStartValueReset(String tableName, String tableID) { 431 return (Vector )this.counterStartValueReset.get(tableName + "_" + tableID); 432 } 433 434 441 public Vector getSubCounterName(String tableName, String tableID) { 442 return (Vector )this.subCounterName.get(tableName + "_" + tableID); 443 } 444 445 451 public Vector getSubCounterIncrement(String tableName, String tableID) { 452 return (Vector )this.subCounterIncrement.get(tableName + "_" + tableID); 453 } 454 455 461 public Vector getSubCounterStartValue(String tableName, String tableID) { 462 return (Vector )this.subCounterStartValue.get(tableName + "_" + tableID); 463 } 464 465 471 public Vector getSubTargetColumnName(String tableName, String tableID) { 472 return (Vector )this.subTargetColumnName.get(tableName + "_" + tableID); 473 474 } 475 476 482 public Vector getSubTargetColumnTyp(String tableName, String tableID) { 483 return (Vector )this.subTargetColumnTyp.get(tableName + "_" + tableID); 484 485 } 486 487 493 public Vector getSubValueMode(String tableName, String tableID) { 494 return (Vector )this.subValueMode.get(tableName + "_" + tableID); 495 } 496 497 503 public Vector getSubCounterKeyColumns(String tableName, String tableID) { 504 return (Vector )this.subCounterKeyColumns.get(tableName + "_" + tableID); 505 } 506 507 513 public Vector getSubCounterKeyColumnsTyp(String tableName, String tableID) { 514 return (Vector )this.subCounterKeyColumnsTyp.get(tableName + "_" + tableID); 515 } 516 517 523 public Vector getSubCounterKeyValues(String tableName, String tableID) { 524 return (Vector )this.subCounterKeyValues.get(tableName + "_" + tableID); 525 } 526 527 533 public void setSubCounterKeyValues(String tableName, String tableID, Hashtable values) { 534 535 Enumeration keys = values.keys(); 536 Vector vecColumns = (Vector )this.subCounterKeyColumns.get(tableName + "_" + tableID); 537 Vector vecValues = new Vector (vecColumns.size()); 538 539 String column; 540 for (int i = 0; i < vecColumns.size(); i++) { 541 Vector subValues = new Vector (); 542 for (int j = 0; j < ( (Vector )vecColumns.get(i)).size(); j++) { 543 column = ( (Vector )vecColumns.get(i)).get(j).toString(); 544 subValues.add(values.get(column)); 545 } 546 vecValues.add(subValues); 547 } 548 this.subCounterKeyValues.put(tableName + "_" + tableID, vecValues); 549 } 550 551 556 public void setCounterValue(String tableName, String tableID) { 557 Vector targetCounterValue = new Vector (); 558 Vector oldValues = getCounterValue(tableName, tableID); 559 Vector counterIncrement = getCounterIncrement(tableName, tableID); 560 for (int i = 0; i < counterIncrement.size(); i++) { 561 BigDecimal newValue = new BigDecimal (oldValues.get(i).toString()); 562 newValue = newValue.add(new BigDecimal (counterIncrement.get(i).toString())); 563 targetCounterValue.addElement(newValue); 564 } 565 this.currentCounterValue.put(tableName + "_" + tableID, targetCounterValue); 566 } 567 568 574 public Vector getCounterValue(String tableName, String tableID) { 575 return (Vector )this.currentCounterValue.get(tableName + "_" + tableID); 576 } 577 578 586 public void setTargetColumnStartValues(String tableName, String tableID, Connection conn, 587 int firstColumn) throws SQLException { 588 Vector values = new Vector (); 589 Vector valuesFromTable = readCounter(tableName, tableID, conn, firstColumn); 591 for (int i = 0; i < this.getCounterName(tableName, tableID).size(); i++) { 592 if (this.getCounterStartValueReset(tableName, 593 tableID).get(i).toString().equalsIgnoreCase("true")) { 594 if (this.getCounterStartValue(tableName, tableID).get(i) != null) { 595 BigDecimal newValue = new BigDecimal ( (this.getCounterStartValue(tableName, 596 tableID)).get(i).toString()); 597 values.addElement(newValue); 598 } else 599 values.addElement(null); 600 } else if (this.getCounterStartValueReset(tableName, 601 tableID).get(i).toString().equalsIgnoreCase("false")) { 602 if (this.getCounterStartValue(tableName, tableID).get(i) != null) { 603 BigDecimal newValue = new BigDecimal (valuesFromTable.get(i).toString()); 604 values.addElement(newValue); 605 } else 606 values.addElement(null); 607 } 608 } 609 this.currentCounterValue.put(tableName + "_" + tableID, values); 610 } 611 612 621 private Vector importValue(Document doc, String tagName, String strAttrName, 622 int iImportJobItem, String defaultValue) { 623 Vector strValue = new Vector (); 624 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 625 if (tagBasic.getLength() != 0) { 626 Element docFragment = (Element )tagBasic.item(iImportJobItem); 627 NodeList tag = docFragment.getElementsByTagName(tagName); 628 for (int i = 0; i < tag.getLength(); i++) { 629 String nodeValue = ""; 630 if (strAttrName != null) { 631 NamedNodeMap attrs = tag.item(i).getAttributes(); 632 Node nodeResult = attrs.getNamedItem(strAttrName); 633 if (nodeResult != null) 634 nodeValue = nodeResult.getNodeValue(); 635 else 636 nodeValue = defaultValue; 637 strValue.addElement(nodeValue); 638 } else { 639 NodeList nodeText = tag.item(i).getChildNodes(); 640 if (nodeText.item(0) != null) { 641 nodeValue = nodeText.item(0).getNodeValue(); 642 strValue.addElement(nodeValue); 643 } 644 } 645 } 646 } 647 return strValue; 648 } 649 650 659 private Vector importSubCounterKeyValue(Document doc, String strAttrName, 660 int iImportJobItem, int iSubCounterItem) { 661 Vector strValue = null; 662 NodeList tagBasic = doc.getElementsByTagName("importDefinition"); 663 if (tagBasic.getLength() != 0) { 664 Element docFragment = (Element )tagBasic.item(iImportJobItem); 665 NodeList tag = docFragment.getElementsByTagName("subCounterColumn"); 666 if (tag.getLength() != 0) { 667 Element docCounterColumn = (Element )tag.item(iSubCounterItem); 668 NodeList tagSubCounterColumn = docCounterColumn.getElementsByTagName("subCounterKeyColumn"); 669 strValue = new Vector (); 670 for (int i = 0; i < tagSubCounterColumn.getLength(); i++) { 671 String nodeValue = ""; 672 if (strAttrName != null) { 673 NamedNodeMap attrs = tagSubCounterColumn.item(i).getAttributes(); 674 Node nodeResult = attrs.getNamedItem(strAttrName); 675 if (nodeResult != null) { 676 nodeValue = nodeResult.getNodeValue(); 677 } else 678 nodeValue = null; 679 strValue.addElement(nodeValue); 680
|