2
Copyright (C) 2009, 2011 Volker Berlin (i-net software)
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
24
package sun.jdbc.odbc;
26
import java.io.InputStream;
27
import java.io.Reader;
28
import java.math.BigDecimal;
31
import cli.System.Data.Common.*;
34
* This JDBC Driver is a wrapper to the ODBC.NET Data Provider. This ResultSet based on a DataReader.
36
public class JdbcOdbcResultSet extends JdbcOdbcObject implements ResultSet{
38
private DbDataReader reader;
40
private final JdbcOdbcStatement statement;
42
private final int holdability;
44
private final int concurrency;
46
private int fetchSize;
50
private final int resultSetType;
52
private ResultSetMetaData metaData;
56
* Create a ResultSet that based on a DbDataReader
59
* the statement for getStatement(), can be null
61
* the reader for the data access, if it null then the resultset is closed.
63
public JdbcOdbcResultSet(JdbcOdbcStatement statement, DbDataReader reader){
64
this.statement = statement;
66
this.resultSetType = TYPE_FORWARD_ONLY;
67
this.concurrency = CONCUR_READ_ONLY;
68
this.holdability = HOLD_CURSORS_OVER_COMMIT;
73
* A constructor for extended classes. All methods that use the reader must be overridden if you use this
77
* the statement for getStatement(), can be null
78
* @param resultSetType
79
* a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or
80
* ResultSet.TYPE_SCROLL_SENSITIVE
82
* a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
84
protected JdbcOdbcResultSet(JdbcOdbcStatement statement, int resultSetType, int concurrency){
85
this.statement = statement;
87
this.resultSetType = resultSetType;
88
this.concurrency = concurrency;
89
this.holdability = HOLD_CURSORS_OVER_COMMIT;
93
public boolean absolute(int rowPosition) throws SQLException{
95
return false; // for Compiler
99
public void afterLast() throws SQLException{
104
public void beforeFirst() throws SQLException{
109
public void cancelRowUpdates() throws SQLException{
114
public void clearWarnings() throws SQLException{
115
// TODO Auto-generated method stub
122
statement.closeReaderIfPossible();
126
public void deleteRow() throws SQLException{
132
public int findColumn(String columnLabel) throws SQLException{
134
return getReader().GetOrdinal(columnLabel) + 1;
135
}catch(ArrayIndexOutOfBoundsException ex){
136
throw new SQLException("Column '" + columnLabel + "' not found.", "S0022", ex);
141
public boolean first() throws SQLException{
143
return false; // for compiler
147
public int getConcurrency(){
152
public String getCursorName() throws SQLException{
153
// TODO Auto-generated method stub
158
public int getFetchDirection(){
159
return FETCH_UNKNOWN;
163
public int getFetchSize(){
168
public int getHoldability(){
173
public ResultSetMetaData getMetaData() throws SQLException{
174
if(metaData == null){
175
metaData = new JdbcOdbcResultSetMetaData(getReader());
181
public int getRow() throws SQLException{
182
getReader(); // checking for is closed
187
public Statement getStatement(){
192
public int getType(){
193
return resultSetType;
197
public SQLWarning getWarnings() throws SQLException{
198
// TODO Auto-generated method stub
203
public void insertRow() throws SQLException{
208
public boolean isAfterLast() throws SQLException{
210
return false; // only for compiler
214
public boolean isBeforeFirst() throws SQLException{
216
return false; // only for compiler
220
public boolean isClosed(){
221
return reader == null;
225
public boolean isFirst() throws SQLException{
227
return false; // only for compiler
231
public boolean isLast() throws SQLException{
233
return false; // only for compiler
237
public boolean last() throws SQLException{
239
return false; // only for compiler
243
public void moveToCurrentRow() throws SQLException{
248
public void moveToInsertRow() throws SQLException{
253
public boolean next() throws SQLException{
254
DbDataReader dataReader = getReader();
255
//if we after the last row then we close the reader
256
//to prevent an error on repeating call of next() after the end
257
//that we check also get_IsClosed()
258
if(!dataReader.get_IsClosed() && dataReader.Read()){
263
statement.closeReaderIfPossible();
268
public boolean previous() throws SQLException{
270
return false; // only for compiler
274
public void refreshRow() throws SQLException{
279
public boolean relative(int rowPositions) throws SQLException{
281
return false; // only for compiler
285
public boolean rowDeleted() throws SQLException{
287
return false; // only for compiler
291
public boolean rowInserted() throws SQLException{
293
return false; // only for compiler
297
public boolean rowUpdated() throws SQLException{
299
return false; // only for compiler
303
public void setFetchDirection(int direction){
308
public void setFetchSize(int rows){
313
public void updateArray(int columnIndex, Array x) throws SQLException{
314
updateObject(columnIndex, x);
318
public void updateArray(String columnLabel, Array x) throws SQLException{
319
updateArray(findColumn(columnLabel), x);
323
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException{
324
updateObject(columnIndex, x, length);
328
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException{
329
updateObject(findColumn(columnLabel), x, length);
333
public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException{
334
updateObject(columnIndex, x, (int)length);
338
public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException{
339
updateObject(findColumn(columnLabel), x, (int)length);
343
public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException{
344
updateObject(columnIndex, x);
348
public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException{
349
updateObject(findColumn(columnLabel), x);
353
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException{
354
updateObject(columnIndex, x);
358
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException{
359
updateObject(findColumn(columnLabel), x);
363
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException{
364
updateObject(columnIndex, x, length);
368
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException{
369
updateObject(findColumn(columnLabel), x, length);
373
public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException{
374
updateObject(columnIndex, x, (int)length);
378
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException{
379
updateObject(findColumn(columnLabel), x, (int)length);
383
public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException{
384
updateObject(columnIndex, x);
388
public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException{
389
updateObject(findColumn(columnLabel), x);
393
public void updateBlob(int columnIndex, Blob x) throws SQLException{
394
updateObject(columnIndex, x);
398
public void updateBlob(String columnLabel, Blob x) throws SQLException{
399
updateObject(findColumn(columnLabel), x);
403
public void updateBlob(int columnIndex, InputStream x, long length) throws SQLException{
404
updateObject(columnIndex, x, (int)length);
408
public void updateBlob(String columnLabel, InputStream x, long length) throws SQLException{
409
updateObject(findColumn(columnLabel), x, (int)length);
413
public void updateBlob(int columnIndex, InputStream x) throws SQLException{
414
updateObject(columnIndex, x);
418
public void updateBlob(String columnLabel, InputStream x) throws SQLException{
419
updateObject(findColumn(columnLabel), x);
423
public void updateBoolean(int columnIndex, boolean x) throws SQLException{
424
updateObject(columnIndex, Boolean.valueOf(x));
428
public void updateBoolean(String columnLabel, boolean x) throws SQLException{
429
updateObject(findColumn(columnLabel), Boolean.valueOf(x));
433
public void updateByte(int columnIndex, byte x) throws SQLException{
434
updateObject(columnIndex, Byte.valueOf(x));
438
public void updateByte(String columnLabel, byte x) throws SQLException{
439
updateObject(findColumn(columnLabel), Byte.valueOf(x));
443
public void updateBytes(int columnIndex, byte[] x) throws SQLException{
444
updateObject(columnIndex, x);
448
public void updateBytes(String columnLabel, byte[] x) throws SQLException{
449
updateObject(findColumn(columnLabel), x);
453
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException{
454
updateObject(columnIndex, x, length);
458
public void updateCharacterStream(String columnLabel, Reader x, int length) throws SQLException{
459
updateObject(findColumn(columnLabel), x, length);
463
public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException{
464
updateObject(columnIndex, x, (int)length);
468
public void updateCharacterStream(String columnLabel, Reader x, long length) throws SQLException{
469
updateObject(findColumn(columnLabel), x, (int)length);
473
public void updateCharacterStream(int columnIndex, Reader x) throws SQLException{
474
updateObject(columnIndex, x);
478
public void updateCharacterStream(String columnLabel, Reader x) throws SQLException{
479
updateObject(findColumn(columnLabel), x);
483
public void updateClob(int columnIndex, Clob x) throws SQLException{
484
updateObject(columnIndex, x);
488
public void updateClob(String columnLabel, Clob x) throws SQLException{
489
updateObject(findColumn(columnLabel), x);
493
public void updateClob(int columnIndex, Reader x, long length) throws SQLException{
494
updateObject(columnIndex, x, (int)length);
498
public void updateClob(String columnLabel, Reader x, long length) throws SQLException{
499
updateObject(findColumn(columnLabel), x, (int)length);
503
public void updateClob(int columnIndex, Reader x) throws SQLException{
504
updateObject(columnIndex, x);
508
public void updateClob(String columnLabel, Reader x) throws SQLException{
509
updateObject(findColumn(columnLabel), x);
513
public void updateDate(int columnIndex, Date x) throws SQLException{
514
updateObject(columnIndex, x);
518
public void updateDate(String columnLabel, Date x) throws SQLException{
519
updateObject(findColumn(columnLabel), x);
523
public void updateDouble(int columnIndex, double x) throws SQLException{
524
updateObject(columnIndex, Double.valueOf(x));
528
public void updateDouble(String columnLabel, double x) throws SQLException{
529
updateObject(findColumn(columnLabel), Double.valueOf(x));
533
public void updateFloat(int columnIndex, float x) throws SQLException{
534
updateObject(columnIndex, Float.valueOf(x));
538
public void updateFloat(String columnLabel, float x) throws SQLException{
539
updateObject(findColumn(columnLabel), Float.valueOf(x));
543
public void updateInt(int columnIndex, int x) throws SQLException{
544
updateObject(columnIndex, Integer.valueOf(x));
548
public void updateInt(String columnLabel, int x) throws SQLException{
549
updateObject(findColumn(columnLabel), Integer.valueOf(x));
553
public void updateLong(int columnIndex, long x) throws SQLException{
554
updateObject(columnIndex, Long.valueOf(x));
558
public void updateLong(String columnLabel, long x) throws SQLException{
559
updateObject(findColumn(columnLabel), Long.valueOf(x));
563
public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException{
564
updateObject(columnIndex, x, (int)length);
568
public void updateNCharacterStream(String columnLabel, Reader x, long length) throws SQLException{
569
updateObject(findColumn(columnLabel), x, (int)length);
573
public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException{
574
updateObject(columnIndex, x);
578
public void updateNCharacterStream(String columnLabel, Reader x) throws SQLException{
579
updateObject(findColumn(columnLabel), x);
583
public void updateNClob(int columnIndex, NClob x) throws SQLException{
584
updateObject(columnIndex, x);
588
public void updateNClob(String columnLabel, NClob x) throws SQLException{
589
updateObject(findColumn(columnLabel), x);
593
public void updateNClob(int columnIndex, Reader x, long length) throws SQLException{
594
updateObject(columnIndex, x, (int)length);
598
public void updateNClob(String columnLabel, Reader x, long length) throws SQLException{
599
updateObject(findColumn(columnLabel), x, (int)length);
603
public void updateNClob(int columnIndex, Reader x) throws SQLException{
604
updateObject(columnIndex, x);
608
public void updateNClob(String columnLabel, Reader x) throws SQLException{
609
updateObject(findColumn(columnLabel), x);
613
public void updateNString(int columnIndex, String x) throws SQLException{
614
updateObject(columnIndex, x);
618
public void updateNString(String columnLabel, String x) throws SQLException{
619
updateObject(findColumn(columnLabel), x);
623
public void updateNull(int columnIndex) throws SQLException{
624
updateObject(columnIndex, null);
628
public void updateNull(String columnLabel) throws SQLException{
629
updateObject(findColumn(columnLabel), null);
633
public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException{
638
public void updateObject(int columnIndex, Object x) throws SQLException{
639
updateObject(columnIndex, x, -1);
643
public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException{
644
updateObject(findColumn(columnLabel), x, scaleOrLength);
648
public void updateObject(String columnLabel, Object x) throws SQLException{
649
updateObject(findColumn(columnLabel), x);
653
public void updateRef(int columnIndex, Ref x) throws SQLException{
654
updateObject(columnIndex, x);
658
public void updateRef(String columnLabel, Ref x) throws SQLException{
659
updateObject(findColumn(columnLabel), x);
663
public void updateRow() throws SQLException{
668
public void updateRowId(int columnIndex, RowId x) throws SQLException{
669
updateObject(columnIndex, x);
673
public void updateRowId(String columnLabel, RowId x) throws SQLException{
674
updateObject(findColumn(columnLabel), x);
678
public void updateSQLXML(int columnIndex, SQLXML x) throws SQLException{
679
updateObject(columnIndex, x);
683
public void updateSQLXML(String columnLabel, SQLXML x) throws SQLException{
684
updateObject(findColumn(columnLabel), x);
688
public void updateShort(int columnIndex, short x) throws SQLException{
689
updateObject(columnIndex, Short.valueOf(x));
693
public void updateShort(String columnLabel, short x) throws SQLException{
694
updateObject(findColumn(columnLabel), Short.valueOf(x));
698
public void updateString(int columnIndex, String x) throws SQLException{
699
updateObject(columnIndex, x);
703
public void updateString(String columnLabel, String x) throws SQLException{
704
updateObject(findColumn(columnLabel), x);
708
public void updateTime(int columnIndex, Time x) throws SQLException{
709
updateObject(columnIndex, x);
713
public void updateTime(String columnLabel, Time x) throws SQLException{
714
updateObject(findColumn(columnLabel), x);
718
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException{
719
updateObject(columnIndex, x);
723
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException{
724
updateObject(findColumn(columnLabel), x);
728
public boolean isWrapperFor(Class<?> iface){
729
return iface.isAssignableFrom(this.getClass());
733
public <T>T unwrap(Class<T> iface) throws SQLException{
734
if(isWrapperFor(iface)){
737
throw new SQLException(this.getClass().getName() + " does not implements " + iface.getName() + ".", "01000");
741
private void throwForwardOnly() throws SQLException{
742
throw new SQLException("ResultSet is forward only.", "24000");
746
private void throwReadOnly() throws SQLException{
747
throw new SQLException("ResultSet is read only.", "24000");
752
* Check if this ResultSet is closed before access to the DbDataReader
755
* @throws SQLException
757
private DbDataReader getReader() throws SQLException{
759
throw new SQLException("ResultSet is closed.", "24000");
769
protected Object getObjectImpl(int columnIndex) throws SQLException{
771
DbDataReader datareader = getReader();
773
return datareader.get_Item(columnIndex-1);
774
}catch(ArrayIndexOutOfBoundsException aioobe){
775
throw new SQLException( "Invalid column number ("+columnIndex+"). A number between 1 and "+datareader.get_FieldCount()+" is valid.", "S1002", aioobe);
777
}catch(Throwable ex){
778
throw JdbcOdbcUtils.createSQLException(ex);
786
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
787
throw new SQLFeatureNotSupportedException();
794
public <T> T getObject(String columnLabel, Class<T> type)
795
throws SQLException {
796
throw new SQLFeatureNotSupportedException();