Skip to content

Commit

Permalink
chore: getAutocommit, getCatalog in PG and getSchema in MySQL to thro…
Browse files Browse the repository at this point in the history
…w UnsupportedMethodError (#312)
  • Loading branch information
joyc-bq authored Nov 15, 2024
1 parent aa14623 commit 66f7c0f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
3 changes: 0 additions & 3 deletions common/lib/aws_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export abstract class AwsClient extends EventEmitter {
protected pluginService: PluginService;
protected isConnected: boolean = false;
protected _isReadOnly: boolean = false;
protected _isAutoCommit: boolean = true;
protected _catalog: string = "";
protected _schema: string = "";
protected _isolationLevel: number = 0;
protected _connectionUrlParser: ConnectionUrlParser;
readonly properties: Map<string, any>;
Expand Down
2 changes: 1 addition & 1 deletion common/lib/utils/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"StaleDnsHelper.staleDnsDetected": "Stale DNS data detected. Opening a connection to '%s'.",
"StaleDnsHelper.reset": "Reset stored writer host.",
"StaleDnsPlugin.requireDynamicProvider": "Dynamic host list provider is required.",
"Client.methodNotSupported": "Method not supported.",
"Client.methodNotSupported": "Method '%s' not supported.",
"Client.invalidTransactionIsolationLevel": "An invalid transaction isolation level was provided: '%s'.",
"AuroraStaleDnsHelper.clusterEndpointDns": "Cluster endpoint resolves to '%s'.",
"AuroraStaleDnsHelper.writerHostSpec": "Writer host: '%s'.",
Expand Down
19 changes: 10 additions & 9 deletions mysql/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export class AwsMySQLClient extends AwsClient {
[DatabaseDialectCodes.AURORA_MYSQL, new AuroraMySQLDatabaseDialect()],
[DatabaseDialectCodes.RDS_MULTI_AZ_MYSQL, new RdsMultiAZMySQLDatabaseDialect()]
]);
private isAutoCommit: boolean = true;
private catalog = "";

constructor(config: any) {
super(config, DatabaseType.MYSQL, AwsMySQLClient.knownDialectsByCode, new MySQLConnectionUrlParser(), new MySQL2DriverDialect());
Expand Down Expand Up @@ -135,7 +137,7 @@ export class AwsMySQLClient extends AwsClient {
this.pluginService.getSessionStateService().setupPristineAutoCommit();
this.pluginService.getSessionStateService().setAutoCommit(autoCommit);

this._isAutoCommit = autoCommit;
this.isAutoCommit = autoCommit;
let setting = "1";
if (!autoCommit) {
setting = "0";
Expand All @@ -144,7 +146,7 @@ export class AwsMySQLClient extends AwsClient {
}

getAutoCommit(): boolean {
return this._isAutoCommit;
return this.isAutoCommit;
}

async setCatalog(catalog: string): Promise<Query | void> {
Expand All @@ -155,20 +157,20 @@ export class AwsMySQLClient extends AwsClient {
this.pluginService.getSessionStateService().setupPristineCatalog();
this.pluginService.getSessionStateService().setCatalog(catalog);

this._catalog = catalog;
this.catalog = catalog;
await this.query({ sql: `USE ${catalog}` });
}

getCatalog(): string {
return this._catalog;
return this.catalog;
}

async setSchema(schema: string): Promise<Query | void> {
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported"));
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "setSchema"));
}

getSchema(): string {
return this._schema;
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "getSchema"));
}

async setTransactionIsolation(level: TransactionIsolationLevel): Promise<Query | void> {
Expand Down Expand Up @@ -242,9 +244,8 @@ export class AwsMySQLClient extends AwsClient {

resetState() {
this._isReadOnly = false;
this._isAutoCommit = true;
this._catalog = "";
this._schema = "";
this.isAutoCommit = true;
this.catalog = "";
this._isolationLevel = TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
}
}
17 changes: 8 additions & 9 deletions pg/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class AwsPGClient extends AwsClient {
[DatabaseDialectCodes.AURORA_PG, new AuroraPgDatabaseDialect()],
[DatabaseDialectCodes.RDS_MULTI_AZ_PG, new RdsMultiAZPgDatabaseDialect()]
]);
private schema: string = "";

constructor(config: any) {
super(config, DatabaseType.POSTGRES, AwsPGClient.knownDialectsByCode, new PgConnectionUrlParser(), new NodePostgresDriverDialect());
Expand Down Expand Up @@ -120,11 +121,11 @@ export class AwsPGClient extends AwsClient {
}

async setAutoCommit(autoCommit: boolean): Promise<QueryResult | void> {
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported"));
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "setAutoCommit"));
}

getAutoCommit(): boolean {
return this._isAutoCommit;
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "getAutoCommit"));
}

async setTransactionIsolation(level: number): Promise<QueryResult | void> {
Expand Down Expand Up @@ -159,11 +160,11 @@ export class AwsPGClient extends AwsClient {
}

async setCatalog(catalog: string): Promise<void> {
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported"));
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "setCatalog"));
}

getCatalog(): string {
return this._catalog;
throw new UnsupportedMethodError(Messages.get("Client.methodNotSupported", "getCatalog"));
}

async setSchema(schema: string): Promise<QueryResult | void> {
Expand All @@ -174,12 +175,12 @@ export class AwsPGClient extends AwsClient {
this.pluginService.getSessionStateService().setupPristineSchema();
this.pluginService.getSessionStateService().setSchema(schema);

this._schema = schema;
this.schema = schema;
return await this.query(`SET search_path TO ${schema};`);
}

getSchema(): string {
return this._schema;
return this.schema;
}

async end() {
Expand Down Expand Up @@ -220,9 +221,7 @@ export class AwsPGClient extends AwsClient {

resetState() {
this._isReadOnly = false;
this._isAutoCommit = true;
this._catalog = "";
this._schema = "";
this.schema = "";
this._isolationLevel = TransactionIsolationLevel.TRANSACTION_READ_COMMITTED;
}
}

0 comments on commit 66f7c0f

Please sign in to comment.