@@ -41,24 +41,25 @@ public boolean wasNull() throws SQLException {
41
41
return wasNull ;
42
42
}
43
43
44
- private <T > T getValue (String columnLabel , SqlValueGetter <T > getter ) throws SQLException {
45
- return getValue (findColumn (columnLabel ), getter );
46
- }
47
-
48
44
private <T > T getValue (int columnIndex , SqlValueGetter <T > getter ) throws SQLException {
49
45
if (columnIndex == 1 ) {
50
- throw new IllegalArgumentException (
51
- "The first element of Array-backed ResultSet can only be retrieved with getInt() " );
46
+ throw new SQLException (
47
+ "The first element of Array-backed ResultSet can only be retrieved with numeric getters " );
52
48
}
53
49
if (columnIndex != 2 ) {
54
- throw new IllegalArgumentException ("Array-backed ResultSet can only have two columns" );
50
+ throw new SQLException ("Array-backed ResultSet can only have two columns" );
55
51
}
56
52
T value = getter .getValue (offset + currentValueIndex );
57
53
58
54
wasNull = value == null ;
59
55
return value ;
60
56
}
61
57
58
+ private int getIndexColumnValue () {
59
+ wasNull = false ;
60
+ return currentValueIndex + 1 ;
61
+ }
62
+
62
63
@ Override
63
64
public String getString (int columnIndex ) throws SQLException {
64
65
return getValue (columnIndex , vector ::getLazyString );
@@ -71,40 +72,57 @@ public boolean getBoolean(int columnIndex) throws SQLException {
71
72
72
73
@ Override
73
74
public byte getByte (int columnIndex ) throws SQLException {
75
+ if (columnIndex == 1 ) {
76
+ return (byte ) getIndexColumnValue ();
77
+ }
74
78
return getValue (columnIndex , vector ::getByte );
75
79
}
76
80
77
81
@ Override
78
82
public short getShort (int columnIndex ) throws SQLException {
83
+ if (columnIndex == 1 ) {
84
+ return (short ) getIndexColumnValue ();
85
+ }
79
86
return getValue (columnIndex , vector ::getShort );
80
87
}
81
88
82
89
@ Override
83
90
public int getInt (int columnIndex ) throws SQLException {
84
91
if (columnIndex == 1 ) {
85
- wasNull = false ;
86
- return currentValueIndex + 1 ;
92
+ return getIndexColumnValue ();
87
93
}
88
94
return getValue (columnIndex , vector ::getInt );
89
95
}
90
96
91
97
@ Override
92
98
public long getLong (int columnIndex ) throws SQLException {
93
- return getInt (columnIndex );
99
+ if (columnIndex == 1 ) {
100
+ return getIndexColumnValue ();
101
+ }
102
+ return getValue (columnIndex , vector ::getLong );
94
103
}
95
104
96
105
@ Override
97
106
public float getFloat (int columnIndex ) throws SQLException {
107
+ if (columnIndex == 1 ) {
108
+ return getIndexColumnValue ();
109
+ }
98
110
return getValue (columnIndex , vector ::getFloat );
99
111
}
100
112
101
113
@ Override
102
114
public double getDouble (int columnIndex ) throws SQLException {
115
+ if (columnIndex == 1 ) {
116
+ return getIndexColumnValue ();
117
+ }
103
118
return getValue (columnIndex , vector ::getDouble );
104
119
}
105
120
106
121
@ Override
107
122
public BigDecimal getBigDecimal (int columnIndex , int scale ) throws SQLException {
123
+ if (columnIndex == 1 ) {
124
+ return BigDecimal .valueOf (getIndexColumnValue ());
125
+ }
108
126
return getValue (columnIndex , vector ::getBigDecimal );
109
127
}
110
128
@@ -145,51 +163,47 @@ public InputStream getBinaryStream(int columnIndex) throws SQLException {
145
163
146
164
@ Override
147
165
public String getString (String columnLabel ) throws SQLException {
148
- return getValue ( columnLabel , vector :: getLazyString );
166
+ return getString ( findColumn ( columnLabel ) );
149
167
}
150
168
151
169
@ Override
152
170
public boolean getBoolean (String columnLabel ) throws SQLException {
153
- return getValue ( columnLabel , vector :: getBoolean );
171
+ return getBoolean ( findColumn ( columnLabel ) );
154
172
}
155
173
156
174
@ Override
157
175
public byte getByte (String columnLabel ) throws SQLException {
158
- return getValue ( columnLabel , vector :: getByte );
176
+ return getByte ( findColumn ( columnLabel ) );
159
177
}
160
178
161
179
@ Override
162
180
public short getShort (String columnLabel ) throws SQLException {
163
- return getValue ( columnLabel , vector :: getShort );
181
+ return getShort ( findColumn ( columnLabel ) );
164
182
}
165
183
166
184
@ Override
167
185
public int getInt (String columnLabel ) throws SQLException {
168
- int columnIndex = findColumn (columnLabel );
169
- if (columnIndex == 1 ) {
170
- return currentValueIndex ;
171
- }
172
- return getValue (columnIndex , vector ::getInt );
186
+ return getInt (findColumn (columnLabel ));
173
187
}
174
188
175
189
@ Override
176
190
public long getLong (String columnLabel ) throws SQLException {
177
- return getInt ( columnLabel );
191
+ return getLong ( findColumn ( columnLabel ) );
178
192
}
179
193
180
194
@ Override
181
195
public float getFloat (String columnLabel ) throws SQLException {
182
- return getValue ( columnLabel , vector :: getFloat );
196
+ return getFloat ( findColumn ( columnLabel ) );
183
197
}
184
198
185
199
@ Override
186
200
public double getDouble (String columnLabel ) throws SQLException {
187
- return getValue ( columnLabel , vector :: getDouble );
201
+ return getDouble ( findColumn ( columnLabel ) );
188
202
}
189
203
190
204
@ Override
191
205
public BigDecimal getBigDecimal (String columnLabel , int scale ) throws SQLException {
192
- return getValue ( columnLabel , vector :: getBigDecimal );
206
+ return getBigDecimal ( findColumn ( columnLabel ), scale );
193
207
}
194
208
195
209
@ Override
@@ -199,17 +213,17 @@ public byte[] getBytes(String columnLabel) throws SQLException {
199
213
200
214
@ Override
201
215
public Date getDate (String columnLabel ) throws SQLException {
202
- return getValue ( columnLabel , vector :: getDate );
216
+ return getDate ( findColumn ( columnLabel ) );
203
217
}
204
218
205
219
@ Override
206
220
public Time getTime (String columnLabel ) throws SQLException {
207
- return getValue ( columnLabel , vector :: getTime );
221
+ return getTime ( findColumn ( columnLabel ) );
208
222
}
209
223
210
224
@ Override
211
225
public Timestamp getTimestamp (String columnLabel ) throws SQLException {
212
- return getValue ( columnLabel , vector :: getTimestamp );
226
+ return getTimestamp ( findColumn ( columnLabel ) );
213
227
}
214
228
215
229
@ Override
@@ -254,12 +268,18 @@ public Object getObject(int columnIndex) throws SQLException {
254
268
255
269
@ Override
256
270
public Object getObject (String columnLabel ) throws SQLException {
257
- return getValue ( columnLabel , vector :: getTimestamp );
271
+ return getObject ( findColumn ( columnLabel ) );
258
272
}
259
273
260
274
@ Override
261
275
public int findColumn (String columnLabel ) throws SQLException {
262
- return Integer .parseInt (columnLabel );
276
+ if ("INDEX" .equalsIgnoreCase (columnLabel )) {
277
+ return 1 ;
278
+ }
279
+ if ("VALUE" .equalsIgnoreCase (columnLabel )) {
280
+ return 2 ;
281
+ }
282
+ throw new SQLException ("Could not find column with label " + columnLabel );
263
283
}
264
284
265
285
@ Override
@@ -279,7 +299,7 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
279
299
280
300
@ Override
281
301
public BigDecimal getBigDecimal (String columnLabel ) throws SQLException {
282
- return getValue ( columnLabel , vector :: getBigDecimal );
302
+ return getBigDecimal ( findColumn ( columnLabel ) );
283
303
}
284
304
285
305
@ Override
@@ -671,7 +691,7 @@ public Array getArray(int columnIndex) throws SQLException {
671
691
672
692
@ Override
673
693
public Object getObject (String columnLabel , Map <String , Class <?>> map ) throws SQLException {
674
- return getValue ( columnLabel , vector :: getObject );
694
+ return getObject ( findColumn ( columnLabel ) );
675
695
}
676
696
677
697
@ Override
@@ -691,7 +711,7 @@ public Clob getClob(String columnLabel) throws SQLException {
691
711
692
712
@ Override
693
713
public Array getArray (String columnLabel ) throws SQLException {
694
- return getValue ( columnLabel , vector :: getArray );
714
+ return getArray ( findColumn ( columnLabel ) );
695
715
}
696
716
697
717
@ Override
0 commit comments