Skip to content

Commit

Permalink
fix: remove default session state values
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc-bq committed Dec 17, 2024
1 parent 46a7fa2 commit 430cad0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 80 deletions.
2 changes: 0 additions & 2 deletions common/lib/client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ export interface ClientWrapper {
abort(): Promise<void>;

queryWithTimeout(sql: string): Promise<any>;

setSessionStateDefault(): void;
}
7 changes: 0 additions & 7 deletions common/lib/database_dialect/database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export enum DatabaseType {
}

export interface DatabaseDialect {
readonly defaultAutoCommit?: boolean;
readonly defaultReadOnly?: boolean;
readonly defaultTransactionIsolation?: number;
readonly defaultCatalog?: string;
readonly defaultSchema?: string;

getDefaultPort(): number;
getHostAliasQuery(): string;
getHostAliasAndParseResults(targetClient: ClientWrapper): Promise<string>;
Expand All @@ -55,5 +49,4 @@ export interface DatabaseDialect {
doesStatementSetAutoCommit(statement: string): boolean | undefined;
doesStatementSetSchema(statement: string): string | undefined;
doesStatementSetCatalog(statement: string): string | undefined;
setDefaultSessionState(sessionState: SessionState): void;
}
9 changes: 0 additions & 9 deletions common/lib/mysql_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export class MySQLClientWrapper implements ClientWrapper {
this.properties = properties;
this.driverDialect = driverDialect;
this.id = uniqueId("MySQLClient_");

this.setSessionStateDefault();
}

query(sql: any): Promise<any> {
Expand All @@ -75,11 +73,4 @@ export class MySQLClientWrapper implements ClientWrapper {
// ignore
}
}

setSessionStateDefault() {
this.sessionState.readOnly.value = false;
this.sessionState.autoCommit.value = true;
this.sessionState.catalog.value = "";
this.sessionState.transactionIsolation.value = TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
}
}
8 changes: 0 additions & 8 deletions common/lib/pg_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class PgClientWrapper implements ClientWrapper {
this.properties = properties;
this.sessionState = new SessionState();
this.id = uniqueId("PgClient_");

this.setSessionStateDefault();
}

query(sql: any): Promise<any> {
Expand All @@ -70,10 +68,4 @@ export class PgClientWrapper implements ClientWrapper {
// Ignore
}
}

