@@ -7,6 +7,8 @@ const helper = require('./helper')
7
7
const informix = require ( 'informixdb' )
8
8
const ReviewService = require ( '../services/ReviewService' )
9
9
const ReviewSummationService = require ( '../services/ReviewSummationService' )
10
+
11
+ let dbConnection = null
10
12
/*
11
13
* This function loads the online review details for a given submission from Informix.
12
14
* It uses the data to create review and reviewSummation objects which are then saved
@@ -90,22 +92,26 @@ async function loadOnlineReviewDetails (authUser, submission) {
90
92
}
91
93
92
94
function queryInformix ( query ) {
93
- const connectionString = 'SERVER=' + config . get ( 'INFORMIX.SERVER' ) +
94
- ';DATABASE=' + config . get ( 'INFORMIX.DATABASE' ) +
95
- ';HOST=' + config . get ( 'INFORMIX.HOST' ) +
96
- ';Protocol=' + config . get ( 'INFORMIX.PROTOCOL' ) +
97
- ';SERVICE=' + config . get ( 'INFORMIX.PORT' ) +
98
- ';DB_LOCALE=' + config . get ( 'INFORMIX.DB_LOCALE' ) +
99
- ';UID=' + config . get ( 'INFORMIX.USER' ) +
95
+ if ( ! dbConnection || dbConnection . connected == false ) {
96
+ const connectionString = 'SERVER=' + config . get ( 'INFORMIX.SERVER' ) +
97
+ ';DATABASE=' + config . get ( 'INFORMIX.DATABASE' ) +
98
+ ';HOST=' + config . get ( 'INFORMIX.HOST' ) +
99
+ ';Protocol=' + config . get ( 'INFORMIX.PROTOCOL' ) +
100
+ ';SERVICE=' + config . get ( 'INFORMIX.PORT' ) +
101
+ ';DB_LOCALE=' + config . get ( 'INFORMIX.DB_LOCALE' ) +
102
+ ';UID=' + config . get ( 'INFORMIX.USER' ) +
100
103
';PWD=' + config . get ( 'INFORMIX.PASSWORD' )
101
-
104
+ try {
105
+ const dbConnection = informix . openSync ( connectionString )
106
+ } catch ( ex ) {
107
+ logger . error ( `Informix connection error: ${ ex } ` )
108
+ }
109
+ }
102
110
let result = null
103
111
try {
104
- const conn = informix . openSync ( connectionString )
105
- result = conn . querySync ( query )
106
- conn . closeSync ( )
112
+ result = dbConnection . querySync ( query )
107
113
} catch ( ex ) {
108
- logger . error ( ex )
114
+ logger . error ( `Informix query error: ${ ex } ` )
109
115
}
110
116
111
117
return result
0 commit comments