-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaws_client.ts
161 lines (127 loc) · 5.35 KB
/
aws_client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { PluginServiceManagerContainer } from "./plugin_service_manager_container";
import { PluginService } from "./plugin_service";
import { ErrorHandler } from "./error_handler";
import { DatabaseDialect, DatabaseType } from "./database_dialect/database_dialect";
import { ConnectionUrlParser } from "./utils/connection_url_parser";
import { HostListProvider } from "./host_list_provider/host_list_provider";
import { PluginManager } from "./plugin_manager";
import { EventEmitter } from "stream";
import { DriverConnectionProvider } from "./driver_connection_provider";
import { ClientWrapper } from "./client_wrapper";
import { ConnectionProviderManager } from "./connection_provider_manager";
import { DefaultTelemetryFactory } from "./utils/telemetry/default_telemetry_factory";
import { TelemetryFactory } from "./utils/telemetry/telemetry_factory";
import { DriverDialect } from "./driver_dialect/driver_dialect";
export abstract class AwsClient extends EventEmitter {
private _defaultPort: number = -1;
protected telemetryFactory: TelemetryFactory;
protected pluginManager: PluginManager;
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 _errorHandler: ErrorHandler;
protected _connectionUrlParser: ConnectionUrlParser;
readonly properties: Map<string, any>;
config: any;
targetClient?: ClientWrapper;
protected constructor(
config: any,
errorHandler: ErrorHandler,
dbType: DatabaseType,
knownDialectsByCode: Map<string, DatabaseDialect>,
parser: ConnectionUrlParser,
driverDialect: DriverDialect
) {
super();
this.config = config;
this._errorHandler = errorHandler;
this._connectionUrlParser = parser;
this.properties = new Map<string, any>(Object.entries(config));
this.telemetryFactory = new DefaultTelemetryFactory(this.properties);
const container = new PluginServiceManagerContainer();
this.pluginService = new PluginService(container, this, dbType, knownDialectsByCode, this.properties, driverDialect);
this.pluginManager = new PluginManager(
container,
this.properties,
new ConnectionProviderManager(new DriverConnectionProvider(), null),
this.telemetryFactory
);
}
private async setup() {
await this.telemetryFactory.init();
await this.pluginManager.init();
}
protected async internalConnect() {
await this.setup();
const hostListProvider: HostListProvider = this.pluginService
.getDialect()
.getHostListProvider(this.properties, this.properties.get("host"), this.pluginService);
this.pluginService.setHostListProvider(hostListProvider);
await this.pluginService.refreshHostList();
const initialHostInfo = this.pluginService.getInitialConnectionHostInfo();
if (initialHostInfo != null) {
await this.pluginManager.initHostProvider(initialHostInfo, this.properties, this.pluginService);
await this.pluginService.refreshHostList();
}
}
protected async internalPostConnect() {
const info = this.pluginService.getCurrentHostInfo();
if (info != null) {
await this.pluginService.refreshHostList();
}
this.isConnected = true;
}
get defaultPort(): number {
return this._defaultPort;
}
get errorHandler(): ErrorHandler {
return this._errorHandler;
}
get connectionUrlParser(): ConnectionUrlParser {
return this._connectionUrlParser;
}
abstract updateSessionStateReadOnly(readOnly: boolean): Promise<any | void>;
abstract setReadOnly(readOnly: boolean): Promise<any | void>;
abstract isReadOnly(): boolean;
abstract setAutoCommit(autoCommit: boolean): Promise<any | void>;
abstract getAutoCommit(): boolean;
abstract setTransactionIsolation(transactionIsolation: number): Promise<any | void>;
abstract getTransactionIsolation(): number;
abstract setSchema(schema: any): Promise<any | void>;
abstract getSchema(): string;
abstract setCatalog(catalog: string): Promise<any | void>;
abstract getCatalog(): string;
abstract end(): Promise<any>;
abstract connect(): Promise<any>;
abstract rollback(): Promise<any>;
abstract resetState(): void;
async isValid(): Promise<boolean> {
if (!this.targetClient) {
return Promise.resolve(false);
}
return await this.pluginService.isClientValid(this.targetClient);
}
async releaseResources(): Promise<any> {
await this.pluginManager.releaseResources();
}
abstract executeQuery(props: Map<string, any>, query: string, targetClient?: ClientWrapper): any;
getPluginInstance<T>(iface: any): T {
return this.pluginManager.getPluginInstance(iface);
}
}