setSessionStateDefault() {
this.sessionState.readOnly.value = false;
this.sessionState.schema.value = "";
this.sessionState.transactionIsolation.value = TransactionIsolationLevel.TRANSACTION_READ_COMMITTED;
}
}
2 changes: 0 additions & 2 deletions common/lib/pool_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,4 @@ export class PoolClientWrapper implements ClientWrapper {
rollback(): Promise<void> {
return this.client?.rollback();
}

setSessionStateDefault() {}
}
20 changes: 10 additions & 10 deletions common/lib/session_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ export class SessionState {
schema: SessionStateField<string> = new SessionStateField<string>();
transactionIsolation: SessionStateField<number> = new SessionStateField<number>();

setAutoCommit(sessionState: SessionState): void {
this.autoCommit.value = sessionState.autoCommit.value;
setAutoCommit(sessionState: SessionState, usePristine: boolean = false): void {
this.autoCommit.value = usePristine ? sessionState.autoCommit.pristineValue : sessionState.autoCommit.value;
}

setReadOnly(sessionState: SessionState): void {
this.readOnly.value = sessionState.readOnly.value;
setReadOnly(sessionState: SessionState, usePristine: boolean = false): void {
this.readOnly.value = usePristine ? sessionState.readOnly.pristineValue : sessionState.readOnly.value;
}

setCatalog(sessionState: SessionState): void {
this.catalog.value = sessionState.catalog.value;
setCatalog(sessionState: SessionState, usePristine: boolean = false): void {
this.catalog.value = usePristine ? sessionState.catalog.pristineValue : sessionState.catalog.value;
}

setSchema(sessionState: SessionState): void {
this.schema.value = sessionState.schema.value;
setSchema(sessionState: SessionState, usePristine: boolean = false): void {
this.schema.value = usePristine ? sessionState.schema.pristineValue : sessionState.schema.value;
}

setTransactionIsolation(sessionState: SessionState): void {
this.transactionIsolation.value = sessionState.transactionIsolation.value;
setTransactionIsolation(sessionState: SessionState, usePristine: boolean = false): void {
this.transactionIsolation.value = usePristine ? sessionState.transactionIsolation.pristineValue : sessionState.transactionIsolation.value;
}

copy(): SessionState {
Expand Down
45 changes: 23 additions & 22 deletions common/lib/session_state_service_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { PluginService } from "./plugin_service";
import { AwsWrapperError, UnsupportedMethodError } from "./utils/errors";
import { logger } from "../logutils";
import { SessionStateTransferHandler } from "./session_state_transfer_handler";
import { ClientWrapper } from "./client_wrapper";

export class SessionStateServiceImpl implements SessionStateService {
protected sessionState: SessionState;
Expand Down Expand Up @@ -57,12 +58,13 @@ export class SessionStateServiceImpl implements SessionStateService {
}
}

const targetClient: ClientWrapper = newClient.targetClient;
if (this.sessionState.autoCommit.value !== undefined) {
this.sessionState.autoCommit.resetPristineValue();
this.setupPristineAutoCommit();
try {
await newClient.targetClient.query(this.pluginService.getDialect().getSetAutoCommitQuery(this.sessionState.autoCommit.value));
newClient.targetClient.sessionState.setAutoCommit(this.sessionState);
await targetClient.query(this.pluginService.getDialect().getSetAutoCommitQuery(this.sessionState.autoCommit.value));
targetClient.sessionState.setAutoCommit(this.sessionState);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -75,8 +77,8 @@ export class SessionStateServiceImpl implements SessionStateService {
this.sessionState.readOnly.resetPristineValue();
this.setupPristineReadOnly();
try {
await newClient.targetClient.query(this.pluginService.getDialect().getSetReadOnlyQuery(this.sessionState.readOnly.value));
newClient.targetClient.sessionState.readOnly.value = this.sessionState.readOnly.value;
await targetClient.query(this.pluginService.getDialect().getSetReadOnlyQuery(this.sessionState.readOnly.value));
targetClient.sessionState.setReadOnly(this.sessionState);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -89,8 +91,8 @@ export class SessionStateServiceImpl implements SessionStateService {
this.sessionState.catalog.resetPristineValue();
this.setupPristineCatalog();
try {
await newClient.targetClient.query(this.pluginService.getDialect().getSetCatalogQuery(this.sessionState.catalog.value));
newClient.targetClient.sessionState.catalog.value = this.sessionState.catalog.value;
await targetClient.query(this.pluginService.getDialect().getSetCatalogQuery(this.sessionState.catalog.value));
targetClient.sessionState.setCatalog(this.sessionState);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -103,8 +105,8 @@ export class SessionStateServiceImpl implements SessionStateService {
this.sessionState.schema.resetPristineValue();
this.setupPristineSchema();
try {
await newClient.targetClient.query(this.pluginService.getDialect().getSetSchemaQuery(this.sessionState.schema.value));
newClient.targetClient.sessionState.schema.value = this.sessionState.schema.value;
await targetClient.query(this.pluginService.getDialect().getSetSchemaQuery(this.sessionState.schema.value));
targetClient.sessionState.setSchema(this.sessionState);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -117,10 +119,8 @@ export class SessionStateServiceImpl implements SessionStateService {
this.sessionState.transactionIsolation.resetPristineValue();
this.setupPristineTransactionIsolation();
try {
await newClient.targetClient.query(
this.pluginService.getDialect().getSetTransactionIsolationQuery(this.sessionState.transactionIsolation.value)
);
newClient.targetClient.sessionState.transactionIsolation.value = this.sessionState.transactionIsolation.value;
await targetClient.query(this.pluginService.getDialect().getSetTransactionIsolationQuery(this.sessionState.transactionIsolation.value));
targetClient.sessionState.setTransactionIsolation(this.sessionState);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -144,11 +144,12 @@ export class SessionStateServiceImpl implements SessionStateService {
}
}

const targetClient: ClientWrapper = client.targetClient;
if (this.copySessionState?.autoCommit.canRestorePristine() && this.copySessionState?.autoCommit.pristineValue !== undefined) {
try {
await client.targetClient.query(this.pluginService.getDialect().getSetAutoCommitQuery(this.copySessionState.autoCommit.pristineValue));
await targetClient.query(this.pluginService.getDialect().getSetAutoCommitQuery(this.copySessionState.autoCommit.pristineValue));
this.setAutoCommit(this.copySessionState.autoCommit.pristineValue);
client.targetClient.sessionState.autoCommit.value = this.copySessionState.autoCommit.pristineValue;
targetClient.sessionState.setAutoCommit(this.copySessionState, true);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -159,9 +160,9 @@ export class SessionStateServiceImpl implements SessionStateService {

if (this.copySessionState?.readOnly.canRestorePristine() && this.copySessionState?.readOnly.pristineValue !== undefined) {
try {
await client.targetClient.query(this.pluginService.getDialect().getSetReadOnlyQuery(this.copySessionState.readOnly.pristineValue));
await targetClient.query(this.pluginService.getDialect().getSetReadOnlyQuery(this.copySessionState.readOnly.pristineValue));
this.setReadOnly(this.sessionState.readOnly.pristineValue);
client.targetClient.sessionState.readOnly.value = this.copySessionState.readOnly.pristineValue;
targetClient.sessionState.setReadOnly(this.copySessionState, true);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -172,9 +173,9 @@ export class SessionStateServiceImpl implements SessionStateService {

if (this.copySessionState?.catalog.canRestorePristine() && this.copySessionState?.catalog.pristineValue !== undefined) {
try {
await client.targetClient.query(this.pluginService.getDialect().getSetCatalogQuery(this.copySessionState.catalog.pristineValue));
await targetClient.query(this.pluginService.getDialect().getSetCatalogQuery(this.copySessionState.catalog.pristineValue));
this.setCatalog(this.copySessionState.catalog.pristineValue);
client.targetClient.sessionState.catalog.value = this.copySessionState.catalog.pristineValue;
targetClient.sessionState.setCatalog(this.copySessionState, true);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -185,9 +186,9 @@ export class SessionStateServiceImpl implements SessionStateService {

if (this.copySessionState?.schema.canRestorePristine() && this.copySessionState?.schema.pristineValue !== undefined) {
try {
await client.targetClient.query(this.pluginService.getDialect().getSetSchemaQuery(this.copySessionState.schema.pristineValue));
await targetClient.query(this.pluginService.getDialect().getSetSchemaQuery(this.copySessionState.schema.pristineValue));
this.setSchema(this.copySessionState.schema.pristineValue);
client.targetClient.sessionState.schema.value = this.copySessionState.schema.pristineValue;
targetClient.sessionState.setSchema(this.copySessionState, true);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand All @@ -198,11 +199,11 @@ export class SessionStateServiceImpl implements SessionStateService {

if (this.copySessionState?.transactionIsolation.canRestorePristine() && this.copySessionState?.transactionIsolation.pristineValue !== undefined) {
try {
await client.targetClient.query(
await targetClient.query(
this.pluginService.getDialect().getSetTransactionIsolationQuery(this.copySessionState.transactionIsolation.pristineValue)
);
this.setTransactionIsolation(this.copySessionState.transactionIsolation.pristineValue);
client.targetClient.sessionState.transactionIsolation.value = this.copySessionState.transactionIsolation.pristineValue;
targetClient.sessionState.setTransactionIsolation(this.copySessionState, true);
} catch (error: any) {
if (error instanceof UnsupportedMethodError) {
// ignore
Expand Down
15 changes: 4 additions & 11 deletions mysql/lib/dialect/mysql_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import { DatabaseDialect, DatabaseType } from "../../../common/lib/database_dialect/database_dialect";
import { HostListProviderService } from "../../../common/lib/host_list_provider_service";
import { HostListProvider } from "../../../common/lib/host_list_provider/host_list_provider";
import { ConnectionStringHostListProvider } from "../../../common/lib/host_list_provider/connection_string_host_list_provider";
import {
ConnectionStringHostListProvider
} from "../../../common/lib/host_list_provider/connection_string_host_list_provider";
import { AwsWrapperError, UnsupportedMethodError } from "../../../common/lib/utils/errors";
import { DatabaseDialectCodes } from "../../../common/lib/database_dialect/database_dialect_codes";
import { TransactionIsolationLevel } from "../../../common/lib/utils/transaction_isolation_level";
Expand All @@ -32,10 +34,7 @@ import { Messages } from "../../../common/lib/utils/messages";
export class MySQLDatabaseDialect implements DatabaseDialect {
protected dialectName: string = this.constructor.name;
protected defaultPort: number = 3306;
readonly defaultAutoCommit: boolean = true;
readonly defaultReadOnly: boolean = false;
readonly defaultTransactionIsolation: number = TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;


getDefaultPort(): number {
return this.defaultPort;
}
Expand Down Expand Up @@ -208,10 +207,4 @@ export class MySQLDatabaseDialect implements DatabaseDialect {
doesStatementSetSchema(statement: string): string | undefined {
return undefined;
}

setDefaultSessionState(sessionState: SessionState) {
sessionState.readOnly.value = false;
sessionState.autoCommit.value = true;
sessionState.transactionIsolation.value = TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ;
}
}
9 changes: 0 additions & 9 deletions pg/lib/dialect/pg_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import { Messages } from "../../../common/lib/utils/messages";
export class PgDatabaseDialect implements DatabaseDialect {
protected dialectName: string = this.constructor.name;
protected defaultPort: number = 5432;
readonly defaultSchema: string = "";
readonly defaultReadOnly: boolean = false;
readonly defaultTransactionIsolation: number = TransactionIsolationLevel.TRANSACTION_READ_COMMITTED;

getDefaultPort(): number {
return this.defaultPort;
Expand Down Expand Up @@ -192,10 +189,4 @@ export class PgDatabaseDialect implements DatabaseDialect {

return undefined;
}

setDefaultSessionState(sessionState: SessionState) {
sessionState.readOnly.value = false;
sessionState.schema.value = "";
sessionState.transactionIsolation.value = TransactionIsolationLevel.TRANSACTION_READ_COMMITTED;
}
}

0 comments on commit 430cad0

Please sign in to comment.