Skip to content

Commit 490471f

Browse files
committed
Improve encapsulation of ResultSet tracking
1 parent 9f73d22 commit 490471f

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightConnection.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public final class ArrowFlightConnection extends AvaticaConnection {
4444
private final ArrowFlightSqlClientHandler clientHandler;
4545
private final ArrowFlightConnectionConfigImpl config;
4646
private ExecutorService executorService;
47-
int metadataResultSetCount;
48-
Map<Integer, ArrowFlightJdbcFlightStreamResultSet> metadataResultSetMap = new HashMap<>();
47+
private int metadataResultSetCount;
48+
private Map<Integer, ArrowFlightJdbcFlightStreamResultSet> metadataResultSetMap = new HashMap<>();
4949

5050
/**
5151
* Creates a new {@link ArrowFlightConnection}.
@@ -178,6 +178,31 @@ synchronized ExecutorService getExecutorService() {
178178
: executorService;
179179
}
180180

181+
/**
182+
* Registers a new metadata ResultSet and assigns it a unique ID. Metadata ResultSets are those
183+
* created without an associated Statement.
184+
*
185+
* @param resultSet the ResultSet to register
186+
* @return the assigned ID
187+
*/
188+
int getNewMetadataResultSetId(ArrowFlightJdbcFlightStreamResultSet resultSet) {
189+
metadataResultSetMap.put(metadataResultSetCount, resultSet);
190+
return metadataResultSetCount++;
191+
}
192+
193+
/**
194+
* Unregisters a metadata ResultSet when it is closed. This method is called by metadata
195+
* ResultSets during their close operation to remove themselves from the tracking map.
196+
*
197+
* @param id the ID of the ResultSet to unregister, or null if not a metadata ResultSet
198+
*/
199+
void onResultSetClose(Integer id) {
200+
if (id == null) {
201+
return;
202+
}
203+
metadataResultSetMap.remove(id);
204+
}
205+
181206
@Override
182207
public Properties getClientInfo() {
183208
final Properties copy = new Properties();

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcFlightStreamResultSet.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ private ArrowFlightJdbcFlightStreamResultSet(
8383
super(null, state, signature, resultSetMetaData, timeZone, firstFrame);
8484
this.connection = connection;
8585
this.flightInfo = flightInfo;
86-
this.id = connection.metadataResultSetCount++;
87-
connection.metadataResultSetMap.put(id, this);
86+
this.id = connection.getNewMetadataResultSetId(this);
8887
}
8988

9089
/**
@@ -242,9 +241,7 @@ public synchronized void close() {
242241
if (isClosed()) {
243242
return;
244243
}
245-
if (id != null) { // id is only set for metadata result sets
246-
this.connection.metadataResultSetMap.remove(id);
247-
}
244+
this.connection.onResultSetClose(id);
248245
if (flightEndpointDataQueue != null) {
249246
// flightStreamQueue should close currentFlightStream internally
250247
flightEndpointDataQueue.close();

0 commit comments

Comments
 (0)