Commit 09593d6
committed
fix: provide default getObject(Class) fallback in QueryJDBCAccessor
QueryJDBCAccessor.getObject(Class) threw "Operation not supported" no
matter what. That's a problem: JDBC says
ResultSet.getObject(int, Class<T>) is supposed to return the value as
T when the conversion is trivial, but every accessor that didn't
override it would throw, even on the identity case like
getObject(col, String.class) against a VARCHAR. Callers had to either
know which accessors implement typed conversion or wrap calls in
catch-and-retry.
The new default does the obvious thing: reject null type with SQLState
22023, fetch the raw object, return null if it's null, return it cast
to T if type.isInstance(raw), otherwise throw a typed conversion
error. Accessors with richer needs (timestamp accessors return
Instant, OffsetDateTime, etc.) keep their overrides.
TimeStampVectorAccessor and TimeStampTZVectorAccessor are the two
that have them today.
Tests in StreamingResultSetMethodTest cover:
- getObjectWithClassUsesAccessorBaseFallback: identity case
(VARCHAR -> String) returns the value via the inherited fallback.
- getObjectWithNullClassThrows: null type parameter raises
SQLException with the expected "must not be null" message.
- getObjectWithIncompatibleClassThrows: requesting an unrelated type
(String column, StringBuilder asked) raises the typed conversion
error rather than returning null or the raw value.
- getObjectWithClassReturnsNullForNullValue: a null column value
short-circuits and returns null regardless of the requested type;
wasNull() is true afterwards.
The existing QueryJDBCAccessorTest still passes since it doesn't
touch getObject(Class). Null-type rejection is also pinned by
TimeStampVectorAccessorTest and
TimeZoneIntegrationTest.testGetObjectWithNullTypeThrows.1 parent 092ac4d commit 09593d6
2 files changed
Lines changed: 83 additions & 4 deletions
File tree
- jdbc-core/src
- main/java/com/salesforce/datacloud/jdbc/core/accessor
- test/java/com/salesforce/datacloud/jdbc/core
Lines changed: 22 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | | - | |
197 | | - | |
198 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
199 | 218 | | |
200 | 219 | | |
201 | 220 | | |
| |||
Lines changed: 61 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
44 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
45 | 59 | | |
46 | 60 | | |
47 | 61 | | |
| |||
143 | 157 | | |
144 | 158 | | |
145 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
146 | 206 | | |
147 | 207 | | |
148 | 208 | | |
| |||
0 commit comments