@itentialopensource/adapter-db_oracle 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/adapter.js +89 -17
- package/package.json +2 -2
- package/propertiesSchema.json +9 -0
- package/compliance-report.json +0 -9
- package/compliance-report.txt +0 -5
- package/refs?service=git-upload-pack +0 -0
package/adapter.js
CHANGED
|
@@ -94,6 +94,25 @@ function formatErrorObject(origin, type, variables, sysCode, sysRes, stack) {
|
|
|
94
94
|
return errorObject;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/**
|
|
98
|
+
* @summary Check if connection error
|
|
99
|
+
*
|
|
100
|
+
* @function isConnectionError
|
|
101
|
+
* @param {object} error - error from Oracle
|
|
102
|
+
*
|
|
103
|
+
* @return {boolean} - the result of error type checking
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
function isConnectionError(error) {
|
|
107
|
+
return error && (
|
|
108
|
+
error.code === 'NJS-003'
|
|
109
|
+
|| error.code === 'NJS-500'
|
|
110
|
+
|| error.code === 'NJS-040'
|
|
111
|
+
|| error.code === 'NJS-521'
|
|
112
|
+
|| error.message.includes('connect')
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
97
116
|
class Oracle extends EventEmitter {
|
|
98
117
|
constructor(prongid, properties) {
|
|
99
118
|
log.trace('adapter oracle loading');
|
|
@@ -136,6 +155,16 @@ class Oracle extends EventEmitter {
|
|
|
136
155
|
connectString: `${this.props.host}:${this.props.port}/${this.props.database}`
|
|
137
156
|
};
|
|
138
157
|
|
|
158
|
+
this.connAttrs = connAttrs;
|
|
159
|
+
|
|
160
|
+
if (this.props.databaseConnection === 'connect on request') {
|
|
161
|
+
return this.emit('ONLINE', {
|
|
162
|
+
id: this.id
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
log.debug('Connecting to Oracle Database with provided auth and connectString');
|
|
167
|
+
|
|
139
168
|
// Get connection
|
|
140
169
|
oracle.getConnection(connAttrs, (error, gotConn) => {
|
|
141
170
|
// Emit online if on stub mode
|
|
@@ -269,6 +298,7 @@ class Oracle extends EventEmitter {
|
|
|
269
298
|
const origin = `${this.id}-${meth}`;
|
|
270
299
|
log.trace(origin);
|
|
271
300
|
|
|
301
|
+
let oracleConnection;
|
|
272
302
|
try {
|
|
273
303
|
// verify the required data has been provided
|
|
274
304
|
if (!sql) {
|
|
@@ -277,24 +307,66 @@ class Oracle extends EventEmitter {
|
|
|
277
307
|
return callback(null, errorObj);
|
|
278
308
|
}
|
|
279
309
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
310
|
+
const executeQuery = (connection, retry = false) => {
|
|
311
|
+
connection.execute(sql, async (exErr, results) => {
|
|
312
|
+
try {
|
|
313
|
+
if (connection && this.props.databaseConnection === 'connect on request') {
|
|
314
|
+
this.alive = false;
|
|
315
|
+
await connection.close();
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (exErr) {
|
|
319
|
+
// If connect on startup and get connection error, attempt to reconnect to Oracle Database and execute the query again
|
|
320
|
+
if (retry && isConnectionError(exErr)) {
|
|
321
|
+
log.warn(`${origin}: Connection error detected, attempting to reconnect to Oracle Database...`);
|
|
322
|
+
oracle.getConnection(this.connAttrs, (connErr, gotConn) => {
|
|
323
|
+
if (connErr) {
|
|
324
|
+
const errorObj = formatErrorObject(origin, 'Oracle Database connection failed', null, null, null, null);
|
|
325
|
+
log.error(`${origin}: Error connecting to Oracle - ${connErr}`);
|
|
326
|
+
return callback(null, errorObj);
|
|
327
|
+
}
|
|
328
|
+
this.connection = gotConn;
|
|
329
|
+
// Only retry once so retry flag is set to false
|
|
330
|
+
executeQuery(this.connection);
|
|
331
|
+
});
|
|
332
|
+
} else {
|
|
333
|
+
// If connect on request or connect on startup with nonconnection error, just return the error
|
|
334
|
+
const errorObj = formatErrorObject(origin, 'Database Error', [exErr], null, null, null);
|
|
335
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
336
|
+
return callback(null, errorObj);
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
log.debug(`result from query: ${JSON.stringify(results)}`);
|
|
340
|
+
return callback({
|
|
341
|
+
status: 'success',
|
|
342
|
+
code: 200,
|
|
343
|
+
response: results
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
} catch (e) {
|
|
347
|
+
const errorObj = formatErrorObject(origin, 'Caught Exception', null, null, null, e);
|
|
348
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
349
|
+
return callback(null, errorObj);
|
|
350
|
+
}
|
|
296
351
|
});
|
|
297
|
-
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
if (this.props.databaseConnection === 'connect on request') {
|
|
355
|
+
log.debug(`${origin}: Connecting to Oracle Database`);
|
|
356
|
+
|
|
357
|
+
oracle.getConnection(this.connAttrs, (error, gotConn) => {
|
|
358
|
+
if (error) {
|
|
359
|
+
const errorObj = formatErrorObject(origin, 'Oracle Database connection failed', null, null, null, null);
|
|
360
|
+
log.error(`${origin}: Error connecting to Oracle - ${error}`);
|
|
361
|
+
return callback(null, errorObj);
|
|
362
|
+
}
|
|
363
|
+
this.alive = true;
|
|
364
|
+
oracleConnection = gotConn;
|
|
365
|
+
executeQuery(oracleConnection);
|
|
366
|
+
});
|
|
367
|
+
} else {
|
|
368
|
+
executeQuery(this.connection, true);
|
|
369
|
+
}
|
|
298
370
|
} catch (ex) {
|
|
299
371
|
const errorObj = formatErrorObject(origin, 'Caught Exception', null, null, null, ex);
|
|
300
372
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itentialopensource/adapter-db_oracle",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Itential adapter to connect to oracle",
|
|
5
5
|
"main": "adapter.js",
|
|
6
6
|
"wizardVersion": "2.44.7",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"ajv": "^8.17.1",
|
|
45
45
|
"fs-extra": "^11.2.0",
|
|
46
|
-
"oracledb": "
|
|
46
|
+
"oracledb": "6.6.0",
|
|
47
47
|
"readline-sync": "^1.4.10",
|
|
48
48
|
"uuid": "^3.1.0"
|
|
49
49
|
},
|
package/propertiesSchema.json
CHANGED
|
@@ -26,6 +26,15 @@
|
|
|
26
26
|
"minimum": 1,
|
|
27
27
|
"maximum": 65535
|
|
28
28
|
},
|
|
29
|
+
"databaseConnection": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Establish single connection to oracle db upon adapter start or new connection to oracle db upon each database request",
|
|
32
|
+
"default": "connect on startup",
|
|
33
|
+
"enum": [
|
|
34
|
+
"connect on startup",
|
|
35
|
+
"connect on request"
|
|
36
|
+
]
|
|
37
|
+
},
|
|
29
38
|
"authentication": {
|
|
30
39
|
"$ref":"#/definitions/authentication"
|
|
31
40
|
}
|
package/compliance-report.json
DELETED
package/compliance-report.txt
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
---------------------------------------------------------------------------------------------
|
|
2
|
-
**** Project Compliance Summary ****
|
|
3
|
-
0 project(s) are not valid
|
|
4
|
-
0 project(s) are valid
|
|
5
|
-
---------------------------------------------------------------------------------------------
|
|
Binary file
|