@things-factory/integration-base 6.2.117 → 6.2.118
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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/integration-base",
|
3
|
-
"version": "6.2.
|
3
|
+
"version": "6.2.118",
|
4
4
|
"main": "dist-server/index.js",
|
5
5
|
"browser": "client/index.js",
|
6
6
|
"things-factory": true,
|
@@ -47,5 +47,5 @@
|
|
47
47
|
"devDependencies": {
|
48
48
|
"@types/cron": "^2.0.1"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "3b0a5f498c8fd799c238cec391c8368ec733e901"
|
51
51
|
}
|
@@ -5,7 +5,7 @@ import { Connector } from '../types'
|
|
5
5
|
import { InputConnection } from '../../service/connection/connection-type'
|
6
6
|
|
7
7
|
try {
|
8
|
-
var
|
8
|
+
var oracledb = require('oracledb')
|
9
9
|
} catch (err) {
|
10
10
|
logger.error('oracledb module loading failed')
|
11
11
|
}
|
@@ -17,7 +17,7 @@ export class OracleConnector implements Connector {
|
|
17
17
|
ConnectionManager.logger.info('oracle-connector connections are ready')
|
18
18
|
}
|
19
19
|
|
20
|
-
async
|
20
|
+
async recreatePool(connection: InputConnection) {
|
21
21
|
const {
|
22
22
|
name,
|
23
23
|
endpoint,
|
@@ -25,12 +25,13 @@ export class OracleConnector implements Connector {
|
|
25
25
|
domain
|
26
26
|
} = connection
|
27
27
|
|
28
|
-
if (!
|
28
|
+
if (!oracledb) {
|
29
29
|
throw new Error('oracledb module loading failed')
|
30
30
|
}
|
31
31
|
|
32
32
|
const poolAlias = `${domain.name}-${name}`
|
33
|
-
|
33
|
+
await oracledb.getPool(poolAlias).close(10)
|
34
|
+
await oracledb.createPool({
|
34
35
|
user,
|
35
36
|
password,
|
36
37
|
// when oracle not using default port must add connection string with port like localhost:port
|
@@ -41,49 +42,106 @@ export class OracleConnector implements Connector {
|
|
41
42
|
poolAlias
|
42
43
|
})
|
43
44
|
|
45
|
+
ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)
|
46
|
+
}
|
47
|
+
|
48
|
+
async connect(connection: InputConnection) {
|
49
|
+
const {
|
50
|
+
name,
|
51
|
+
endpoint,
|
52
|
+
params: { user, password, database, poolMin, poolMax, poolIncrement },
|
53
|
+
domain
|
54
|
+
} = connection
|
55
|
+
|
56
|
+
if (!oracledb) {
|
57
|
+
throw new Error('oracledb module loading failed')
|
58
|
+
}
|
59
|
+
|
60
|
+
const poolAlias = `${domain.name}-${name}`
|
61
|
+
|
62
|
+
var enableStatistics = true
|
63
|
+
const pool = await oracledb.createPool({
|
64
|
+
user,
|
65
|
+
password,
|
66
|
+
// when oracle not using default port must add connection string with port like localhost:port
|
67
|
+
connectString: `${endpoint.trim()}/${database}`,
|
68
|
+
poolMin,
|
69
|
+
poolMax,
|
70
|
+
poolIncrement,
|
71
|
+
poolAlias,
|
72
|
+
enableStatistics
|
73
|
+
})
|
44
74
|
|
45
75
|
ConnectionManager.addConnectionInstance(connection, {
|
46
76
|
query: async (query, params) => {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
77
|
+
let dbConnection: any = {}
|
78
|
+
let taskResult: any = {}
|
79
|
+
try {
|
80
|
+
dbConnection = await oracledb.getConnection(poolAlias)
|
81
|
+
|
82
|
+
taskResult = (
|
83
|
+
await dbConnection.execute(query, params, {
|
84
|
+
outFormat: oracledb.OBJECT
|
85
|
+
})
|
86
|
+
).rows
|
87
|
+
} catch (e) {
|
88
|
+
if (e.name === 'Error' && e.message.includes('NJS-040')) {
|
89
|
+
await this.recreatePool(connection)
|
90
|
+
}
|
91
|
+
throw e
|
92
|
+
}
|
93
|
+
finally {
|
94
|
+
await dbConnection.close()
|
95
|
+
}
|
96
|
+
return taskResult
|
55
97
|
|
56
98
|
},
|
57
99
|
execute: async (procedure, params) => {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
100
|
+
let dbConnection: any = {}
|
101
|
+
let taskResult: any = {}
|
102
|
+
try {
|
103
|
+
// TODO: need to check if this is available when procedure string is a common query.
|
104
|
+
procedure = `BEGIN
|
105
|
+
${procedure}
|
106
|
+
END;`
|
107
|
+
dbConnection = await oracledb.getConnection(poolAlias)
|
108
|
+
|
109
|
+
// console.log('\n************* stat after get ****************')
|
110
|
+
// await oracledb.getPool(poolAlias).logStatistics()
|
111
|
+
|
112
|
+
const result = await dbConnection.execute(procedure, params, {
|
113
|
+
outFormat: oracledb.OBJECT
|
114
|
+
})
|
115
|
+
|
116
|
+
let paramKeys = Object.keys(params)
|
117
|
+
|
118
|
+
for (const paramKey of paramKeys) {
|
119
|
+
if (params[paramKey].dir === oracledb?.BIND_OUT) {
|
120
|
+
if (params[paramKey].type === oracledb?.CURSOR) {
|
121
|
+
const resultSetTemp = result.outBinds[paramKey]
|
122
|
+
taskResult[paramKey] = await resultSetTemp.getRows()
|
123
|
+
await resultSetTemp.close()
|
124
|
+
} else {
|
125
|
+
taskResult[paramKey] = result.outBinds[paramKey]
|
126
|
+
}
|
78
127
|
}
|
79
128
|
}
|
129
|
+
} catch (e) {
|
130
|
+
if (e.name === 'Error' && e.message.includes('NJS-040')) {
|
131
|
+
await this.recreatePool(connection)
|
132
|
+
}
|
133
|
+
throw e
|
80
134
|
}
|
135
|
+
finally {
|
136
|
+
await dbConnection.close()
|
81
137
|
|
82
|
-
|
138
|
+
// console.log('\n************* stat after close ****************')
|
139
|
+
// await oracledb.getPool(poolAlias).logStatistics()
|
140
|
+
}
|
83
141
|
return taskResult
|
84
142
|
},
|
85
143
|
close: async () => {
|
86
|
-
await
|
144
|
+
await oracledb.getPool(poolAlias).close(10)
|
87
145
|
}
|
88
146
|
})
|
89
147
|
|