Skip to content

Commit 89d5dbf

Browse files
committed
Internal code refactoring and test case updates
1 parent 664cc07 commit 89d5dbf

File tree

6 files changed

+89
-166
lines changed

6 files changed

+89
-166
lines changed

lib/aqQueue.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -169,7 +169,7 @@ class AqQueue {
169169
errors.assertArgCount(arguments, 1, 1);
170170
errors.assertParamValue(Number.isInteger(maxMessages) && maxMessages > 0,
171171
1);
172-
const msgImpls = await this._impl.deqMany(maxMessages);
172+
const msgImpls = await this._impl.deq(maxMessages);
173173
return msgImpls.map(i => this._makeMessage(i));
174174
}
175175

@@ -180,9 +180,9 @@ class AqQueue {
180180
//---------------------------------------------------------------------------
181181
async deqOne() {
182182
errors.assertArgCount(arguments, 0, 0);
183-
const msgImpl = await this._impl.deqOne();
184-
if (msgImpl)
185-
return this._makeMessage(msgImpl);
183+
const msgImpls = await this._impl.deq(1);
184+
if (msgImpls)
185+
return this._makeMessage(msgImpls[0]);
186186
}
187187

188188
//---------------------------------------------------------------------------
@@ -212,7 +212,7 @@ class AqQueue {
212212
for (let i = 0; i < messages.length; i++) {
213213
verifiedMessages[i] = this._verifyMessage(messages[i]);
214214
}
215-
const msgImpls = await this._impl.enqMany(verifiedMessages);
215+
const msgImpls = await this._impl.enq(verifiedMessages);
216216
return msgImpls.map(i => this._makeMessage(i));
217217
}
218218

@@ -224,8 +224,8 @@ class AqQueue {
224224
async enqOne(message) {
225225
errors.assertArgCount(arguments, 1, 1);
226226
message = this._verifyMessage(message);
227-
const msgImpl = await this._impl.enqOne(message);
228-
return this._makeMessage(msgImpl);
227+
const msgImpls = await this._impl.enq([message]);
228+
return this._makeMessage(msgImpls[0]);
229229
}
230230

231231
//---------------------------------------------------------------------------

src/njsAqQueue.c

Lines changed: 54 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -33,35 +33,26 @@
3333
#include "njsModule.h"
3434

3535
// class methods
36-
NJS_NAPI_METHOD_DECL_ASYNC(njsAqQueue_deqMany);
37-
NJS_NAPI_METHOD_DECL_ASYNC(njsAqQueue_deqOne);
38-
NJS_NAPI_METHOD_DECL_ASYNC(njsAqQueue_enqMany);
39-
NJS_NAPI_METHOD_DECL_ASYNC(njsAqQueue_enqOne);
36+
NJS_NAPI_METHOD_DECL_ASYNC(njsAqQueue_deq);
37+
NJS_NAPI_METHOD_DECL_ASYNC(njsAqQueue_enq);
4038

4139
// asynchronous methods
42-
static NJS_ASYNC_METHOD(njsAqQueue_deqManyAsync);
43-
static NJS_ASYNC_METHOD(njsAqQueue_deqOneAsync);
44-
static NJS_ASYNC_METHOD(njsAqQueue_enqManyAsync);
45-
static NJS_ASYNC_METHOD(njsAqQueue_enqOneAsync);
40+
static NJS_ASYNC_METHOD(njsAqQueue_deqAsync);
41+
static NJS_ASYNC_METHOD(njsAqQueue_enqAsync);
4642

4743
// post asynchronous methods
48-
static NJS_ASYNC_POST_METHOD(njsAqQueue_deqManyPostAsync);
49-
static NJS_ASYNC_POST_METHOD(njsAqQueue_deqOnePostAsync);
50-
static NJS_ASYNC_POST_METHOD(njsAqQueue_enqManyPostAsync);
51-
static NJS_ASYNC_POST_METHOD(njsAqQueue_enqOnePostAsync);
44+
static NJS_ASYNC_POST_METHOD(njsAqQueue_deqPostAsync);
45+
static NJS_ASYNC_POST_METHOD(njsAqQueue_enqPostAsync);
46+
5247

5348
// finalize
5449
static NJS_NAPI_FINALIZE(njsAqQueue_finalize);
5550

5651
// properties defined by the class
5752
static const napi_property_descriptor njsClassProperties[] = {
58-
{ "deqMany", NULL, njsAqQueue_deqMany, NULL, NULL, NULL, napi_default,
59-
NULL },
60-
{ "deqOne", NULL, njsAqQueue_deqOne, NULL, NULL, NULL, napi_default,
61-
NULL },
62-
{ "enqMany", NULL, njsAqQueue_enqMany, NULL, NULL, NULL, napi_default,
53+
{ "deq", NULL, njsAqQueue_deq, NULL, NULL, NULL, napi_default,
6354
NULL },
64-
{ "enqOne", NULL, njsAqQueue_enqOne, NULL, NULL, NULL, napi_default,
55+
{ "enq", NULL, njsAqQueue_enq, NULL, NULL, NULL, napi_default,
6556
NULL },
6657
{ NULL, NULL, NULL, NULL, NULL, NULL, napi_default, NULL }
6758
};
@@ -337,45 +328,50 @@ bool njsAqQueue_createFromHandle(njsBaton *baton, napi_env env,
337328

338329

339330
//-----------------------------------------------------------------------------
340-
// njsAqQueue_deqMany()
341-
// Dequeue multiple messages from an AQ queue.
331+
// njsAqQueue_deq()
332+
// Dequeue messages from an AQ queue.
342333
//
343334
// PARAMETERS
344-
// - number specifying the maximum number of messages to dequeue
335+
// - an array of one or more messages to dequeue
345336
//-----------------------------------------------------------------------------
346-
NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_deqMany, 1, NULL)
337+
NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_deq, 1, NULL)
347338
{
348339
NJS_CHECK_NAPI(env, napi_get_value_uint32(env, args[0],
349340
&baton->numMsgProps))
350-
return njsBaton_queueWork(baton, env, "DeqMany", njsAqQueue_deqManyAsync,
351-
njsAqQueue_deqManyPostAsync, returnValue);
341+
return njsBaton_queueWork(baton, env, "Deq", njsAqQueue_deqAsync,
342+
njsAqQueue_deqPostAsync, returnValue);
352343
}
353344

354345

355346
//-----------------------------------------------------------------------------
356-
// njsAqQueue_deqManyAsync()
357-
// Worker function for njsAqQueue_deqMany().
347+
// njsAqQueue_deqAsync()
348+
// Worker function for njsAqQueue_deqOne() & njsAqueue_deqMany()
358349
//-----------------------------------------------------------------------------
359-
static bool njsAqQueue_deqManyAsync(njsBaton *baton)
350+
static bool njsAqQueue_deqAsync(njsBaton* baton)
360351
{
361352
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
362353

363354
baton->msgProps = calloc(baton->numMsgProps, sizeof(dpiMsgProps*));
364355
if (!baton->msgProps)
365356
return njsBaton_setErrorInsufficientMemory(baton);
366-
if (dpiQueue_deqMany(queue->handle, &baton->numMsgProps,
367-
baton->msgProps) < 0)
368-
return njsBaton_setErrorDPI(baton);
369-
357+
if (baton->numMsgProps == 1) {
358+
if (dpiQueue_deqOne(queue->handle, &baton->msgProps[0]) < 0)
359+
return njsBaton_setErrorDPI(baton);
360+
} else {
361+
// deqMany case
362+
if (dpiQueue_deqMany(queue->handle, &baton->numMsgProps,
363+
baton->msgProps) < 0)
364+
return njsBaton_setErrorDPI(baton);
365+
}
370366
return true;
371367
}
372368

373369

374370
//-----------------------------------------------------------------------------
375-
// njsAqQueue_deqManyPostAsync()
371+
// njsAqQueue_deqPostAsync()
376372
// Defines the value returned to JS.
377373
//-----------------------------------------------------------------------------
378-
static bool njsAqQueue_deqManyPostAsync(njsBaton *baton, napi_env env,
374+
static bool njsAqQueue_deqPostAsync(njsBaton *baton, napi_env env,
379375
napi_value *result)
380376
{
381377
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
@@ -396,60 +392,13 @@ static bool njsAqQueue_deqManyPostAsync(njsBaton *baton, napi_env env,
396392

397393

398394
//-----------------------------------------------------------------------------
399-
// njsAqQueue_deqOne()
400-
// Dequeue a message from an AQ queue.
401-
//
402-
// PARAMETERS - NONE
403-
//-----------------------------------------------------------------------------
404-
NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_deqOne, 0, NULL)
405-
{
406-
return njsBaton_queueWork(baton, env, "DeqOne", njsAqQueue_deqOneAsync,
407-
njsAqQueue_deqOnePostAsync, returnValue);
408-
}
409-
410-
411-
//-----------------------------------------------------------------------------
412-
// njsAqQueue_deqOneAsync()
413-
// Worker function for njsAqQueue_deqOne().
414-
//-----------------------------------------------------------------------------
415-
static bool njsAqQueue_deqOneAsync(njsBaton *baton)
416-
{
417-
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
418-
419-
if (dpiQueue_deqOne(queue->handle, &baton->dpiMsgPropsHandle) < 0)
420-
return njsBaton_setErrorDPI(baton);
421-
422-
return true;
423-
}
424-
425-
426-
//-----------------------------------------------------------------------------
427-
// njsAqQueue_deqOnePostAsync()
428-
// Defines the value returned to JS.
429-
//-----------------------------------------------------------------------------
430-
static bool njsAqQueue_deqOnePostAsync(njsBaton *baton, napi_env env,
431-
napi_value *result)
432-
{
433-
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
434-
435-
if (baton->dpiMsgPropsHandle) {
436-
if (!njsAqMessage_createFromHandle(baton, baton->dpiMsgPropsHandle,
437-
env, queue, result))
438-
return false;
439-
baton->dpiMsgPropsHandle = NULL;
440-
}
441-
return true;
442-
}
443-
444-
445-
//-----------------------------------------------------------------------------
446-
// njsAqQueue_enqMany()
447-
// Enqueue multiple message into an AQ queue.
395+
// njsAqQueue_enq()
396+
// Enqueue message(s) into an AQ queue.
448397
//
449398
// PARAMETERS
450-
// - array of objects containing payload and options
399+
// - array of one or more messages to enqueue
451400
//-----------------------------------------------------------------------------
452-
NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_enqMany, 1, NULL)
401+
NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_enq, 1, NULL)
453402
{
454403
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
455404
napi_value message;
@@ -466,33 +415,39 @@ NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_enqMany, 1, NULL)
466415
&baton->msgProps[i]))
467416
return false;
468417
}
469-
return njsBaton_queueWork(baton, env, "EnqMany", njsAqQueue_enqManyAsync,
470-
njsAqQueue_enqManyPostAsync, returnValue);
418+
return njsBaton_queueWork(baton, env, "Enq", njsAqQueue_enqAsync,
419+
njsAqQueue_enqPostAsync, returnValue);
471420
}
472421

