1 32 33 package com.nqadmin.swingSet.datasources; 34 35 import java.sql.SQLException ; 36 import java.sql.Connection ; 37 import java.sql.ResultSet ; 38 import java.sql.ResultSetMetaData ; 39 import java.io.ObjectInputStream ; 40 import java.io.IOException ; 41 import java.sql.Date ; 42 import javax.sql.RowSetListener ; 43 import com.sun.rowset.JdbcRowSetImpl; 44 import java.beans.PropertyChangeSupport ; 45 import java.beans.PropertyChangeListener ; 46 import java.beans.VetoableChangeSupport ; 47 import java.beans.VetoableChangeListener ; 48 import java.beans.PropertyVetoException ; 49 50 61 public class SSJdbcRowSetImpl extends SSRowSetAdapter { 62 63 66 protected SSConnection sSConnection = new SSConnection(); 67 68 71 protected String command = ""; 72 73 76 transient protected Connection connection; 77 78 81 transient protected JdbcRowSetImpl rowset; 82 83 86 transient protected ResultSetMetaData metaData; 87 88 91 private PropertyChangeSupport pChangeSupport = new PropertyChangeSupport (this); 92 93 96 private VetoableChangeSupport vChangeSupport = new VetoableChangeSupport (this); 97 98 101 public SSJdbcRowSetImpl(){ 102 } 103 104 108 public SSJdbcRowSetImpl(SSConnection _ssConnection) { 109 sSConnection = _ssConnection; 110 } 111 112 117 public SSJdbcRowSetImpl(SSConnection _ssConnection, String _command) { 118 sSConnection = _ssConnection; 119 command = _command; 120 } 121 122 127 public void addPropertyChangeListener(PropertyChangeListener _listener) { 128 pChangeSupport.addPropertyChangeListener(_listener); 129 } 130 131 136 public void removePropertyChangeListener(PropertyChangeListener _listener) { 137 pChangeSupport.removePropertyChangeListener(_listener); 138 } 139 140 145 public void addVetoableChangeListener(VetoableChangeListener _listener) { 146 vChangeSupport.addVetoableChangeListener(_listener); 147 } 148 149 154 public void removeVetoableChangeListener(VetoableChangeListener _listener) { 155 vChangeSupport.removeVetoableChangeListener(_listener); 156 } 157 158 162 public void setSSConnection(SSConnection _ssConnection) { 163 SSConnection oldValue = sSConnection; 164 sSConnection = _ssConnection; 165 pChangeSupport.firePropertyChange("ssConnection", oldValue, sSConnection); 166 } 167 168 172 public void setCommand(String _command) { 173 String oldValue = command; 174 command = _command; 175 pChangeSupport.firePropertyChange("command", oldValue, command); 176 177 try { 178 if (rowset != null) { 179 rowset.setCommand(command); 180 } 181 }catch(SQLException se){ 182 se.printStackTrace(); 183 } 184 } 185 186 190 public SSConnection getSSConnection(){ 191 return sSConnection; 192 } 193 194 198 public String getCommand(){ 199 return command; 200 } 201 202 210 public void execute() throws SQLException { 211 if(rowset == null){ 212 rowset = new JdbcRowSetImpl(sSConnection.getConnection()); 213 rowset.setType(ResultSet.TYPE_SCROLL_INSENSITIVE); 214 rowset.setConcurrency(ResultSet.CONCUR_UPDATABLE); 215 rowset.setCommand(command); 216 } 217 rowset.execute(); 218 metaData = rowset.getMetaData(); 219 } 220 221 224 protected void readObject(ObjectInputStream inStream) throws ClassNotFoundException , IOException { 225 inStream.defaultReadObject(); 226 connection = sSConnection.getConnection(); 228 try{ 229 rowset = new JdbcRowSetImpl(connection); 231 rowset.setType(ResultSet.TYPE_SCROLL_INSENSITIVE); 232 rowset.setConcurrency(ResultSet.CONCUR_UPDATABLE); 233 234 rowset.setCommand(command); 236 237 if(!command.equals("")){ 239 rowset.execute(); 240 metaData = rowset.getMetaData(); 241 } 242 }catch(SQLException se){ 243 se.printStackTrace(); 244 } 245 246 } 247 248 256 public boolean getBoolean(int columnIndex) throws SQLException { 257 return rowset.getBoolean(columnIndex); 258 } 259 260 268 public int getInt(int columnIndex) throws SQLException { 269 return rowset.getInt(columnIndex); 270 } 271 272 280 public long getLong(int columnIndex) throws SQLException { 281 return rowset.getLong(columnIndex); 282 } 283 284 292 public float getFloat(int columnIndex) throws SQLException { 293 return rowset.getFloat(columnIndex); 294 } 295 296 304 public double getDouble(int columnIndex) throws SQLException { 305 return rowset.getDouble(columnIndex); 306 } 307 308 316 public String getString(int columnIndex) throws SQLException { 317 return rowset.getString(columnIndex); 318 } 319 320 328 public Date getDate(int columnIndex) throws SQLException { 329 return rowset.getDate(columnIndex); 330 } 331 332 340 public byte[] getBytes(int columnIndex) throws SQLException { 341 return rowset.getBytes(columnIndex); 342 } 343 344 353 public void updateBoolean(int columnIndex, boolean value) throws SQLException { 354 rowset.updateBoolean(columnIndex, value); 355 } 356 357 366 public void updateInt(int columnIndex, int value) throws SQLException { 367 rowset.updateInt(columnIndex, value); 368 } 369 370 379 public void updateLong(int columnIndex, long value) throws SQLException { 380 rowset.updateLong(columnIndex, value); 381 } 382 383 392 public void updateFloat(int columnIndex, float value) throws SQLException { 393 rowset.updateFloat(columnIndex, value); 394 } 395 396 405 public void updateDouble(int columnIndex, double value) throws SQLException { 406 rowset.updateDouble(columnIndex, value); 407 } 408 409 418 public void updateString(int columnIndex, String value) throws SQLException { 419 rowset.updateString(columnIndex, value); 420 } 421 422 431 public void updateDate(int columnIndex, Date value) throws SQLException { 432 rowset.updateDate(columnIndex, value); 433 } 434 435 444 public void updateBytes(int columnIndex, byte[] value) throws SQLException { 445 rowset.updateBytes(columnIndex, value); 446 } 447 448 456 public void updateNull(int columnIndex) throws SQLException { 457 rowset.updateNull(columnIndex); 458 } 459 460 468 public boolean getBoolean(String columnName) throws SQLException { 469 return rowset.getBoolean(columnName); 470 } 471 472 480 public int getInt(String columnName) throws SQLException { 481 return rowset.getInt(columnName); 482 } 483 484 492 public long getLong(String columnName) throws SQLException { 493 return rowset.getLong(columnName); 494 } 495 496 504 public float getFloat(String columnName) throws SQLException { 505 return rowset.getFloat(columnName); 506 } 507 508 516 public double getDouble(String columnName) throws SQLException { 517 return rowset.getDouble(columnName); 518 } 519 520 528 public String getString(String columnName) throws SQLException { 529 return rowset.getString(columnName); 530 } 531 532 540 public Date getDate(String columnName) throws SQLException { 541 return rowset.getDate(columnName); 542 } 543 544 552 public byte[] getBytes(String columnName) throws SQLException { 553 return rowset.getBytes(columnName); 554 } 555 556 565 public void updateBoolean(String columnName, boolean value) throws SQLException { 566 rowset.updateBoolean(columnName, value); 567 } 568 569 578 public void updateInt(String columnName, int value) throws SQLException { 579 rowset.updateInt(columnName, value); 580 } 581 582 591 public void updateLong(String columnName, long value) throws SQLException { 592 rowset.updateLong(columnName, value); 593 } 594 595 604 public void updateFloat(String columnName, float value) throws SQLException { 605 rowset.updateFloat(columnName, value); 606 } 607 608 617 public void updateDouble(String columnName, double value) throws SQLException { 618 rowset.updateDouble(columnName, value); 619 } 620 621 630 public void updateString(String columnName, String value) throws SQLException { 631 rowset.updateString(columnName, value); 632 } 633 634 643 public void updateDate(String columnName, Date value) throws SQLException { 644 rowset.updateDate(columnName, value); 645 } 646 647 656 public void updateBytes(String columnName, byte[] value) throws SQLException { 657 rowset.updateBytes(columnName, value); 658 } 659 660 668 public void updateNull(String columnName) throws SQLException { 669 rowset.updateNull(columnName); 670 } 671 672 685 public void addRowSetListener(RowSetListener listener){ 686 rowset.addRowSetListener(listener); 687 } 688 689 695 public void removeRowSetListener(RowSetListener listener){ 696 rowset.removeRowSetListener(listener); 697 } 698 699 706 public String getColumnName(int columnIndex) throws SQLException { 707 return metaData.getColumnName(columnIndex); 708 } 709 710 716 public int getColumnIndex(String columnName) throws SQLException { 717 return rowset.findColumn(columnName); 718 } 719 720 726 public int getColumnType(String columnName) throws SQLException { 727 return metaData.getColumnType(getColumnIndex(columnName)); 728 } 729 730 736 public int getColumnType(int columnIndex) throws SQLException { 737 return metaData.getColumnType(columnIndex); 738 } 739 740 746 public int getRow() throws SQLException { 747 return rowset.getRow(); 748 } 749 750 755 public int getColumnCount() throws SQLException { 756 return metaData.getColumnCount(); 757 } 758 759 770 public boolean next() throws SQLException { 771 return rowset.next(); 772 } 773 774 779 public boolean previous() throws SQLException { 780 return rowset.previous(); 781 } 782 783 789 public boolean last() throws SQLException { 790 return rowset.last(); 791 } 792 793 799 public boolean first() throws SQLException { 800 return rowset.first(); 801 } 802 803 808 public boolean isFirst() throws SQLException { 809 return rowset.isFirst(); 810 } 811 812 820 public boolean isLast() throws SQLException { 821 return rowset.isLast(); 822 } 823 824 829 public void beforeFirst() throws SQLException { 830 rowset.beforeFirst(); 831 } 832 833 850 public boolean absolute(int row) throws SQLException { 851 return rowset.absolute(row); 852 } 853 854 860 public void updateRow() throws SQLException { 861 rowset.updateRow(); 862 } 863 864 869 public void moveToCurrentRow() throws SQLException { 870 rowset.moveToCurrentRow(); 871 } 872 873 885 public void moveToInsertRow() throws SQLException { 886 rowset.moveToInsertRow(); 887 } 888 889 896 public void insertRow() throws SQLException { 897 rowset.insertRow(); 898 } 899 900 906 public void deleteRow() throws SQLException { 907 rowset.deleteRow(); 908 } 909 910 918 public void cancelRowUpdates() throws SQLException { 919 rowset.cancelRowUpdates(); 920 } 921 922 937 public void refreshRow() throws SQLException { 938 rowset.refreshRow(); 939 } 940 941 } 942 | Popular Tags |