1 22 23 package org.xquark.extractor.runtime; 24 25 import java.io.DataOutputStream ; 26 import java.sql.*; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.xml.sax.ContentHandler ; 31 import org.xml.sax.ErrorHandler ; 32 import org.xml.sax.SAXException ; 33 import org.xml.sax.ext.LexicalHandler ; 34 import org.xml.sax.helpers.AttributesImpl ; 35 import org.xquark.extractor.algebra.MapItem; 36 import org.xquark.extractor.algebra.Mapper; 37 import org.xquark.extractor.common.MessageLibrary; 38 import org.xquark.schema.validation.PSVInfoSetProvider; 39 import org.xquark.xml.xdbc.XMLDBCException; 40 import org.xquark.xquery.parser.Step; 41 import org.xquark.xquery.xdbc.XDBCResultSetInterface; 42 43 47 public class XDBCResultSet implements XDBCResultSetInterface { 48 private static final String RCSRevision = "$Revision: 1.3 $"; 49 private static final String RCSName = "$Name: $"; 50 51 private ContentHandler _contenthandler = null; 52 private LexicalHandler _lexicalhandler = null; 53 private ErrorHandler _errorhandler = null; 54 private Mapper _mapper = null; 55 private LookAheadResultSet _sqlResultSet = null; 56 57 59 private String _partAttributeName = null; 60 61 62 private List _nullIdentifier = new ArrayList (1); 63 64 65 private AttributesImpl _nullAttribute = new AttributesImpl (); 66 67 private String _namespace = null; 68 69 private boolean _isClosed = false; 70 71 private Statement _jdbcStatement = null; 72 73 public void setNamespace(String namespace) { 74 this._namespace = namespace; 75 } 76 77 129 public XDBCResultSet(ResultSet sqlResultSet, Mapper mapper) throws XMLDBCException { 130 if (sqlResultSet == null || mapper == null) 132 throw new XMLDBCException("The arguments of the XDBCResultSet constructor cannot be null.", null); 133 134 141 142 _nullIdentifier.add(null); 143 144 _mapper = mapper; 145 146 if (_mapper.isMultiPart()) { 147 _partAttributeName = _mapper.getPartAttributeName(); 148 try { 149 _sqlResultSet = new EliminatedSqlResultSet(sqlResultSet, _mapper.getEliminationGuide()); 150 } catch (SQLException ex) { 151 throw new XMLDBCException("XDBCResultSet constructor failed .", ex); 152 } 153 } else { 154 try { 155 _sqlResultSet = new LookAheadSqlResultSet(sqlResultSet); 156 } catch (SQLException ex) { 157 throw new XMLDBCException("XDBCResultSet constructor failed .", ex); 158 } 159 } 160 161 } 163 164 public XDBCResultSet(ResultSet sqlResultSet, Mapper mapper, boolean heavyElimination) throws XMLDBCException { 165 if (sqlResultSet == null || mapper == null) 167 throw new XMLDBCException("The arguments of the XDBCResultSet constructor cannot be null.", null); 168 169 176 177 _nullIdentifier.add(null); 178 179 _mapper = mapper; 180 181 if (heavyElimination && _mapper.isMultiPart()) { 182 _partAttributeName = _mapper.getPartAttributeName(); 183 try { 184 _sqlResultSet = new HeavyElimination(sqlResultSet, _mapper.getEliminationGuide()); 185 } catch (SQLException ex) { 187 throw new XMLDBCException("XDBCResultSet constructor failed .", ex); 188 } 189 190 } else if (_mapper.isMultiPart()) { 191 _partAttributeName = _mapper.getPartAttributeName(); 192 try { 193 _sqlResultSet = new EliminatedSqlResultSet(sqlResultSet, _mapper.getEliminationGuide()); 194 } catch (SQLException ex) { 196 throw new XMLDBCException("XDBCResultSet constructor failed .", ex); 197 } 198 } else { 199 try { 200 _sqlResultSet = new LookAheadSqlResultSet(sqlResultSet); 201 } catch (SQLException ex) { 202 throw new XMLDBCException("XDBCResultSet constructor failed .", ex); 203 } 204 } 205 206 } 208 209 212 public String fetch(String path, int nodeAccessor, String loopID, PSVInfoSetProvider psvisp) throws XMLDBCException { 214 return fetch(path, nodeAccessor); 215 } 216 217 public String fetch(String path, int nodeAccessor, String loopID) throws XMLDBCException { 218 return fetch(path, nodeAccessor); 219 } 220 public String fetch(String path, int nodeAccessor) throws XMLDBCException { 221 224 if (_isClosed) 225 throw new XMLDBCException("XMLResultSet is already closed"); 226 String retVal; 227 try { 228 MapItem mapItem = _mapper.map(path); 229 if (mapItem != null) 230 retVal = _sqlResultSet.getString(mapItem.getItemName()); 231 else 232 throw new XMLDBCException("(fetch) This path \"" + path + "\" can not be found in the result set.", null); 233 } catch (SQLException sqle) { 234 throw new XMLDBCException(sqle.getMessage(), sqle); 235 } 236 237 return retVal; 240 } 241 242 245 public void generate(String path, int nodeAccessor, String loopID, PSVInfoSetProvider psvisp) throws XMLDBCException { 247 generate(path, nodeAccessor); 248 } 249 250 public void generate(String path, int nodeAccessor, String loopID) throws XMLDBCException { 251 generate(path, nodeAccessor); 252 } 253 public void generate(String path, int nodeAccessor) throws XMLDBCException { 254 if (_isClosed) 258 throw new XMLDBCException("XMLResultSet is already closed"); 259 MapItem mapItem = _mapper.map(path); 260 262 if (null == mapItem) { 263 throw new XMLDBCException(MessageLibrary.getMessage("IE_INV_ARG", "generate(String path, int nodeAccessor, String loopID, org.xml.sax.ContentHandler handler)", "path = " + path), null); 264 } 265 try { 266 String tag = mapItem.getElementName(); 267 String namespace = mapItem.getNamespace(); 268 if (namespace == null) 269 namespace = ""; 270 if (mapItem.isLeafPath()) { 273 String value = _sqlResultSet.getString(mapItem.getItemName()); 277 if (value != null) { 279 if (null != tag) { 280 if (nodeAccessor == 0 || nodeAccessor == Step.CHILD_NODE) { 281 if (_contenthandler != null) { 283 _contenthandler.startElement(namespace, tag, "", _nullAttribute); 284 _contenthandler.characters(value.toCharArray(), 0, value.length()); 285 _contenthandler.endElement(namespace, tag, ""); 286 } 287 } else if (nodeAccessor == Step.CHILD_TEXT) { 288 if (_contenthandler != null) 291 _contenthandler.characters(value.toCharArray(), 0, value.length()); 292 } 293 } else if (_contenthandler != null) { 294 _contenthandler.characters(value.toCharArray(), 0, value.length()); 295 } 296 } 297 } else { 298 if (nodeAccessor == 0) { 299 List children = mapItem.getChildren(); 300 if (null != tag) { 301 if (_contenthandler != null) { 302 _contenthandler.startElement(namespace, tag, "", _nullAttribute); 303 for (int i = 0; i < children.size(); i++) 304 generate((String ) children.get(i), nodeAccessor); 305 _contenthandler.endElement(namespace, tag, ""); 306 } 307 } else { 308 for (int i = 0; i < children.size(); i++) { 309 generate((String ) children.get(i), nodeAccessor); 310 } 311 } 312 } else if (nodeAccessor == Step.CHILD_NODE) { 313 List children = mapItem.getChildren(); 315 for (int i = 0; i < children.size(); i++) { 316 generate((String ) children.get(i), (tag == null) ? nodeAccessor : 0); 317 } 318 } 319 } 320 } catch (SAXException e) { 321 throw new XMLDBCException(e.getMessage()); 322 } catch (SQLException e) { 323 throw new XMLDBCException(e.getMessage()); 324 } 325 } 327 328 331 public void getIdentifiers(Object [] identifiers) throws XMLDBCException { 332 334 if (_isClosed) 335 throw new XMLDBCException("XMLResultSet is already closed"); 336 List keyList = _mapper.getIdentifierList(); 337 MapItem keyItem; 339 try { 340 if (null == keyList) { 341 throw new XMLDBCException("There is no identifier in the resultset."); 342 } 343 if (null != _partAttributeName) { 344 for (int i = 0; i < keyList.size(); i++) { 345 346 348 long currentPart = _sqlResultSet.getLong(_partAttributeName); 349 350 keyItem = (MapItem) keyList.get(i); 352 353 if (keyItem.isLeafPath()) { 355 identifiers[i] = _sqlResultSet.getString(keyItem.getItemName()); 356 if (null == identifiers[i] && keyItem.isPartOf(currentPart)) { 357 identifiers[i] = _nullIdentifier; 358 } 359 } else { 360 if (keyItem.isPartOf(currentPart)) { 361 List idAttrs = new ArrayList (); 362 List children = _mapper.getChildren(keyItem); 363 for (int j = 0; j < children.size(); j++) { 364 MapItem child = (MapItem) children.get(j); 365 String attrValue = _sqlResultSet.getString(child.getItemName()); 366 idAttrs.add(attrValue); 367 } 368 identifiers[i] = idAttrs; 369 } else { 370 identifiers[i] = null; 371 } 372 373 } 374 375 377 379 } 380 } else { 381 for (int i = 0; i < keyList.size(); i++) { 382 keyItem = (MapItem) keyList.get(i); 383 identifiers[i] = _sqlResultSet.getString(keyItem.getItemName()); 385 if (null == identifiers[i]) { 386 identifiers[i] = _nullIdentifier; 387 } 388 } 390 } 391 } catch (SQLException sqle) { 392 throw new XMLDBCException(sqle.getMessage()); 393 } 394 395 } 397 398 401 public void getNextIdentifiers(Object [] identifiers) throws XMLDBCException { 402 404 if (_isClosed) 405 throw new XMLDBCException("XMLResultSet is already closed"); 406 boolean hasNext; 407 hasNext = _sqlResultSet.lookAhead(); 410 if (hasNext) { 411 getIdentifiers(identifiers); 412 _sqlResultSet.goBack(); 413 } else { 414 identifiers = null; 415 } 416 422 } 424 425 428 public boolean next() throws XMLDBCException { 429 431 if (_isClosed) 432 throw new XMLDBCException("XMLResultSet is already closed"); 433 boolean retVal = false; 434 try { 435 retVal = _sqlResultSet.next(); 436 437 449 } catch (SQLException sqle) { 450 throw new XMLDBCException(sqle.getMessage(), sqle); 452 } 453 454 return retVal; 456 } 457 458 461 462 public boolean hasNext() throws XMLDBCException { 463 if (_isClosed) 465 throw new XMLDBCException("XMLResultSet is already closed"); 466 boolean retVal = _sqlResultSet.lookAhead(); 467 if (retVal) { 469 _sqlResultSet.goBack(); 470 } 471 return retVal; 473 } 474 475 478 public void setContentHandler(ContentHandler handler) { 479 if (handler == null) 480 throw new NullPointerException ("ContentHandler can not be null."); 481 this._contenthandler = handler; 482 } 483 484 487 public void setLexicalHandler(LexicalHandler handler) { 488 if (handler == null) 489 throw new NullPointerException ("LexicalHandler can not be null."); 490 this._lexicalhandler = handler; 491 } 492 493 496 public void setErrorHandler(ErrorHandler handler) { 497 if (handler == null) 498 throw new NullPointerException ("ErrorHandler can not be null."); 499 this._errorhandler = handler; 500 } 501 502 503 public ResultSet getSqlResultSet() { 504 return _sqlResultSet.getSqlResultSet(); 505 } 506 507 public Mapper getMapper() { 508 return _mapper; 509 } 510 511 public void close() throws XMLDBCException { 512 if (!_isClosed) { 513 try { 514 _isClosed = true; 515 _sqlResultSet.close(); 516 } catch (SQLException ex) { 517 throw new XMLDBCException(ex.getMessage(), ex); 518 } 519 } 520 } 521 522 class LookAheadSqlResultSet implements LookAheadResultSet { 523 private static final String RCSRevision = "$Revision: 1.3 $"; 524 private static final String RCSName = "$Name: $"; 525 526 private int BOR = 0; 527 private int BUFFER = 1; 528 private int RESULTSET = 2; 529 530 private ResultSet _resultset; 531 private List _buffer = new ArrayList (); 532 private List _attributeNameList = new ArrayList (); 533 private int _attributeNumber; 534 535 private boolean _bufferNotEmpty; 536 private boolean _resultSetNotEmpty; 537 private int _cursor; 538 539 public LookAheadSqlResultSet(ResultSet resultset) throws SQLException { 540 _resultset = resultset; 542 543 ResultSetMetaData _rsm = _resultset.getMetaData(); 544 545 _attributeNumber = _rsm.getColumnCount(); 546 for (int i = 1; i <= _attributeNumber; i++) { 547 _attributeNameList.add(_rsm.getColumnName(i)); 548 } 549 550 _bufferNotEmpty = _resultset.next(); 551 if (_bufferNotEmpty) { 552 refreshBuffer(); 553 _resultSetNotEmpty = _resultset.next(); 554 } 555 _cursor = BOR; 556 } 558 559 public boolean next() throws SQLException { 560 boolean retVal; 562 if (BOR == _cursor) { 563 _cursor = BUFFER; 564 } else { 565 if (_resultSetNotEmpty) { 566 refreshBuffer(); 567 _resultSetNotEmpty = _resultset.next(); 568 } else { 569 _resultset.close(); 570 _bufferNotEmpty = false; 571 } 572 } 573 return _bufferNotEmpty; 575 } 576 577 public boolean hasNext() { 578 return _resultSetNotEmpty; 579 } 580 581 public boolean lookAhead() { 582 boolean retVal = false; 584 if (BOR == _cursor) { 585 retVal = _bufferNotEmpty; 586 if (retVal) { 588 _cursor = BUFFER; 589 } 590 } else if (BUFFER == _cursor) { 591 retVal = _resultSetNotEmpty; 592 if (retVal) { 594 _cursor = RESULTSET; 595 } 596 } else { 597 org.xquark.extractor.common.Debug.assertTrue(false, "Logic error"); 598 } 599 600 return retVal; 602 } 603 604 public boolean goBack() { 605 boolean retVal = false; 607 if (BUFFER == _cursor) { 608 _cursor = BOR; 609 retVal = true; 610 } else if (RESULTSET == _cursor) { 611 _cursor = BUFFER; 612 retVal = true; 613 } else if (BOR == _cursor) { 614 retVal = false; 615 } 616 617 return retVal; 619 } 620 621 public long getLong(String name) throws SQLException { 622 long retVal = 0; 624 if (BUFFER == _cursor) { 625 retVal = getLongFromBuffer(name); 626 } else { 627 try { 628 retVal = _resultset.getLong(name); 629 } catch (SQLException e) { 630 } 631 } 632 return retVal; 634 } 635 636 public String getString(String name) throws SQLException { 637 String retVal = null; 639 if (BUFFER == _cursor) { 640 retVal = getStringFromBuffer(name); 641 } else { 642 try { 643 retVal = _resultset.getString(name); 644 } catch (SQLException e) { 645 } 646 } 647 return retVal; 649 } 650 651 private void refreshBuffer() throws SQLException { 652 _buffer.clear(); 654 for (int i = 1; i <= _attributeNumber; i++) { 655 _buffer.add(_resultset.getString(i)); 656 } 657 } 659 660 public String getStringFromBuffer(String name) { 661 String retVal = null; 663 int index = -1; 664 for (int i = 0; i < _attributeNameList.size(); i++) { 665 if (name.equalsIgnoreCase((String ) _attributeNameList.get(i))) { 666 index = i; 667 break; 668 } 669 } 670 if (-1 != index) { 671 if (!_buffer.isEmpty()) retVal = (String ) _buffer.get(index); 673 } 674 return retVal; 676 } 677 678 public long getLongFromBuffer(String name) { 679 long retVal = 0; 681 int index = -1; 682 for (int i = 0; i < _attributeNameList.size(); i++) { 683 if (name.equalsIgnoreCase((String ) _attributeNameList.get(i))) { 684 index = i; 685 break; 686 } 687 } 688 if (-1 != index) { 689 if (!_buffer.isEmpty()) retVal = Long.parseLong((String ) _buffer.get(index)); 691 } 692 return retVal; 694 } 695 696 697 public ResultSet getSqlResultSet() { 698 return _resultset; 699 } 700 701 public void write(DataOutputStream dos) throws java.io.IOException { 702 704 String newLine = System.getProperty("line.separator"); 705 706 dos.writeBytes("<LookAheadResultSet>"); 707 dos.writeBytes(newLine); 708 709 dos.writeBytes("<header>"); 710 for (int i = 0; i < _attributeNameList.size(); i++) { 711 Object obj = _attributeNameList.get(i); 712 if (null != obj) { 713 dos.writeBytes((String ) obj); 714 dos.writeBytes(",\t"); 715 } 716 } 717 dos.writeBytes("</header>"); 718 dos.writeBytes(newLine); 719 720 try { 721 while (next()) { 722 dos.writeBytes("<row>"); 723 for (int i = 0; i < _buffer.size(); i++) { 724 Object obj = _buffer.get(i); 725 if (null != obj) { 726 dos.writeBytes((String ) obj); 727 dos.writeBytes(",\t"); 728 } 729 } 730 dos.writeBytes("</row>"); 731 dos.writeBytes(newLine); 732 } 733 734 dos.writeBytes("</LookAheadResultSet>"); 735 dos.writeBytes(newLine); 736 ; 737 } catch (SQLException ex) { 738 ex.printStackTrace(); 739 } 740 741 } 743 public void close() throws SQLException { 744 try { 745 _resultset.close(); 746 } catch (SQLException ex) { 747 } 748 } 749 } 750 751 class HeavyElimination extends EliminatedSqlResultSet { 752 List _keyColumnList = new ArrayList (); 753 String partAttributeName = _partAttributeName; 754 HeavyElimination(ResultSet resultSet, int[] eliminationGuide) throws SQLException { 755 super(resultSet, eliminationGuide); 756 _keyColumnList = _mapper.getAllIdentifierAttributeNames(); 757 } 758 759 protected boolean feedBuffer2() throws SQLException { 760 boolean retVal = false; 762 763 int oldCursor = _cursor; 764 _cursor = BUFFER2; 765 boolean isRedundant = false; 766 if (_resultSetNotEmpty) { 767 fillBuffer2(); 768 _resultSetNotEmpty = _resultSet.next(); 769 if (_buffer2NotEmpty) { 770 if (_resultSetNotEmpty) { 771 isRedundant = isRedundant(); 772 if (isRedundant) { 773 retVal = feedBuffer2(); 774 } else { 775 retVal = true; 776 } 777 } else { 778 _resultSetNotEmpty = false; 779 retVal = true; 780 } 781 } else { 782 retVal = false; 783 } 784 } else { 785 retVal = false; 786 _buffer2NotEmpty = false; 787 _resultSet.close(); 788 } 789 _cursor = oldCursor; 790 791 return retVal; 793 } 794 795 private boolean isRedundant() throws SQLException { 796 boolean retVal = true; 798 799 int oldCursor = _cursor; 800 _cursor = BUFFER2; 801 String idInBuffer = null; 802 String idInResultset = null; 803 String keyColumnName = null; 804 for (int i = 0; i < __keyColumnList.size(); i++) { 805 keyColumnName = (String ) __keyColumnList.get(i); 806 idInBuffer = getStringFromBuffer(keyColumnName); 807 idInResultset = _resultSet.getString(keyColumnName); 808 if (null != idInBuffer && null != idInResultset) { 809 retVal = idInBuffer.equals(idInResultset); 810 } 811 else if (null != idInBuffer && null == idInResultset) { 815 retVal = false; 816 } 817 if (!retVal) { 818 break; 819 } 820 } 821 _cursor = oldCursor; 822 return retVal; 824 } 825 } 826 827 class EliminatedSqlResultSet implements LookAheadResultSet { 828 private static final String RCSRevision = "$Revision: 1.3 $"; 829 private static final String RCSName = "$Name: $"; 830 831 protected int BOR = 0; 832 protected int BUFFER1 = 1; 833 protected int BUFFER2 = 2; 834 protected int RESULTSET = 3; 835 836 protected ResultSet _resultSet; 837 protected List _buffer1; 838 protected List _buffer2; 839 840 protected List _attributeNameList = new ArrayList (); 841 protected int _attributeNumber; 842 843 protected boolean _buffer1NotEmpty = false; 844 protected boolean _buffer2NotEmpty = false; 845 ; 846 protected boolean _resultSetNotEmpty = false; 847 ; 848 protected int _cursor = BOR; 849 850 int[] _eliminationGuide; 851 852 853 protected String __partAttributeName = null; 854 protected List __keyColumnList = new ArrayList (); 855 856 857 public EliminatedSqlResultSet(ResultSet resultSet, int[] eliminationGuide) throws SQLException { 858 860 _resultSet = resultSet; 861 _eliminationGuide = eliminationGuide; 862 863 864 __partAttributeName = _partAttributeName; 865 __keyColumnList = _mapper.getAllIdentifierAttributeNames(); 866 867 ResultSetMetaData _rsm = _resultSet.getMetaData(); 868 869 _resultSetNotEmpty = _resultSet.next(); 870 871 if (_resultSetNotEmpty) { 872 _attributeNumber = _rsm.getColumnCount(); 873 for (int i = 1; i <= _attributeNumber; i++) { 874 _attributeNameList.add(_rsm.getColumnName(i)); 875 } 876 877 _buffer1 = new ArrayList (_attributeNumber); 878 _buffer2 = new ArrayList (_attributeNumber); 879 for (int i = 0; i < _attributeNumber; i++) { 880 _buffer1.add(null); 881 _buffer2.add(null); 882 } 883 884 feedBuffer2(); 885 feedBuffer1(); 886 feedBuffer2(); 887 888 } 889 _cursor = BOR; 890 891 } 893 894 protected boolean feedBuffer1() { 895 boolean retVal = false; 897 898 List tmp = _buffer1; 899 900 _buffer1 = _buffer2; 901 _buffer1NotEmpty = _buffer2NotEmpty; 902 retVal = _buffer1NotEmpty; 903 904 _buffer2 = tmp; 905 _buffer2NotEmpty = false; 906 907 return retVal; 909 } 910 911 protected boolean feedBuffer2() throws SQLException { 912 boolean retVal = false; 914 915 int oldCursor = _cursor; 916 _cursor = BUFFER2; 917 if (_resultSetNotEmpty) { 918 fillBuffer2(); 919 _resultSetNotEmpty = _resultSet.next(); 920 if (_buffer2NotEmpty) { 921 if (_resultSetNotEmpty) { 922 long currentPartBitmap = getLongFromBuffer(_partAttributeName); 923 int curQueryNo = 1; 924 while (1 != currentPartBitmap) { 925 currentPartBitmap = currentPartBitmap >> 1; 926 curQueryNo++; 927 } 928 929 long nextParttBitmap = _resultSet.getLong(_partAttributeName); 930 int nextQueryNo = 1; 931 while (1 != nextParttBitmap) { 932 nextParttBitmap = nextParttBitmap >> 1; 933 nextQueryNo++; 934 } 935 936 if ((nextQueryNo <= _eliminationGuide[curQueryNo - 1]) && (nextQueryNo > curQueryNo)) { 937 938 retVal = feedBuffer2(); 940 org.xquark.extractor.common.Debug.assertTrue(retVal, "retVal"); 941 } else { 942 retVal = true; 943 } 944 } else { 945 _resultSetNotEmpty = false; 946 retVal = true; 947 } 948 } else { 949 retVal = false; 950 } 951 } else { 952 retVal = false; 953 _buffer2NotEmpty = false; 954 _resultSet.close(); 955 } 956 _cursor = oldCursor; 957 958 return retVal; 960 } 961 962 protected void fillBuffer2() throws SQLException { 963 for (int i = 1; i <= _attributeNumber; i++) { 965 _buffer2.set(i - 1, _resultSet.getString(i)); 966 } 967 _buffer2NotEmpty = true; 968 969 } 971 972 public boolean next() throws SQLException { 973 boolean retVal = false; 975 976 if (BOR == _cursor) { 977 _cursor = BUFFER1; 978 retVal = _buffer1NotEmpty; 979 } else if (BUFFER1 == _cursor) { 980 retVal = feedBuffer1(); 981 feedBuffer2(); 982 } else { 983 org.xquark.extractor.common.Debug.assertTrue(false, "Logic error"); 984 } 985 986 return retVal; 988 } 989 990 public boolean lookAhead() { 991 boolean retVal = false; 993 if (BOR == _cursor) { 994 retVal = _buffer1NotEmpty; 995 if (retVal) { 996 _cursor = BUFFER1; 997 } 998 } else if (BUFFER1 == _cursor) { 999 retVal = _buffer2NotEmpty; 1000 if (retVal) { 1001 _cursor = BUFFER2; 1002 } 1003 } else { 1004 org.xquark.extractor.common.Debug.assertTrue(false, "Logic error"); 1005 } 1006 1007 return retVal; 1009 } 1010 1011 public boolean goBack() { 1012 boolean retVal = false; 1014 if (BUFFER1 == _cursor) { 1015 _cursor = BOR; 1016 retVal = true; 1017 } else if (BUFFER2 == _cursor) { 1018 _cursor = BUFFER1; 1019 retVal = true; 1020 } else if (BOR == _cursor) { 1021 retVal = false; 1022 } 1023 1024 return retVal; 1026 } 1027 1028 public long getLong(String name) throws SQLException { 1029 long retVal = getLongFromBuffer(name); 1030 return retVal; 1031 } 1032 1033 public String getString(String name) throws SQLException { 1034 1036 String retVal = null; 1037 if (BUFFER1 == _cursor || BUFFER2 == _cursor) { 1038 retVal = getStringFromBuffer(name); 1039 } else { 1040 retVal = _resultSet.getString(name); 1042 } 1045 1046 return retVal; 1048 } 1049 1050 public String getStringFromBuffer(String name) { 1051 String retVal = null; 1053 1054 int index = -1; 1055 if (BUFFER1 == _cursor) { 1056 for (int i = 0; i < _attributeNameList.size(); i++) { 1057 if (name.equalsIgnoreCase((String ) _attributeNameList.get(i))) { 1058 index = i; 1059 break; 1060 } 1061 } 1062 if (-1 != index) { 1063 retVal = (String ) _buffer1.get(index); 1064 } 1065 } else if (BUFFER2 == _cursor) { 1066 for (int i = 0; i < _attributeNameList.size(); i++) { 1067 if (name.equalsIgnoreCase((String ) _attributeNameList.get(i))) { 1068 index = i; 1069 break; 1070 } 1071 } 1072 if (-1 != index) { 1073 retVal = (String ) _buffer2.get(index); 1074 } 1075 1076 } else { 1077 org.xquark.extractor.common.Debug.assertTrue(false, "Logic error : cursor is not on buffers when calling getStringFromBuffer(String name)"); 1078 } 1079 1080 return retVal; 1082 } 1083 1084 public long getLongFromBuffer(String name) { 1085 long retVal = 0; 1087 1088 int index = -1; 1089 if (BUFFER1 == _cursor) { 1090 for (int i = 0; i < _attributeNameList.size(); i++) { 1091 if (name.equalsIgnoreCase((String ) _attributeNameList.get(i))) { 1092 index = i; 1093 break; 1094 } 1095 } 1096 if (-1 != index) { 1097 retVal = Long.parseLong((String ) _buffer1.get(index)); 1098 } 1099 } else if (BUFFER2 == _cursor) { 1100 for (int i = 0; i < _attributeNameList.size(); i++) { 1101 if (name.equalsIgnoreCase((String ) _attributeNameList.get(i))) { 1102 index = i; 1103 break; 1104 } 1105 } 1106 if (-1 != index) { 1107 retVal = Long.parseLong((String ) _buffer2.get(index)); 1108 } 1109 } else { 1110 org.xquark.extractor.common.Debug.assertTrue(false, "Logic error : cursor is not on buffers when calling getLongFromBuffer(String name)"); 1111 } 1112 1113 return retVal; 1115 } 1116 1117 1118 public ResultSet getSqlResultSet() { 1119 return _resultSet; 1120 } 1121 1122 public void close() throws SQLException { 1123 try { 1124 _resultSet.close(); 1125 } catch (SQLException ex) { 1126 } 1127 } 1128 1129 public void print() throws SQLException { 1130 System.err.println(this.toString()); 1131 System.err.println("==============================================="); 1132 for (int i = 0; i < _attributeNameList.size(); i++) { 1133 System.err.print(_attributeNameList.get(i)); 1134 System.err.print('\t'); 1135 } 1136 System.err.println(); 1137 1138 while (next()) { 1139 for (int i = 0; i < _attributeNameList.size(); i++) { 1140 System.err.print(getString((String ) _attributeNameList.get(i))); 1141 System.err.print('\t'); 1142 } 1143 System.err.println(); 1144 } 1145 } 1146 } 1147 interface LookAheadResultSet { 1148 public boolean next() throws SQLException; 1149 public boolean lookAhead(); 1150 public boolean goBack(); 1151 public long getLong(String name)throws SQLException; 1152 public long getLongFromBuffer(String name); 1153 public String getString(String name)throws SQLException; 1154 public String getStringFromBuffer(String name); 1155 public ResultSet getSqlResultSet(); 1156 public void close() throws SQLException; 1157} 1158} 1159 | Popular Tags |