forked from oracle/node-oracledb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnjsPool.c
754 lines (645 loc) · 27.8 KB
/
njsPool.c
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
// Copyright (c) 2015, 2023, Oracle and/or its affiliates.
//-----------------------------------------------------------------------------
//
// This software is dual-licensed to you under the Universal Permissive License
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
// either license.
//
// If you elect to accept the software under the Apache License, Version 2.0,
// the following applies:
//
// 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
//
// https://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.
//
// NAME
// njsPool.c
//
// DESCRIPTION
// Pool class implementation.
//
//-----------------------------------------------------------------------------
#include "njsModule.h"
// class methods
NJS_NAPI_METHOD_DECL_ASYNC(njsPool_close);
NJS_NAPI_METHOD_DECL_ASYNC(njsPool_create);
NJS_NAPI_METHOD_DECL_ASYNC(njsPool_getConnection);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getConnectionsInUse);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getConnectionsOpen);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getPoolIncrement);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getPoolMax);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getPoolMaxPerShard);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getPoolMin);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getPoolPingInterval);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getPoolTimeout);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getStmtCacheSize);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_getSodaMetaDataCache);
NJS_NAPI_METHOD_DECL_ASYNC(njsPool_reconfigure);
NJS_NAPI_METHOD_DECL_SYNC(njsPool_returnAccessToken);
NJS_NAPI_METHOD_DECL_ASYNC(njsPool_setAccessToken);
// asynchronous methods
static NJS_ASYNC_METHOD(njsPool_closeAsync);
static NJS_ASYNC_METHOD(njsPool_createAsync);
static NJS_ASYNC_METHOD(njsPool_getConnectionAsync);
static NJS_ASYNC_METHOD(njsPool_reconfigureAsync);
static NJS_ASYNC_METHOD(njsPool_setAccessTokenAsync);
// post asynchronous methods
static NJS_ASYNC_POST_METHOD(njsPool_createPostAsync);
static NJS_ASYNC_POST_METHOD(njsPool_getConnectionPostAsync);
// finalize
static NJS_NAPI_FINALIZE(njsPool_finalize);
// properties defined by the class
static const napi_property_descriptor njsClassProperties[] = {
{ "close", NULL, njsPool_close, NULL, NULL, NULL, napi_default, NULL },
{ "create", NULL, njsPool_create, NULL, NULL, NULL, napi_default, NULL },
{ "getConnection", NULL, njsPool_getConnection, NULL, NULL, NULL,
napi_default, NULL },
{ "getConnectionsInUse", NULL, njsPool_getConnectionsInUse, NULL, NULL,
NULL, napi_default, NULL },
{ "getConnectionsOpen", NULL, njsPool_getConnectionsOpen, NULL, NULL, NULL,
napi_default, NULL },
{ "getPoolIncrement", NULL, njsPool_getPoolIncrement, NULL, NULL, NULL,
napi_default, NULL },
{ "getPoolMax", NULL, njsPool_getPoolMax, NULL, NULL, NULL, napi_default,
NULL },
{ "getPoolMaxPerShard", NULL, njsPool_getPoolMaxPerShard, NULL, NULL, NULL,
napi_default, NULL },
{ "getPoolMin", NULL, njsPool_getPoolMin, NULL, NULL, NULL, napi_default,
NULL },
{ "getPoolPingInterval", NULL, njsPool_getPoolPingInterval, NULL, NULL,
NULL, napi_default, NULL },
{ "getPoolTimeout", NULL, njsPool_getPoolTimeout, NULL, NULL, NULL,
napi_default, NULL },
{ "getStmtCacheSize", NULL, njsPool_getStmtCacheSize, NULL, NULL, NULL,
napi_default, NULL },
{ "getSodaMetaDataCache", NULL, njsPool_getSodaMetaDataCache, NULL, NULL,
NULL, napi_default, NULL },
{ "reconfigure", NULL, njsPool_reconfigure, NULL, NULL, NULL,
napi_default, NULL },
{ "returnAccessToken", NULL, njsPool_returnAccessToken, NULL, NULL, NULL,
napi_default, NULL },
{ "setAccessToken", NULL, njsPool_setAccessToken, NULL, NULL, NULL,
napi_default, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL, napi_default, NULL }
};
// class definition
const njsClassDef njsClassDefPool = {
"PoolImpl", sizeof(njsPool), njsPool_finalize, njsClassProperties, false
};
//-----------------------------------------------------------------------------
// njsPool_close()
// Close the pool.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_close, 0, NULL)
{
njsPool *pool = (njsPool*) baton->callingInstance;
baton->accessTokenCallback = pool->accessTokenCallback;
pool->accessTokenCallback = NULL;
baton->dpiPoolHandle = pool->handle;
pool->handle = NULL;
return njsBaton_queueWork(baton, env, "Close", njsPool_closeAsync, NULL,
returnValue);
}
//-----------------------------------------------------------------------------
// njsPool_closeAsync()
// Worker function for njsPool_close().
//-----------------------------------------------------------------------------
static bool njsPool_closeAsync(njsBaton *baton)
{
njsPool *pool = (njsPool*) baton->callingInstance;
pool->accessTokenCallback = baton->accessTokenCallback;
if (baton->accessTokenCallback) {
njsTokenCallback_stopNotifications(baton->accessTokenCallback);
baton->accessTokenCallback = NULL;
}
if (dpiPool_close(baton->dpiPoolHandle, DPI_MODE_POOL_CLOSE_FORCE) < 0) {
njsBaton_setErrorDPI(baton);
pool->handle = baton->dpiPoolHandle;
baton->dpiPoolHandle = NULL;
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// njsPool_create()
// Create a connection pool.
//
// PARAMETERS
// - options
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_create, 1, &njsClassDefPool)
{
napi_value callback;
if (!njsBaton_commonConnectProcessArgs(baton, env, args))
return false;
if (!njsUtils_getNamedPropertyString(env, args[0], "sessionCallback",
&baton->plsqlFixupCallback, &baton->plsqlFixupCallbackLength))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolMax",
&baton->poolMax))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolMaxPerShard",
&baton->poolMaxPerShard))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolMin",
&baton->poolMin))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolIncrement",
&baton->poolIncrement))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolTimeout",
&baton->poolTimeout))
return false;
if (!njsUtils_getNamedPropertyInt(env, args[0], "poolPingInterval",
&baton->poolPingInterval))
return false;
if (!njsUtils_getNamedPropertyBool(env, args[0], "homogeneous",
&baton->homogeneous))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "queueTimeout",
&baton->poolWaitTimeout))
return false;
if (!njsUtils_getNamedPropertyBool(env, args[0], "sodaMetaDataCache",
&baton->sodaMetadataCache))
return false;
if (!njsUtils_getNamedProperty(env, args[0], "accessTokenFn",
&callback))
return false;
if (callback && !njsTokenCallback_new(baton, env, callback))
return false;
return njsBaton_queueWork(baton, env, "create", njsPool_createAsync,
njsPool_createPostAsync, returnValue);
}
//-----------------------------------------------------------------------------
// njsPool_createAsync()
// Worker function for createPool() performed on thread. This establishes
// the connection using the information found in the baton.
//-----------------------------------------------------------------------------
static bool njsPool_createAsync(njsBaton *baton)
{
dpiCommonCreateParams commonParams;
dpiPoolCreateParams params;
dpiAccessToken accessToken;
// setup pool creation parameters
if (dpiContext_initPoolCreateParams(baton->globals->context, ¶ms) < 0)
return njsBaton_setErrorDPI(baton);
params.minSessions = baton->poolMin;
params.maxSessions = baton->poolMax;
params.maxSessionsPerShard = baton->poolMaxPerShard;
params.sessionIncrement = baton->poolIncrement;
params.getMode = (baton->poolMaxPerShard > 0) ?
DPI_MODE_POOL_GET_TIMEDWAIT : DPI_MODE_POOL_GET_WAIT;
params.waitTimeout = baton->poolWaitTimeout;
params.timeout = baton->poolTimeout;
params.externalAuth = baton->externalAuth;
params.homogeneous = baton->homogeneous;
params.plsqlFixupCallback = baton->plsqlFixupCallback;
params.plsqlFixupCallbackLength =
(uint32_t) baton->plsqlFixupCallbackLength;
if (params.externalAuth && !baton->token && !baton->privateKey)
params.homogeneous = 0;
params.pingInterval = baton->poolPingInterval;
// call function for token based authentication
if (baton->accessTokenCallback) {
params.accessTokenCallback =
(dpiAccessTokenCallback) njsTokenCallback_eventHandler;
params.accessTokenCallbackContext = baton->accessTokenCallback;
}
// setup common creation parameters
if (!njsBaton_initCommonCreateParams(baton, &commonParams))
return false;
commonParams.edition = baton->edition;
commonParams.editionLength = (uint32_t) baton->editionLength;
if (baton->sodaMetadataCache)
commonParams.sodaMetadataCache = 1;
commonParams.stmtCacheSize = baton->stmtCacheSize;
// set token based auth parameters
if (baton->token) {
accessToken.token = baton->token;
accessToken.tokenLength = baton->tokenLength;
accessToken.privateKey = baton->privateKey;
accessToken.privateKeyLength = baton->privateKeyLength;
commonParams.accessToken = &accessToken;
}
// create pool
if (dpiPool_create(baton->globals->context, baton->user,
(uint32_t) baton->userLength, baton->password,
(uint32_t) baton->passwordLength, baton->connectString,
(uint32_t) baton->connectStringLength, &commonParams,
¶ms, &baton->dpiPoolHandle) < 0)
return njsBaton_setErrorDPI(baton);
return true;
}
//-----------------------------------------------------------------------------
// njsPool_createPostAsync()
// Defines the value returned to JS.
//-----------------------------------------------------------------------------
static bool njsPool_createPostAsync(njsBaton *baton, napi_env env,
napi_value *result)
{
njsPool *pool = (njsPool*) baton->callingInstance;
// transfer the ODPI-C pool handle to the new object
pool->handle = baton->dpiPoolHandle;
baton->dpiPoolHandle = NULL;
// perform other initializations
pool->poolMax = baton->poolMax;
pool->poolMaxPerShard = baton->poolMaxPerShard;
pool->poolMin = baton->poolMin;
pool->poolIncrement = baton->poolIncrement;
pool->poolTimeout = baton->poolTimeout;
pool->poolPingInterval = baton->poolPingInterval;
pool->stmtCacheSize = baton->stmtCacheSize;
pool->sodaMetadataCache = baton->sodaMetadataCache;
// token based authentication initialization
if (baton->accessTokenCallback) {
pool->accessTokenCallback = baton->accessTokenCallback;
if (!njsTokenCallback_startNotifications(pool->accessTokenCallback,
env))
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// njsPool_finalize()
// Invoked when the njsPool object is garbage collected.
//-----------------------------------------------------------------------------
static void njsPool_finalize(napi_env env, void *finalizeData,
void *finalizeHint)
{
njsPool *pool = (njsPool*) finalizeData;
if (pool->handle) {
NJS_FREE_AND_CLEAR(pool->accessTokenCallback);
dpiPool_release(pool->handle);
pool->handle = NULL;
}
free(pool);
}
//-----------------------------------------------------------------------------
// njsPool_getConnection()
// Acquires a connection from the pool and returns it.
//
// PARAMETERS
// - options
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_getConnection, 1, NULL)
{
if (!njsUtils_getNamedPropertyString(env, args[0], "connectionClass",
&baton->connectionClass, &baton->connectionClassLength))
return false;
if (!njsUtils_getNamedPropertyString(env, args[0], "user", &baton->user,
&baton->userLength))
return false;
if (!njsUtils_getNamedPropertyString(env, args[0], "password",
&baton->password, &baton->passwordLength))
return false;
if (!njsUtils_getNamedPropertyString(env, args[0], "tag", &baton->tag,
&baton->tagLength))
return false;
if (!njsUtils_getNamedPropertyBool(env, args[0], "matchAnyTag",
&baton->matchAnyTag))
return false;
if (!njsUtils_getNamedPropertyShardingKey(env, args[0], "shardingKey",
&baton->numShardingKeyColumns, &baton->shardingKeyColumns))
return false;
if (!njsUtils_getNamedPropertyShardingKey(env, args[0], "superShardingKey",
&baton->numSuperShardingKeyColumns,
&baton->superShardingKeyColumns))
return false;
return njsBaton_queueWork(baton, env, "GetConnection",
njsPool_getConnectionAsync, njsPool_getConnectionPostAsync,
returnValue);
}
//-----------------------------------------------------------------------------
// njsPool_getConnectionAsync()
// Worker function for njsPool_getConnection().
//-----------------------------------------------------------------------------
static bool njsPool_getConnectionAsync(njsBaton *baton)
{
njsPool *pool = (njsPool*) baton->callingInstance;
dpiConnCreateParams params;
// populate connection creation parameters
if (dpiContext_initConnCreateParams(baton->globals->context, ¶ms) < 0)
return njsBaton_setErrorDPI(baton);
params.matchAnyTag = baton->matchAnyTag;
params.connectionClass = baton->connectionClass;
params.connectionClassLength = (uint32_t) baton->connectionClassLength;
params.tag = baton->tag;
params.tagLength = (uint32_t) baton->tagLength;
// Sharding
params.shardingKeyColumns = baton->shardingKeyColumns;
params.numShardingKeyColumns = baton->numShardingKeyColumns;
params.superShardingKeyColumns = baton->superShardingKeyColumns;
params.numSuperShardingKeyColumns = baton->numSuperShardingKeyColumns;
// acquire connection from pool
if (dpiPool_acquireConnection(pool->handle, baton->user,
(uint32_t) baton->userLength, baton->password,
(uint32_t) baton->passwordLength, ¶ms,
&baton->dpiConnHandle) < 0)
return njsBaton_setErrorDPI(baton);
// keep track of return parameters
NJS_FREE_AND_CLEAR(baton->tag);
baton->tagLength = 0;
if (params.outTagLength > 0) {
baton->tag = malloc(params.outTagLength);
if (!baton->tag)
return njsBaton_setErrorInsufficientMemory(baton);
strncpy(baton->tag, params.outTag, params.outTagLength);
baton->tagLength = params.outTagLength;
}
baton->newSession = params.outNewSession;
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getConnectionPostAsync()
// Defines the value returned to JS.
//-----------------------------------------------------------------------------
static bool njsPool_getConnectionPostAsync(njsBaton *baton, napi_env env,
napi_value *result)
{
napi_value temp;
// create connection
if (!njsConnection_newFromBaton(baton, env, result))
return false;
// store a reference to the pool on the connection
NJS_CHECK_NAPI(env, napi_get_reference_value(env, baton->jsCallingObjRef,
&temp))
NJS_CHECK_NAPI(env, napi_set_named_property(env, *result, "_pool", temp))
// store a boolean indicating whether a new session was created
NJS_CHECK_NAPI(env, napi_get_boolean(env, baton->newSession, &temp))
NJS_CHECK_NAPI(env, napi_set_named_property(env, *result, "_newSession",
temp))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_reconfigure()
// Change the pool parameters
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_reconfigure, 1, NULL)
{
njsPool *pool = (njsPool*) baton->callingInstance;
// set defaults
baton->poolMin = pool->poolMin;
baton->poolMax = pool->poolMax;
baton->poolIncrement = pool->poolIncrement;
baton->poolPingInterval = pool->poolPingInterval;
baton->poolTimeout = pool->poolTimeout;
baton->stmtCacheSize = pool->stmtCacheSize;
baton->poolMaxPerShard = pool->poolMaxPerShard;
baton->sodaMetadataCache = pool->sodaMetadataCache;
// check arguments
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolMin",
&baton->poolMin))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolMax",
&baton->poolMax))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolMaxPerShard",
&baton->poolMaxPerShard))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolIncrement",
&baton->poolIncrement))
return false;
if (!njsUtils_getNamedPropertyInt(env, args[0], "poolPingInterval",
&baton->poolPingInterval))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "poolTimeout",
&baton->poolTimeout))
return false;
if (!njsUtils_getNamedPropertyUnsignedInt(env, args[0], "stmtCacheSize",
&baton->stmtCacheSize))
return false;
if (!njsUtils_getNamedPropertyBool(env, args[0], "sodaMetaDataCache",
&baton->sodaMetadataCache))
return false;
return njsBaton_queueWork(baton, env, "Reconfigure",
njsPool_reconfigureAsync, NULL, returnValue);
}
//-----------------------------------------------------------------------------
// njsPool_reconfigureAsync()
// Worker function for njsPool_reconfigure().
//-----------------------------------------------------------------------------
static bool njsPool_reconfigureAsync(njsBaton *baton)
{
njsPool *pool = (njsPool*) baton->callingInstance;
if ((pool->poolMin != baton->poolMin) ||
(pool->poolMax != baton->poolMax) ||
(pool->poolIncrement != baton->poolIncrement)) {
// reconfigure pool-creation parameters
if (dpiPool_reconfigure(pool->handle, baton->poolMin, baton->poolMax,
baton->poolIncrement) < 0)
return njsBaton_setErrorDPI(baton);
// Update the pool creation parameters.
pool->poolMin = baton->poolMin;
pool->poolMax = baton->poolMax;
pool->poolIncrement = baton->poolIncrement;
}
// Other pool parameters: poolPingInterval, poolTimeout, poolMaxPerShard,
// stmtCacheSize, sodaMetaDataCache
if (pool->poolPingInterval != baton->poolPingInterval) {
if (dpiPool_setPingInterval(pool->handle, baton->poolPingInterval) < 0)
return njsBaton_setErrorDPI(baton);
pool->poolPingInterval = baton->poolPingInterval;
}
if (pool->poolTimeout != baton->poolTimeout) {
if (dpiPool_setTimeout(pool->handle, baton->poolTimeout) < 0)
return njsBaton_setErrorDPI(baton);
pool->poolTimeout = baton->poolTimeout;
}
if (pool->poolMaxPerShard != baton->poolMaxPerShard) {
if (dpiPool_setMaxSessionsPerShard(pool->handle,
baton->poolMaxPerShard) < 0)
return njsBaton_setErrorDPI(baton);
pool->poolMaxPerShard = baton->poolMaxPerShard;
}
if (pool->stmtCacheSize != baton->stmtCacheSize) {
if (dpiPool_setStmtCacheSize(pool->handle, baton->stmtCacheSize) < 0)
return njsBaton_setErrorDPI(baton);
pool->stmtCacheSize = baton->stmtCacheSize;
}
if (pool->sodaMetadataCache != baton->sodaMetadataCache) {
if (dpiPool_setSodaMetadataCache(pool->handle,
baton->sodaMetadataCache ? 1 : 0) < 0) {
return njsBaton_setErrorDPI(baton);
}
pool->sodaMetadataCache = baton->sodaMetadataCache;
}
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getConnectionsInUse()
// Get accessor of "connectionsInUse" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getConnectionsInUse, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
uint32_t value;
if (pool->handle) {
if (dpiPool_getBusyCount(pool->handle, &value) < 0)
return njsUtils_throwErrorDPI(env, globals);
NJS_CHECK_NAPI(env, napi_create_uint32(env, value, returnValue))
}
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getConnectionsOpen()
// Get accessor of "connectionsOpen" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getConnectionsOpen, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
uint32_t value;
if (pool->handle) {
if (dpiPool_getOpenCount(pool->handle, &value) < 0)
return njsUtils_throwErrorDPI(env, globals);
NJS_CHECK_NAPI(env, napi_create_uint32(env, value, returnValue))
}
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getPoolIncrement()
// Get accessor of "poolIncrement" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getPoolIncrement, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_uint32(env, pool->poolIncrement,
returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getPoolMax()
// Get accessor of "poolMax" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getPoolMax, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_uint32(env, pool->poolMax, returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getPoolMaxPerShard()
// Get accessor of "poolMaxPerShard" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getPoolMaxPerShard, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_uint32(env, pool->poolMaxPerShard,
returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getPoolMin()
// Get accessor of "poolMin" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getPoolMin, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_uint32(env, pool->poolMin, returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getPoolPingInterval()
// Get accessor of "poolPingInterval" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getPoolPingInterval, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_int32(env, pool->poolPingInterval,
returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getPoolTimeout()
// Get accessor of "poolTimeout" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getPoolTimeout, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_uint32(env, pool->poolTimeout,
returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getSodaMetaDataCache()
// Get accessor for "sodaMetaDataCache" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getSodaMetaDataCache, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
int enabled;
if (pool->handle) {
if (dpiPool_getSodaMetadataCache(pool->handle, &enabled) < 0)
enabled = 0;
NJS_CHECK_NAPI(env, napi_get_boolean(env, enabled, returnValue))
}
return true;
}
//-----------------------------------------------------------------------------
// njsPool_getStmtCacheSize()
// Get accessor of "stmtCacheSize" property.
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_getStmtCacheSize, 0, NULL)
{
njsPool *pool = (njsPool*) callingInstance;
NJS_CHECK_NAPI(env, napi_create_uint32(env, pool->stmtCacheSize,
returnValue))
return true;
}
//-----------------------------------------------------------------------------
// njsPool_returnAccessToken()
// Returns the access token through to the callback. This needs to be done
// independently in order to handle possible asynchronous Javascript code.
//
// PARAMETERS
// - externalObj (contains native njsAccessToken structure)
// - accessToken (value to be returned through callback)
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_SYNC(njsPool_returnAccessToken, 2, NULL)
{
njsTokenCallback *callback;
NJS_CHECK_NAPI(env, napi_get_value_external(env, args[0],
(void**) &callback))
return njsTokenCallback_returnAccessToken(callback, env, args[1]);
}
//-----------------------------------------------------------------------------
// njsPool_setAccessToken() [PUBLIC]
// set access token and private key for existing pool in token
// based authentication
//-----------------------------------------------------------------------------
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_setAccessToken, 1, NULL)
{
if (!njsUtils_getNamedPropertyString(env, args[0], "token", &baton->token,
&baton->tokenLength))
return false;
if (!njsUtils_getNamedPropertyString(env, args[0], "privateKey",
&baton->privateKey, &baton->privateKeyLength))
return false;
return njsBaton_queueWork(baton, env, "token",
njsPool_setAccessTokenAsync, NULL, returnValue);
}
//-----------------------------------------------------------------------------
// njsPool_setAccessTokenAsync() [PUBLIC]
// set access token and private key for existing pool in token
// based authentication
//-----------------------------------------------------------------------------
static bool njsPool_setAccessTokenAsync(njsBaton *baton)
{
njsPool *pool = (njsPool*) baton->callingInstance;
dpiAccessToken tokenInfo;
tokenInfo.token = baton->token;
tokenInfo.tokenLength = baton->tokenLength;
tokenInfo.privateKey = baton->privateKey;
tokenInfo.privateKeyLength = baton->privateKeyLength;
if (dpiPool_setAccessToken(pool->handle, &tokenInfo) < 0)
return njsBaton_setErrorDPI(baton);
return true;
}