Skip to content

Commit a6da614

Browse files
committed
refactor: drop StreamingResultSet getObject(Class) bandaid
Now that QueryJDBCAccessor.getObject(Class) provides the raw + isInstance fallback as its base-class default, StreamingResultSet no longer needs the catch-and-retry path that worked around accessors which threw "Operation not supported." Collapse getObject(int, Class) to direct dispatch and update the regression test's WHY comment to point at the accessor base class as the load-bearing layer. Addresses: review comment on PR #175 line 388.
1 parent 2cc9e98 commit a6da614

2 files changed

Lines changed: 8 additions & 31 deletions

File tree

jdbc-core/src/main/java/com/salesforce/datacloud/jdbc/core/StreamingResultSet.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -360,32 +360,10 @@ public Object getObject(int columnIndex, Map<String, Class<?>> map) throws SQLEx
360360

361361
@Override
362362
public <T> T getObject(int columnIndex, Class<T> type) throws SQLException {
363-
if (type == null) {
364-
throw new SQLException("Target type must not be null");
365-
}
366-
// Default implementation: get the raw Object and check if it matches the requested type.
367-
// Accessors that need richer conversion (e.g. Arrow Decimal → BigInteger) can still
368-
// override the accessor-level getObject(Class) — in that case we dispatch to them first.
369363
val accessor = getAccessor(columnIndex);
370-
try {
371-
val typed = accessor.getObject(type);
372-
updateWasNull(accessor);
373-
return typed;
374-
} catch (SQLException ex) {
375-
// Accessor does not implement typed getObject — fall back to raw + isInstance check.
376-
val raw = accessor.getObject();
377-
updateWasNull(accessor);
378-
if (raw == null) {
379-
return null;
380-
}
381-
if (type.isInstance(raw)) {
382-
return type.cast(raw);
383-
}
384-
throw new SQLException(
385-
"Cannot convert column value to " + type.getName() + "; actual type is "
386-
+ raw.getClass().getName(),
387-
ex);
388-
}
364+
val result = accessor.getObject(type);
365+
updateWasNull(accessor);
366+
return result;
389367
}
390368

391369
@Override

jdbc-core/src/test/java/com/salesforce/datacloud/jdbc/core/StreamingResultSetMethodTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,11 @@ void methodsThrowAfterClose() throws Exception {
191191
}
192192

193193
@Test
194-
void getObjectWithClassFallsBackToIsInstanceOnAccessorWithoutTypedOverload() throws Exception {
195-
// VarCharVectorAccessor does not override getObject(Class). Without the fallback path
196-
// in StreamingResultSet.getObject(int, Class), getObject(col, String.class) on a VARCHAR
197-
// column would throw outright. This test pins that the fallback (raw + isInstance) wires
198-
// a String back to the caller. If the catch-block fallback is removed by a future
199-
// refactor, this assertion fires.
194+
void getObjectWithClassUsesAccessorBaseFallback() throws Exception {
195+
// VarCharVectorAccessor does not override getObject(Class); it inherits the default in
196+
// QueryJDBCAccessor that does raw + isInstance. Pin that this delivers a String for a
197+
// VARCHAR column — regressing the base-class fallback breaks every accessor that does
198+
// not implement typed conversion of its own.
200199
try (val rs = createResultSet()) {
201200
rs.next();
202201
assertThat(rs.getObject(1, String.class)).isEqualTo("hello");

0 commit comments

Comments
 (0)