Skip to content

Commit 8a607c4

Browse files
committed
addressed comments
1 parent ad059d7 commit 8a607c4

1 file changed

Lines changed: 19 additions & 40 deletions

File tree

lib/DBSQLSession.ts

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,22 @@ export default class DBSQLSession implements IDBSQLSession {
157157

158158
private operations = new CloseableCollection<DBSQLOperation>();
159159

160+
/**
161+
* Helper method to determine if runAsync should be set for metadata operations
162+
* @private
163+
* @returns true if supported by protocol version, undefined otherwise
164+
*/
165+
private getRunAsyncForMetadataOperations(): boolean | undefined {
166+
return ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
167+
}
168+
160169
constructor({ handle, context, serverProtocolVersion }: DBSQLSessionConstructorOptions) {
161170
this.sessionHandle = handle;
162171
this.context = context;
163172
// Get the server protocol version from the provided parameter (from TOpenSessionResp)
164-
// rather than from the handle
165173
this.serverProtocolVersion = serverProtocolVersion;
166174
this.context.getLogger().log(LogLevel.debug, `Session created with id: ${this.id}`);
167-
if (this.serverProtocolVersion) {
168-
this.context.getLogger().log(LogLevel.debug, `Server protocol version: ${this.serverProtocolVersion}`);
169-
}
175+
this.context.getLogger().log(LogLevel.debug, `Server protocol version: ${this.serverProtocolVersion}`);
170176
}
171177

172178
public get id() {
@@ -379,12 +385,9 @@ export default class DBSQLSession implements IDBSQLSession {
379385
const driver = await this.context.getDriver();
380386
const clientConfig = this.context.getConfig();
381387

382-
// Set runAsync only if supported by protocol version
383-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
384-
385388
const operationPromise = driver.getTypeInfo({
386389
sessionHandle: this.sessionHandle,
387-
runAsync,
390+
runAsync: this.getRunAsyncForMetadataOperations(),
388391
...getDirectResultsOptions(request.maxRows, clientConfig),
389392
});
390393
const response = await this.handleResponse(operationPromise);
@@ -402,12 +405,9 @@ export default class DBSQLSession implements IDBSQLSession {
402405
const driver = await this.context.getDriver();
403406
const clientConfig = this.context.getConfig();
404407

405-
// Set runAsync only if supported by protocol version
406-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
407-
408408
const operationPromise = driver.getCatalogs({
409409
sessionHandle: this.sessionHandle,
410-
runAsync,
410+
runAsync: this.getRunAsyncForMetadataOperations(),
411411
...getDirectResultsOptions(request.maxRows, clientConfig),
412412
});
413413
const response = await this.handleResponse(operationPromise);
@@ -425,14 +425,11 @@ export default class DBSQLSession implements IDBSQLSession {
425425
const driver = await this.context.getDriver();
426426
const clientConfig = this.context.getConfig();
427427

428-
// Set runAsync only if supported by protocol version
429-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
430-
431428
const operationPromise = driver.getSchemas({
432429
sessionHandle: this.sessionHandle,
433430
catalogName: request.catalogName,
434431
schemaName: request.schemaName,
435-
runAsync,
432+
runAsync: this.getRunAsyncForMetadataOperations(),
436433
...getDirectResultsOptions(request.maxRows, clientConfig),
437434
});
438435
const response = await this.handleResponse(operationPromise);
@@ -450,16 +447,13 @@ export default class DBSQLSession implements IDBSQLSession {
450447
const driver = await this.context.getDriver();
451448
const clientConfig = this.context.getConfig();
452449

453-
// Set runAsync only if supported by protocol version
454-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
455-
456450
const operationPromise = driver.getTables({
457451
sessionHandle: this.sessionHandle,
458452
catalogName: request.catalogName,
459453
schemaName: request.schemaName,
460454
tableName: request.tableName,
461455
tableTypes: request.tableTypes,
462-
runAsync,
456+
runAsync: this.getRunAsyncForMetadataOperations(),
463457
...getDirectResultsOptions(request.maxRows, clientConfig),
464458
});
465459
const response = await this.handleResponse(operationPromise);
@@ -477,12 +471,9 @@ export default class DBSQLSession implements IDBSQLSession {
477471
const driver = await this.context.getDriver();
478472
const clientConfig = this.context.getConfig();
479473

480-
// Set runAsync only if supported by protocol version
481-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
482-
483474
const operationPromise = driver.getTableTypes({
484475
sessionHandle: this.sessionHandle,
485-
runAsync,
476+
runAsync: this.getRunAsyncForMetadataOperations(),
486477
...getDirectResultsOptions(request.maxRows, clientConfig),
487478
});
488479
const response = await this.handleResponse(operationPromise);
@@ -500,16 +491,13 @@ export default class DBSQLSession implements IDBSQLSession {
500491
const driver = await this.context.getDriver();
501492
const clientConfig = this.context.getConfig();
502493

503-
// Set runAsync only if supported by protocol version
504-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
505-
506494
const operationPromise = driver.getColumns({
507495
sessionHandle: this.sessionHandle,
508496
catalogName: request.catalogName,
509497
schemaName: request.schemaName,
510498
tableName: request.tableName,
511499
columnName: request.columnName,
512-
runAsync,
500+
runAsync: this.getRunAsyncForMetadataOperations(),
513501
...getDirectResultsOptions(request.maxRows, clientConfig),
514502
});
515503
const response = await this.handleResponse(operationPromise);
@@ -527,15 +515,12 @@ export default class DBSQLSession implements IDBSQLSession {
527515
const driver = await this.context.getDriver();
528516
const clientConfig = this.context.getConfig();
529517

530-
// Set runAsync only if supported by protocol version
531-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
532-
533518
const operationPromise = driver.getFunctions({
534519
sessionHandle: this.sessionHandle,
535520
catalogName: request.catalogName,
536521
schemaName: request.schemaName,
537522
functionName: request.functionName,
538-
runAsync,
523+
runAsync: this.getRunAsyncForMetadataOperations(),
539524
...getDirectResultsOptions(request.maxRows, clientConfig),
540525
});
541526
const response = await this.handleResponse(operationPromise);
@@ -547,15 +532,12 @@ export default class DBSQLSession implements IDBSQLSession {
547532
const driver = await this.context.getDriver();
548533
const clientConfig = this.context.getConfig();
549534

550-
// Set runAsync only if supported by protocol version
551-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
552-
553535
const operationPromise = driver.getPrimaryKeys({
554536
sessionHandle: this.sessionHandle,
555537
catalogName: request.catalogName,
556538
schemaName: request.schemaName,
557539
tableName: request.tableName,
558-
runAsync,
540+
runAsync: this.getRunAsyncForMetadataOperations(),
559541
...getDirectResultsOptions(request.maxRows, clientConfig),
560542
});
561543
const response = await this.handleResponse(operationPromise);
@@ -573,9 +555,6 @@ export default class DBSQLSession implements IDBSQLSession {
573555
const driver = await this.context.getDriver();
574556
const clientConfig = this.context.getConfig();
575557

576-
// Set runAsync only if supported by protocol version
577-
const runAsync = ProtocolVersion.supportsAsyncMetadataOperations(this.serverProtocolVersion) ? true : undefined;
578-
579558
const operationPromise = driver.getCrossReference({
580559
sessionHandle: this.sessionHandle,
581560
parentCatalogName: request.parentCatalogName,
@@ -584,7 +563,7 @@ export default class DBSQLSession implements IDBSQLSession {
584563
foreignCatalogName: request.foreignCatalogName,
585564
foreignSchemaName: request.foreignSchemaName,
586565
foreignTableName: request.foreignTableName,
587-
runAsync,
566+
runAsync: this.getRunAsyncForMetadataOperations(),
588567
...getDirectResultsOptions(request.maxRows, clientConfig),
589568
});
590569
const response = await this.handleResponse(operationPromise);

0 commit comments

Comments
 (0)