@itentialopensource/adapter-db_oracle 0.3.3 → 0.3.5

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/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ## 0.3.4 [08-25-2024]
3
+
4
+ * update dependencies and metadata
5
+
6
+ See merge request itentialopensource/adapters/adapter-db_oracle!12
7
+
8
+ ---
9
+
2
10
  ## 0.3.3 [08-14-2024]
3
11
 
4
12
  * Changes made at 2024.08.14_19:29PM
package/TAB2.md CHANGED
@@ -43,8 +43,8 @@ Sample Properties can be used to help you configure the adapter in the Itential
43
43
  "host": "localhost",
44
44
  "port": 3306,
45
45
  "authentication": {
46
- "username": "your username",
47
- "password": "your password"
46
+ "username": "username",
47
+ "password": "password"
48
48
  }
49
49
  }
50
50
  ```
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
- // query connection
281
- this.connection.execute(sql, (error, results) => {
282
- // close connection
283
- // this.connection.end();
284
- log.debug(`result from query: ${JSON.stringify(results)}`);
285
-
286
- if (error) {
287
- const errorObj = formatErrorObject(origin, 'Database Error', [error], null, null, null);
288
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
289
- return callback(null, errorObj);
290
- }
291
-
292
- return callback({
293
- status: 'success',
294
- code: 200,
295
- response: results
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/metadata.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "adapter-db_oracle",
3
3
  "webName": "Adapter for Integration to Oracle Database",
4
+ "supportLevel": "community",
4
5
  "vendor": "Oracle",
5
6
  "product": "Oracle DB",
7
+ "techAlliance": false,
6
8
  "osVersion": [],
7
9
  "apiVersions": [],
8
10
  "iapVersions": [
@@ -38,7 +40,7 @@
38
40
  "storeLink": "",
39
41
  "npmLink": "https://www.npmjs.com/package/@itentialopensource/adapter-db_oracle",
40
42
  "repoLink": "https://gitlab.com/itentialopensource/adapters/adapter-db_oracle",
41
- "docLink": "",
43
+ "docLink": "https://gitlab.com/itentialopensource/adapters/adapter-db_oracle/-/blob/master/README.md?ref_type=heads",
42
44
  "demoLinks": [],
43
45
  "trainingLinks": [
44
46
  {
@@ -75,7 +77,5 @@
75
77
  "workflowProjects": [],
76
78
  "transformationProjects": [],
77
79
  "exampleProjects": []
78
- },
79
- "supportLevel": "community",
80
- "techAlliance": false
80
+ }
81
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-db_oracle",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
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": "^4.0.1",
46
+ "oracledb": "6.6.0",
47
47
  "readline-sync": "^1.4.10",
48
48
  "uuid": "^3.1.0"
49
49
  },
@@ -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
  }
Binary file
@@ -6,8 +6,8 @@
6
6
  "host": "localhost",
7
7
  "port": 3306,
8
8
  "authentication": {
9
- "username": "your username",
10
- "password": "your password"
9
+ "username": "username",
10
+ "password": "password"
11
11
  }
12
12
  },
13
13
  "groups": [],
@@ -25,7 +25,7 @@ const attemptTimeout = 10000;
25
25
  // always check these in with bogus data!!!
26
26
  const host = 'localhost';
27
27
  const username = 'your username';
28
- const password = 'your password';
28
+ const usepass = 'your password';
29
29
  const port = 3306;
30
30
  const sslenable = false;
31
31
  const sslinvalid = false;
@@ -46,7 +46,7 @@ global.pronghornProps = {
46
46
  port,
47
47
  authentication: {
48
48
  username,
49
- password
49
+ password: usepass
50
50
  },
51
51
  ssl: {
52
52
  enabled: sslenable,
@@ -1,9 +0,0 @@
1
- {
2
- "ComplianceEntries": [
3
- {
4
- "name": "Compliance Summary",
5
- "numInvalidProjects": 0,
6
- "numValidProjects": 0
7
- }
8
- ]
9
- }
@@ -1,5 +0,0 @@
1
- ---------------------------------------------------------------------------------------------
2
- **** Project Compliance Summary ****
3
- 0 project(s) are not valid
4
- 0 project(s) are valid
5
- ---------------------------------------------------------------------------------------------