1 22 23 package org.xquark.extractor.runtime; 24 25 import java.sql.*; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 import org.xml.sax.ContentHandler ; 30 import org.xml.sax.ErrorHandler ; 31 import org.xml.sax.SAXException ; 32 import org.xml.sax.ext.LexicalHandler ; 33 import org.xml.sax.helpers.AttributesImpl ; 34 import org.xquark.extractor.algebra.MapItem; 35 import org.xquark.extractor.algebra.Mapper; 36 import org.xquark.extractor.common.Debug; 37 import org.xquark.extractor.common.MessageLibrary; 38 import org.xquark.extractor.common.SqlWrapperException; 39 import org.xquark.extractor.metadata.ExtractorMappingInfo; 40 import org.xquark.extractor.sql.StatementInfo; 41 import org.xquark.jdbc.typing.DBMSInfo; 42 import org.xquark.schema.SchemaConstants; 43 import org.xquark.schema.SchemaException; 44 import org.xquark.schema.SimpleType; 45 import org.xquark.schema.validation.PSVInfoSetProvider; 46 import org.xquark.xml.xdbc.XMLDBCException; 47 import org.xquark.xquery.parser.Step; 48 import org.xquark.xquery.parser.XQueryException; 49 import org.xquark.xquery.xdbc.XDBCResultSetInterface; 50 51 56 public final class SynchronizedResultSet implements XDBCResultSetInterface { 57 58 private static final String RCSRevision = "$Revision: 1.5 $"; 59 private static final String RCSName = "$Name: $"; 60 61 static final Object NULLID = new Object (); 62 static final AttributesImpl NULL_ATTRIBUTE = new AttributesImpl (); 63 64 65 private LookAheadJdbcResultSet _lookAheadRes; 66 67 68 private Mapper _mapper; 69 70 private boolean _hasIdentifiers = false; 71 72 75 private Object [] _aoThisId; 76 77 78 private Object [] _aoThisNextId; 79 80 private int _reconstructionIdCount = 0; 81 82 86 private int[] _aiIdPosition; 87 88 89 private List _slaveList; 90 91 92 private SynchronizedResultSet _father; 93 94 97 private int _curSlaveIndex = 0; 98 99 100 private int _maxSlaveIndex; 101 102 103 private boolean _isSynchronizedWithFather = false; 104 105 106 private boolean _isClosed = false; 107 108 private ContentHandler _contenthandler = null; 109 private LexicalHandler _lexicalhandler = null; 110 private ErrorHandler _errorhandler = null; 111 112 113 private Statement _jdbcStatement = null; 114 115 124 public SynchronizedResultSet(List requestList, Mapper mapper, Statement jdbcStatement, DBMSInfo info) 125 throws XMLDBCException { 126 try { 127 init(jdbcStatement, executeRequests(requestList, jdbcStatement), mapper, info); 128 } 129 catch (SQLException ex) { 130 throw new XMLDBCException(ex.getMessage(), ex); 131 } 132 133 _jdbcStatement = jdbcStatement; } 135 136 public SynchronizedResultSet(PreparedStatement pStmt, Mapper mapper, DBMSInfo info) 137 throws XMLDBCException { 138 try { 139 init(pStmt, pStmt.executeQuery(), mapper, info); 140 } 141 catch (SQLException ex) { 142 throw new XMLDBCException(ex.getMessage(), ex); 143 } 144 } 145 146 private void init(Statement jdbcStatement, ResultSet jdbcResultSet, Mapper mapper, DBMSInfo info) 147 throws XMLDBCException { 148 try { 149 try { 150 _lookAheadRes = new LookAheadJdbcResultSet(jdbcResultSet, mapper, info); 151 } 152 catch (XQueryException e) { 153 throw new XMLDBCException("Could not get next results from result set.", e); 154 } 155 156 SQLWarning warning = null; 157 warning = jdbcStatement.getWarnings(); 158 if (null != warning) { 159 throw warning; 160 } 161 warning = jdbcResultSet.getWarnings(); 162 if (null != warning) { 163 throw warning; 164 } 165 } 166 catch (SQLException ex) { 167 throw new XMLDBCException(ex.getMessage(), ex); 168 } 169 170 mapper.optimize(); 171 setMapper(mapper); 172 } 173 174 182 public void setIdPosition(int[] idPosition) { 183 _aiIdPosition = idPosition; 184 } 185 186 public int getReconstructionIdCount() { 187 return _reconstructionIdCount; 188 } 189 190 public void setReconstructionIdCount(int idCount) { 191 _reconstructionIdCount = idCount; 192 } 193 194 198 public void setMapper(Mapper mapper) { 199 _mapper = mapper; 200 201 List idMapItemList = mapper.getIdentifierList(); 202 if (null != idMapItemList && !idMapItemList.isEmpty()) { 203 int idNumber = mapper.getIdentifierList().size(); 204 _aoThisId = new Object [idNumber]; 205 _aoThisNextId = new Object [idNumber]; 206 207 _hasIdentifiers = true; 208 } else { 209 _hasIdentifiers = false; 210 } 211 } 212 213 217 void setFather(SynchronizedResultSet father) { 218 _father = father; 219 } 220 221 225 public void setSlaveList(List slaveList) { 226 _slaveList = slaveList; 227 228 if (null != _slaveList) { 229 _maxSlaveIndex = _slaveList.size() - 1; 230 SynchronizedResultSet slave = null; 231 for (int i = 0; i < _maxSlaveIndex + 1; i++) { 232 slave = (SynchronizedResultSet) _slaveList.get(i); 233 slave.setFather(this); 234 } 235 } 237 } 238 239 247 protected ResultSet executeRequests(List requestList, Statement jdbcStatement) 248 throws SQLException { 249 StatementInfo request = null; 250 int last = requestList.size() - 1; 251 for (int i = 0; i < last; i++) { 252 request = (StatementInfo) requestList.get(i); 253 jdbcStatement.executeUpdate(request.sStmt); 254 } 255 request = (StatementInfo) requestList.get(last); 256 return jdbcStatement.executeQuery(request.sStmt); 257 } 258 259 264 public void close() throws XMLDBCException { 265 if (!_isClosed) { 266 267 if (!isLeaf()) { 268 SynchronizedResultSet slave = null; 269 for (int i = 0; i < _slaveList.size(); i++) { 270 slave = (SynchronizedResultSet) _slaveList.get(i); 271 slave.close(); 272 } 273 } 274 275 276 try { 277 if (_jdbcStatement != null) { 278 _jdbcStatement.close(); 279 _jdbcStatement = null; 280 } 281 if (_lookAheadRes != null) { 282 _lookAheadRes.close(); 283 _lookAheadRes = null; 284 } 285 } catch (SQLException ex) { 286 throw new XMLDBCException(ex.getMessage(), ex); 287 } 288 _isClosed = true; 289 } 290 } 291 292 public boolean next() throws XMLDBCException { 293 boolean retVal = false; 294 295 if (isLeaf()) { 296 retVal = nextInThis(); 297 } else if (isRoot()) { 298 retVal = next_internalNode(); 299 } else { 300 retVal = next_internalNode(); 301 } 302 303 return retVal; 304 } 305 306 313 protected boolean next_internalNode() throws XMLDBCException { 314 boolean retVal = false; 316 317 if (!_isSynchronizedWithFather || _curSlaveIndex == -1) { 318 retVal = nextInThis(); 319 if (retVal) { 320 _curSlaveIndex = 0; 321 retVal = nextInSlaves(); 322 if (!retVal) { 323 _curSlaveIndex = -1; 324 retVal = true; 325 } 326 } 327 } else { 328 retVal = nextInSlaves(); 329 if (!retVal) { 330 retVal = nextInThis(); 331 if (retVal) { 332 _curSlaveIndex = 0; 333 retVal = nextInSlaves(); 334 if (!retVal) { 335 _curSlaveIndex = -1; 336 retVal = true; 337 } 338 } 339 } 340 } 341 return retVal; 343 } 344 345 352 protected boolean nextInThis() throws XMLDBCException { 353 boolean retVal = false; 355 try { 356 if (!isRoot()) { 357 358 if (_lookAheadRes.hasNext()) { 359 _lookAheadRes.lookAhead(); 360 feedIdentifiers(_aoThisNextId); 361 _lookAheadRes.goBack(); 362 if (isSynchronized(_father._aoThisId, _aoThisNextId)) { 363 try { 364 _lookAheadRes.next(); 365 } catch (SQLException ex) { 366 throw new XMLDBCException(MessageLibrary.getMessage("D_ACC_FAIL", ex.getMessage()), ex); 367 368 } 369 for (int i = 0; i < _aoThisNextId.length; i++) { 370 _aoThisId[i] = _aoThisNextId[i]; 371 } 372 retVal = true; 373 } 374 } 375 } else { 376 377 if (_lookAheadRes.hasNext()) { 378 try { 379 _lookAheadRes.next(); 380 } catch (SQLException ex) { 381 throw new XMLDBCException(MessageLibrary.getMessage("D_ACC_FAIL", ex.getMessage()), ex); 382 } 383 feedIdentifiers(_aoThisId); 384 retVal = true; 385 } 386 } 387 } catch (XQueryException e) { 388 throw new XMLDBCException("Could not get next results from result set.", e); 389 } 390 391 if (retVal) { 392 notifySlaves(); 393 _isSynchronizedWithFather = true; 394 } 395 396 return retVal; 398 } 399 400 408 protected boolean nextInSlaves() { 409 boolean retVal = false; 411 412 SynchronizedResultSet curSlave = null; 413 for (int i = _curSlaveIndex; i <= _maxSlaveIndex; i++) { 414 curSlave = (SynchronizedResultSet) _slaveList.get(i); 415 try { 416 retVal = curSlave.next(); 417 } catch (XMLDBCException ex) { 418 continue; 419 } 420 if (retVal) { 421 _curSlaveIndex = i; 422 retVal = true; 423 break; 424 } 425 } 426 427 return retVal; 429 } 430 431 433 protected void notifySlaves() { 434 if (null != _slaveList) { 436 SynchronizedResultSet slave = null; 437 for (int i = 0; i < _slaveList.size(); i++) { 438 slave = (SynchronizedResultSet) _slaveList.get(i); 439 slave.fatherIdsChanged(); 440 } 441 } 442 444 } 445 446 450 protected void fatherIdsChanged() { 451 _isSynchronizedWithFather = false; 452 } 453 454 public boolean hasNext() throws XMLDBCException { 455 if (_isClosed) 457 throw new XMLDBCException(MessageLibrary.getMessage("RS_CLOSED")); 458 boolean retVal = false; 459 460 retVal = _lookAheadRes.hasNext(); 461 462 463 if (!retVal) { 464 SynchronizedResultSet curSlave = null; 465 if (_curSlaveIndex != -1 && !isLeaf()) { 466 for (int i = _curSlaveIndex; i <= _maxSlaveIndex; i++) { 467 curSlave = (SynchronizedResultSet) _slaveList.get(i); 468 retVal = curSlave.hasNext(); 469 470 if (retVal) { 471 break; 472 } 473 } 474 } 475 } 476 477 return retVal; 479 } 480 481 public void getIdentifiers(Object [] ids) throws XMLDBCException { 482 if (_isClosed) 484 throw new XMLDBCException(MessageLibrary.getMessage("RS_CLOSED")); 485 if (!_hasIdentifiers) 486 throw new XMLDBCException(MessageLibrary.getMessage("RS_NO_ID"), null); 487 488 if (!isLeaf() && _curSlaveIndex >= 0) { 489 490 SynchronizedResultSet curSlave = (SynchronizedResultSet) _slaveList.get(_curSlaveIndex); 491 curSlave.getIdentifiers(ids); 492 } else { 493 fillIdsWithCache(ids, _aoThisId); 494 } 495 496 StringBuffer idsBuf = new StringBuffer (); 497 printArray(idsBuf, ids); 498 } 501 502 private void printArray(StringBuffer buffer, Object [] array) { 503 buffer.append('['); 504 for (int i = 0; i < array.length; i++) { 505 Object item = array[i]; 506 if (item instanceof Object []) { 507 printArray(buffer, array); 508 } 509 if (null != item) { 510 buffer.append(item.toString()); 511 } 512 513 buffer.append(",\t"); 514 } 515 buffer.append(']'); 516 } 517 518 523 protected void feedIdentifiers(Object [] ids) throws XMLDBCException { 524 526 List lmiIdItemList = _mapper.getIdentifierList(); 527 Object id = null; 528 if (null != lmiIdItemList) { 529 MapItem idItem = null; 530 for (int i = 0; i < lmiIdItemList.size(); i++) { 531 idItem = (MapItem) lmiIdItemList.get(i); 532 id = getIdentifiers(idItem); 533 ids[i] = id; 534 } 535 } 536 537 } 539 540 546 protected Object getIdentifiers(MapItem idItem) throws XMLDBCException { 547 Object retVal = null; 549 550 try { 551 if (idItem.isLeafPath()) { 552 retVal = _lookAheadRes.getString(idItem.getItemName()); 553 if (null == retVal) { 554 retVal = NULLID; 555 } 556 } else { 557 List idAttrs = new ArrayList (); 558 List children = idItem.getChildItemList(); 559 for (int j = 0; j < children.size(); j++) { 560 MapItem child = (MapItem) children.get(j); 561 String attrValue = _lookAheadRes.getString(child.getItemName()); 562 idAttrs.add(attrValue); 563 } 564 retVal = idAttrs; 565 } 566 } catch (SQLException ex) { 567 throw new XMLDBCException(MessageLibrary.getMessage("D_ACC_FAIL", ex.getMessage()), ex); 568 } 569 return retVal; 571 } 572 573 580 public void getNextIdentifiers(Object [] ids) throws XMLDBCException { 581 if (_isClosed) 583 throw new XMLDBCException(MessageLibrary.getMessage("RS_CLOSED")); 584 if (!_hasIdentifiers) 585 throw new XMLDBCException(MessageLibrary.getMessage("RS_NO_ID"), null); 586 587 boolean retVal = false; 588 if (!_isSynchronizedWithFather) { 589 590 if (_lookAheadRes.lookAhead()) { 591 feedIdentifiers(_aoThisNextId); 592 _lookAheadRes.goBack(); 593 if (!isLeaf()) { 594 retVal = getNextIdentifiersInSlaves(_aoThisNextId, ids, 0); 595 if (!retVal) { 596 fillIdsWithCache(ids, _aoThisNextId); 597 retVal = true; 598 } 599 } else { 600 fillIdsWithCache(ids, _aoThisNextId); 601 } 602 } else { 603 604 throw new XMLDBCException("getNextIdentifiers(Object[] ids) while there isn't next result ", null); 605 } 606 } else { 607 if (!isLeaf()) { 608 609 retVal = getNextIdentifiersInSlaves(_aoThisId, ids, _curSlaveIndex); 610 if (!retVal) { 611 if (_lookAheadRes.lookAhead()) { 612 feedIdentifiers(_aoThisNextId); 613 _lookAheadRes.goBack(); 614 retVal = getNextIdentifiersInSlaves(_aoThisNextId, ids, 0); 615 if (!retVal) { 616 fillIdsWithCache(ids, _aoThisNextId); 617 retVal = true; 618 } 619 } else { 620 621 throw new XMLDBCException("getNextIdentifiers(Object[] ids) called, while there isn't next result ", null); 622 } 623 } 624 } else { 625 if (_lookAheadRes.lookAhead()) { 626 feedIdentifiers(_aoThisNextId); 627 fillIdsWithCache(ids, _aoThisNextId); 628 _lookAheadRes.goBack(); 629 } else { 630 631 throw new XMLDBCException("getNextIdentifiers(Object[] ids) called, while there isn't next result ", null); 632 } 633 } 634 } 635 StringBuffer idsBuf = new StringBuffer (); 636 printArray(idsBuf, ids); 637 } 640 641 649 protected boolean getNextIdentifiersOf(Object [] fatherIds, Object [] ids) throws XMLDBCException { 650 boolean retVal = false; 652 653 if (isLeaf()) { 654 retVal = getNextIdentifiersOf_leaf(fatherIds, ids); 655 } else { 656 retVal = getNextIdentifiersOf_internalNode(fatherIds, ids); 657 } 658 659 return retVal; 661 } 662 663 672 protected boolean getNextIdentifiersOf_internalNode(Object [] fatherIds, Object [] ids) throws XMLDBCException { 673 675 boolean retVal = false; 676 if (!_isSynchronizedWithFather) { 677 if (_lookAheadRes.lookAhead()) { 678 feedIdentifiers(_aoThisNextId); 679 _lookAheadRes.goBack(); 680 if (isSynchronized(fatherIds, _aoThisNextId)) { 681 retVal = getNextIdentifiersInSlaves(_aoThisNextId, ids, 0); 682 if (!retVal) { 683 fillIdsWithCache(ids, _aoThisNextId); 684 retVal = true; 685 } 686 } 687 688 } 689 } else { 690 691 retVal = getNextIdentifiersInSlaves(_aoThisId, ids, _curSlaveIndex); 692 if (!retVal) { 693 if (_lookAheadRes.lookAhead()) { 694 feedIdentifiers(_aoThisNextId); 695 _lookAheadRes.goBack(); 696 if (isSynchronized(fatherIds, _aoThisNextId)) { 697 retVal = getNextIdentifiersInSlaves(_aoThisNextId, ids, 0); 698 if (!retVal) { 699 fillIdsWithCache(ids, _aoThisNextId); 700 retVal = true; 701 } 702 } 703 } 704 } 705 } 706 707 return retVal; 709 } 710 711 protected void fillIdsWithCache(Object [] ids, Object [] cache) { 712 713 for (int i = 0; i < ids.length; i++) { 714 ids[i] = null; 715 } 716 717 for (int i = 0; i < cache.length; i++) { 718 ids[_aiIdPosition == null ? i : _aiIdPosition[i]] = cache[i]; 719 } 720 721 } 722 723 731 protected boolean getNextIdentifiersInSlaves(Object [] fatherIds, Object [] ids, int startIndex) throws XMLDBCException { 732 boolean retVal = false; 734 735 SynchronizedResultSet curSlave = null; 736 if (startIndex != -1) { 737 for (int i = startIndex; i <= _maxSlaveIndex; i++) { 738 curSlave = (SynchronizedResultSet) _slaveList.get(i); 739 retVal = curSlave.getNextIdentifiersOf(fatherIds, ids); 740 if (retVal) { 741 break; 742 } 743 } 744 } 745 746 return retVal; 748 } 749 750 758 protected boolean getNextIdentifiersOf_leaf(Object [] fatherIds, Object [] ids) throws XMLDBCException { 759 761 boolean retVal = false; 762 if (_lookAheadRes.lookAhead()) { 763 feedIdentifiers(_aoThisNextId); 764 _lookAheadRes.goBack(); 765 if (isSynchronized(fatherIds, _aoThisNextId)) { 766 fillIdsWithCache(ids, _aoThisNextId); 767 retVal = true; 768 } 769 } 770 771 return retVal; 773 } 774 775 782 public void generate(String path, int nodeAccessor, String loopID) throws XMLDBCException { 783 generate(path, nodeAccessor); 784 } 785 786 public void generate(String path, int nodeAccessor) throws XMLDBCException { 787 generate(path, nodeAccessor, (PSVInfoSetProvider) null); 788 } 789 790 public void generate(String path, int nodeAccessor, String loopID, PSVInfoSetProvider psvisp) throws XMLDBCException { 791 generate(path, nodeAccessor, psvisp); 792 } 793 794 public void generate(String path, int nodeAccessor, PSVInfoSetProvider psvisp) throws XMLDBCException { 795 796 if (_isClosed) 798 throw new XMLDBCException(MessageLibrary.getMessage("RS_CLOSED")); 799 if (_contenthandler != null) { 800 if (_curSlaveIndex != -1 && !isLeaf()) { 801 802 SynchronizedResultSet curSlave = (SynchronizedResultSet) _slaveList.get(_curSlaveIndex); 803 curSlave.generate(path, nodeAccessor); 804 } else { 805 806 MapItem mapItem = _mapper.map(path); 807 if (mapItem == null) { 808 int toto = 0; 809 } 810 Debug.assertTrue(null != mapItem, "null!=mapItem"); 811 switch (nodeAccessor) { 812 case 0 : 813 generate(mapItem, psvisp); 814 break; 815 case Step.CHILD_TEXT : 816 818 String value = fetch(mapItem, psvisp); 819 if (null != value) { 820 try { 821 if (psvisp != null) { 822 ExtractorMappingInfo emi = mapItem.getMappingInfo(); 823 SimpleType st = emi.getXMLType(); 824 psvisp.setActualValue(-1, st.getPrimitive().convert(value, false)); 825 psvisp.setNormalizedValue(-1, value); 826 } 827 _contenthandler.characters(value.toCharArray(), 0, value.length()); 828 } catch (SchemaException ex) { 829 throw new XMLDBCException(ex.getMessage(), ex); 830 } catch (SAXException ex) { 831 throw new XMLDBCException(ex.getMessage(), ex); 832 } 833 } 834 break; 835 case Step.CHILD_NODE : 836 if (mapItem.isLeafPath()) { 838 generate(mapItem, psvisp); 839 } else { 840 List childItemList = mapItem.getChildItemList(); 841 for (int i = 0; i < childItemList.size(); i++) { 842 mapItem = (MapItem) childItemList.get(i); 843 generate(mapItem, psvisp); 844 } 845 } 846 break; 847 default : 848 throw new XMLDBCException("Internal error : error argument in function call"); 849 } 850 } 851 } 852 } 854 855 860 private final static String STAR = "*"; 861 protected void generate(MapItem mapItem, PSVInfoSetProvider psvisp) throws XMLDBCException { 862 try { 864 String tag = mapItem.getElementName(); 865 String namespace = mapItem.getNamespace(); 866 if (namespace != null && namespace.equals(STAR)) 868 namespace = null; 869 if (mapItem.isLeafPath()) { 870 871 String value = _lookAheadRes.getString(mapItem.getItemName()); 872 if (value != null) { 873 if (null != tag) { 874 if (psvisp != null) { 875 psvisp.pushElementInfoset((namespace == null) ? "" : namespace, tag); 876 psvisp.initElementValidationInfo(null, mapItem.getMappingInfo().getXMLType(), false, SchemaConstants.LAX); 878 } 879 _contenthandler.startElement((namespace == null) ? "" : namespace, tag, "", NULL_ATTRIBUTE); 880 } 881 if (psvisp != null) { 882 ExtractorMappingInfo emi = mapItem.getMappingInfo(); 883 SimpleType st = emi.getXMLType(); 884 psvisp.setActualValue(-1, st.getPrimitive().convert(value, false)); 886 psvisp.setNormalizedValue(-1, value); 887 } 888 _contenthandler.characters(value.toCharArray(), 0, value.length()); 889 if (null != tag) { 890 _contenthandler.endElement(namespace, tag, ""); 891 if (psvisp != null) { 892 psvisp.popElementInfoset(); 893 } 894 } 895 } 896 } else { 897 898 if (psvisp != null) { 899 psvisp.pushElementInfoset((namespace == null) ? "" : namespace, tag); 900 if (mapItem.getMappingInfo() != null) 902 psvisp.initElementValidationInfo(null, mapItem.getMappingInfo().getXMLType(), false, SchemaConstants.LAX); 903 } 904 _contenthandler.startElement((namespace == null) ? "" : namespace, tag, "", NULL_ATTRIBUTE); 905 List childItemList = mapItem.getChildItemList(); 906 for (int i = 0; i < childItemList.size(); i++) { 907 generate((MapItem) childItemList.get(i), psvisp); 908 } 909 _contenthandler.endElement(namespace, tag, ""); 910 if (psvisp != null) { 911 psvisp.popElementInfoset(); 912 } 913 } 914 } catch (SQLException ex) { 915 throw new XMLDBCException(ex.getMessage(), ex); 916 } catch (SchemaException ex) { 917 throw new XMLDBCException(ex.getMessage(), ex); 918 } catch (SAXException ex) { 919 throw new XMLDBCException(ex.getMessage(), ex); 920 } 921 } 923 924 protected boolean willGenerateOnlyCharacters(MapItem mapItem) throws XMLDBCException { 925 try { 926 return mapItem.isLeafPath() && _lookAheadRes.getString(mapItem.getItemName()) != null && mapItem.getElementName() == null; 927 } catch (SQLException ex) { 928 throw new XMLDBCException(ex.getMessage(), ex); 929 } 930 } 931 932 940 public String fetch(String path, int nodeAccessor, String loopID) throws XMLDBCException { 941 return fetch(path, nodeAccessor); 942 } 943 public String fetch(String path, int nodeAccessor) throws XMLDBCException { 944 return fetch(path, nodeAccessor, (PSVInfoSetProvider) null); 945 } 946 947 public String fetch(String path, int nodeAccessor, String loopID, PSVInfoSetProvider psvisp) throws XMLDBCException { 948 return fetch(path, nodeAccessor, psvisp); 949 } 950 951 public String fetch(String path, int nodeAccessor, PSVInfoSetProvider psvisp) throws XMLDBCException { 952 if (_isClosed) 954 throw new XMLDBCException(MessageLibrary.getMessage("RS_CLOSED")); 955 String retVal = null; 956 957 if (_curSlaveIndex != -1 && !isLeaf()) { 958 959 960 SynchronizedResultSet curSlave = (SynchronizedResultSet) _slaveList.get(_curSlaveIndex); 961 retVal = curSlave.fetch(path, nodeAccessor, psvisp); 962 } else { 963 964 MapItem mapItem = _mapper.map(path); 965 if (mapItem != null) { 966 retVal = fetch(mapItem, psvisp); 967 } else { 968 throw new XMLDBCException("(fetch) This path \"" + path + "\" can not be found in the result set.", null); 969 } 970 } 971 return retVal; 973 } 974 975 981 protected String fetch(MapItem mapItem, PSVInfoSetProvider psvisp) throws XMLDBCException { 982 String retVal = null; 984 try { 985 retVal = _lookAheadRes.getString(mapItem.getItemName()); 986 } 995 catch (SQLException ex) { 999 throw new XMLDBCException(MessageLibrary.getMessage("D_ACC_FAIL"), ex); 1000 } 1001 1002 return retVal; 1004 } 1005 1006 1012 protected boolean isSynchronized(Object [] fatherId, Object [] thisId) { 1013 boolean retVal = true; 1015 1016 if (null != fatherId && null != thisId) { 1017 for (int i = 0; i < fatherId.length; i++) { 1018 retVal = fatherId[i].equals(thisId[i]); 1019 if (!retVal) { 1020 break; 1021 } 1022 } 1023 } else { 1024 throw new SqlWrapperException(MessageLibrary.getMessage("IE_INV_ARG", "isSynchronized(Object[] fatherId, Object[] thisId)"), null); 1025 } 1026 1027 return retVal; 1029 } 1030 1031 public boolean isRoot() { 1032 return null == _father; 1033 } 1034 1035 public boolean isLeaf() { 1036 return null == _slaveList || _slaveList.isEmpty(); 1037 } 1038 1039 public void setContentHandler(ContentHandler handler) { 1040 if (handler == null) 1041 throw new NullPointerException ("ContentHandler can not be null."); 1042 this._contenthandler = handler; 1043 1044 if (!isLeaf()) { 1045 SynchronizedResultSet slave = null; 1046 for (int i = 0; i < _slaveList.size(); i++) { 1047 slave = (SynchronizedResultSet) _slaveList.get(i); 1048 slave.setContentHandler(_contenthandler); 1049 } 1050 } 1051 } 1052 1053 public void setLexicalHandler(LexicalHandler handler) { 1054 if (handler == null) 1055 throw new NullPointerException ("LexicalHandler can not be null."); 1056 this._lexicalhandler = handler; 1057 1058 if (!isLeaf()) { 1059 SynchronizedResultSet slave = null; 1060 for (int i = 0; i < _slaveList.size(); i++) { 1061 slave = (SynchronizedResultSet) _slaveList.get(i); 1062 slave.setLexicalHandler(_lexicalhandler); 1063 } 1064 } 1065 } 1066 1067 public void setErrorHandler(ErrorHandler handler) { 1068 if (handler == null) 1069 throw new NullPointerException ("ErrorHandler can not be null."); 1070 this._errorhandler = handler; 1071 1072 if (!isLeaf()) { 1073 SynchronizedResultSet slave = null; 1074 for (int i = 0; i < _slaveList.size(); i++) { 1075 slave = (SynchronizedResultSet) _slaveList.get(i); 1076 slave.setErrorHandler(_errorhandler); 1077 } 1078 } 1079 } 1080} 1081 | Popular Tags |