473422

474423
//-----------------------------------------------------------------------------
475-
// njsAqQueue_enqManyAsync()
476-
// Worker function for njsAqQueue_enqMany().
424+
// njsAqQueue_enqAsync()
425+
//
426+
// Worker thread function for njsAqQueue_enqOne() & njsAqQueue_enqMany()
477427
//-----------------------------------------------------------------------------
478-
static bool njsAqQueue_enqManyAsync(njsBaton *baton)
428+
static bool njsAqQueue_enqAsync(njsBaton *baton)
479429
{
480430
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
481431

482-
if (dpiQueue_enqMany(queue->handle, baton->numMsgProps,
483-
baton->msgProps) < 0)
484-
return njsBaton_setErrorDPI(baton);
485-
432+
if (baton->numMsgProps == 1) {
433+
// enqOne case
434+
if (dpiQueue_enqOne(queue->handle, baton->msgProps[0]) < 0)
435+
return njsBaton_setErrorDPI(baton);
436+
} else {
437+
// enqMany case
438+
if (dpiQueue_enqMany(queue->handle, baton->numMsgProps,
439+
baton->msgProps) < 0)
440+
return njsBaton_setErrorDPI(baton);
441+
}
486442
return true;
487443
}
488444

489445

490446
//-----------------------------------------------------------------------------
491-
// njsAqQueue_enqManyPostAsync()
492-
// returns the value to JS.
493-
//
447+
// njsAqQueue_enqOnePostAsync()
448+
// Defines the value returned to JS.
494449
//-----------------------------------------------------------------------------
495-
static bool njsAqQueue_enqManyPostAsync(njsBaton *baton, napi_env env,
450+
static bool njsAqQueue_enqPostAsync(njsBaton *baton, napi_env env,
496451
napi_value *result)
497452
{
498453
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
@@ -501,6 +456,7 @@ static bool njsAqQueue_enqManyPostAsync(njsBaton *baton, napi_env env,
501456

502457
NJS_CHECK_NAPI(env, napi_create_array_with_length(env, baton->numMsgProps,
503458
result))
459+
504460
for (i = 0; i < baton->numMsgProps; i++) {
505461
if (!njsAqMessage_createFromHandle(baton, baton->msgProps[i], env,
506462
queue, &temp))
@@ -511,57 +467,6 @@ static bool njsAqQueue_enqManyPostAsync(njsBaton *baton, napi_env env,
511467
return true;
512468
}
513469

514-
515-
//-----------------------------------------------------------------------------
516-
// njsAqQueue_enqOne()
517-
// Enqueue a message into an AQ queue.
518-
//
519-
// PARAMETERS
520-
// - object containing payload and message properties
521-
//-----------------------------------------------------------------------------
522-
NJS_NAPI_METHOD_IMPL_ASYNC(njsAqQueue_enqOne, 1, NULL)
523-
{
524-
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
525-
526-
if (!njsAqQueue_createMessage(baton, queue, env, args[0],
527-
&baton->dpiMsgPropsHandle))
528-
return false;
529-
return njsBaton_queueWork(baton, env, "EnqOne", njsAqQueue_enqOneAsync,
530-
njsAqQueue_enqOnePostAsync, returnValue);
531-
}
532-
533-
534-
//-----------------------------------------------------------------------------
535-
// njsAqQueue_enqOneAsync()
536-
// Worker function for njsAqQueue_enqOne().
537-
//-----------------------------------------------------------------------------
538-
static bool njsAqQueue_enqOneAsync(njsBaton *baton)
539-
{
540-
njsAqQueue *queue = (njsAqQueue*) baton->callingInstance;
541-
542-
if (dpiQueue_enqOne(queue->handle, baton->dpiMsgPropsHandle) < 0)
543-
return njsBaton_setErrorDPI(baton);
544-
545-
return true;
546-
}
547-
548-
549-
550-
//-----------------------------------------------------------------------------
551-
// njsAqQueue_enqOnePostAsync()
552-
// Defines the value returned to JS.
553-
//-----------------------------------------------------------------------------
554-
static bool njsAqQueue_enqOnePostAsync(njsBaton *baton, napi_env env,
555-
napi_value *result)
556-
{
557-
njsAqQueue *queue = (njsAqQueue*)baton->callingInstance;
558-
if (!njsAqMessage_createFromHandle(baton, baton->dpiMsgPropsHandle,
559-
env, queue, result))
560-
return false;
561-
baton->dpiMsgPropsHandle = NULL;
562-
return true;
563-
}
564-
565470
//-----------------------------------------------------------------------------
566471
// njsAqQueue_finalize()
567472
// Invoked when the njsAqQueue object is garbage collected.

src/njsBaton.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2015, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -246,10 +246,6 @@ void njsBaton_free(njsBaton *baton, napi_env env)
246246
dpiLob_release(baton->dpiLobHandle);
247247
baton->dpiLobHandle = NULL;
248248
}
249-
if (baton->dpiMsgPropsHandle) {
250-
dpiMsgProps_release(baton->dpiMsgPropsHandle);
251-
baton->dpiMsgPropsHandle = NULL;
252-
}
253249
if (baton->dpiPoolHandle) {
254250
dpiPool_release(baton->dpiPoolHandle);
255251
baton->dpiPoolHandle = NULL;

src/njsModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2019, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2019, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -340,7 +340,6 @@ struct njsBaton {
340340
// ODPI-C handles (requires release)
341341
dpiConn *dpiConnHandle;
342342
dpiLob *dpiLobHandle;
343-
dpiMsgProps *dpiMsgPropsHandle;
344343
dpiPool *dpiPoolHandle;
345344
dpiStmt *dpiStmtHandle;
346345
dpiObjectType *dpiObjectTypeHandle;

0 commit comments

Comments
 (0)