oracledb 2.2.0 → 2.3.0
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 +44 -0
- package/README.md +2 -2
- package/binding.gyp +1 -0
- package/lib/connection.js +46 -0
- package/lib/oracledb.js +84 -0
- package/lib/pool.js +20 -9
- package/lib/querystream.js +2 -1
- package/lib/rel.txt +1 -1
- package/odpi/README.md +2 -2
- package/odpi/include/dpi.h +40 -4
- package/odpi/src/dpiConn.c +64 -5
- package/odpi/src/dpiContext.c +24 -10
- package/odpi/src/dpiEnv.c +5 -1
- package/odpi/src/dpiErrorMessages.h +3 -0
- package/odpi/src/dpiImpl.h +49 -4
- package/odpi/src/dpiOci.c +4 -3
- package/odpi/src/dpiPool.c +88 -18
- package/odpi/src/dpiStmt.c +35 -10
- package/odpi/src/dpiSubscr.c +98 -5
- package/odpi/src/dpiVar.c +7 -1
- package/package/MAKEPKG.BAT +64 -1
- package/package/README.md +5 -1
- package/package/oracledbinstall.js +1 -1
- package/package/package.json +2 -2
- package/package.json +2 -2
- package/src/njsCommon.cpp +56 -6
- package/src/njsCommon.h +28 -8
- package/src/njsConnection.cpp +285 -35
- package/src/njsConnection.h +12 -1
- package/src/njsIntLob.cpp +4 -0
- package/src/njsMessages.cpp +3 -0
- package/src/njsMessages.h +3 -0
- package/src/njsOracle.cpp +56 -0
- package/src/njsOracle.h +6 -1
- package/src/njsPool.cpp +21 -3
- package/src/njsSubscription.cpp +388 -0
- package/src/njsSubscription.h +111 -0
package/src/njsPool.cpp
CHANGED
|
@@ -360,14 +360,24 @@ NAN_METHOD(njsPool::GetConnection)
|
|
|
360
360
|
{
|
|
361
361
|
njsBaton *baton;
|
|
362
362
|
njsPool *pool;
|
|
363
|
+
Local<Object> connProps;
|
|
363
364
|
|
|
364
|
-
pool = (njsPool*) ValidateArgs(info,
|
|
365
|
+
pool = (njsPool*) ValidateArgs(info, 2, 2);
|
|
365
366
|
if (!pool)
|
|
366
367
|
return;
|
|
368
|
+
|
|
369
|
+
/* Get optional connection properties: argument may have empty json */
|
|
370
|
+
if (!pool->GetObjectArg(info, 0, connProps))
|
|
371
|
+
return;
|
|
372
|
+
|
|
367
373
|
baton = pool->CreateBaton(info);
|
|
368
374
|
if (!baton)
|
|
369
375
|
return;
|
|
370
376
|
if (baton->error.empty()) {
|
|
377
|
+
/* Connection Properties: If empty json, values will be empty */
|
|
378
|
+
baton->GetStringFromJSON(connProps, "user", 0, baton->user);
|
|
379
|
+
baton->GetStringFromJSON(connProps, "password", 0, baton->password);
|
|
380
|
+
|
|
371
381
|
baton->jsOracledb.Reset(pool->jsOracledb);
|
|
372
382
|
njsOracledb *oracledb = baton->GetOracledb();
|
|
373
383
|
baton->connClass = oracledb->getConnectionClass();
|
|
@@ -397,8 +407,16 @@ void njsPool::Async_GetConnection(njsBaton *baton)
|
|
|
397
407
|
params.connectionClass = baton->connClass.c_str();
|
|
398
408
|
params.connectionClassLength = baton->connClass.length();
|
|
399
409
|
}
|
|
400
|
-
if (dpiPool_acquireConnection(baton->dpiPoolHandle,
|
|
401
|
-
|
|
410
|
+
if (dpiPool_acquireConnection(baton->dpiPoolHandle,
|
|
411
|
+
baton->user.empty() ?
|
|
412
|
+
NULL : baton->user.c_str(),
|
|
413
|
+
baton->user.empty() ?
|
|
414
|
+
0 : baton->user.length(),
|
|
415
|
+
baton->password.empty () ?
|
|
416
|
+
NULL : baton->password.c_str(),
|
|
417
|
+
baton->password.empty () ?
|
|
418
|
+
0 : baton->password.length(),
|
|
419
|
+
¶ms, &baton->dpiConnHandle) < 0)
|
|
402
420
|
baton->GetDPIError();
|
|
403
421
|
}
|
|
404
422
|
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
*
|
|
5
|
+
* You may not use the identified files except in compliance with the Apache
|
|
6
|
+
* License, Version 2.0 (the "License.")
|
|
7
|
+
*
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
13
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
*
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
* This file uses NAN:
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) 2015 NAN contributors
|
|
21
|
+
*
|
|
22
|
+
* NAN contributors listed at https://github.com/rvagg/nan#contributors
|
|
23
|
+
*
|
|
24
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
25
|
+
* a copy of this software and associated documentation files (the
|
|
26
|
+
* "Software"), to deal in the Software without restriction, including
|
|
27
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
28
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
29
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
30
|
+
* the following conditions:
|
|
31
|
+
*
|
|
32
|
+
* The above copyright notice and this permission notice shall be
|
|
33
|
+
* included in all copies or substantial portions of the Software.
|
|
34
|
+
*
|
|
35
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
36
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
37
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
38
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
39
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
40
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
41
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
42
|
+
*
|
|
43
|
+
* NAME
|
|
44
|
+
* njsSubscription.cpp
|
|
45
|
+
*
|
|
46
|
+
* DESCRIPTION
|
|
47
|
+
* Subscription class implementation.
|
|
48
|
+
*
|
|
49
|
+
*****************************************************************************/
|
|
50
|
+
|
|
51
|
+
#include "njsSubscription.h"
|
|
52
|
+
#include "njsOracle.h"
|
|
53
|
+
|
|
54
|
+
using namespace std;
|
|
55
|
+
using namespace node;
|
|
56
|
+
using namespace v8;
|
|
57
|
+
|
|
58
|
+
// peristent ResultSet class handle
|
|
59
|
+
Nan::Persistent<FunctionTemplate> njsSubscription::subscriptionTemplate_s;
|
|
60
|
+
|
|
61
|
+
//-----------------------------------------------------------------------------
|
|
62
|
+
// njsSubscription::~njsSubscription()
|
|
63
|
+
// Destructor. If notifications have been started (noted by the presence of a
|
|
64
|
+
// subscription handle) then notifications will be stopped.
|
|
65
|
+
//-----------------------------------------------------------------------------
|
|
66
|
+
njsSubscription::~njsSubscription()
|
|
67
|
+
{
|
|
68
|
+
if (dpiSubscrHandle)
|
|
69
|
+
StopNotifications();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
//-----------------------------------------------------------------------------
|
|
74
|
+
// njsSubscription::ProcessNotification()
|
|
75
|
+
// This method is called inside the event loop in the JavaScript main thread.
|
|
76
|
+
// It works together with the EventHandler() method and lets that function
|
|
77
|
+
// know when its work is complete by "waiting" for the barrier.
|
|
78
|
+
//-----------------------------------------------------------------------------
|
|
79
|
+
void njsSubscription::ProcessNotification(uv_async_t *handle)
|
|
80
|
+
{
|
|
81
|
+
njsSubscription *subscription = (njsSubscription*) handle->data;
|
|
82
|
+
Nan::HandleScope scope;
|
|
83
|
+
|
|
84
|
+
Local<Function> callback = Nan::New<Function>(subscription->jsCallback);
|
|
85
|
+
Local<Value> callbackArgs[1];
|
|
86
|
+
callbackArgs[0] = subscription->CreateMessage(subscription->message);
|
|
87
|
+
Nan::AsyncResource *asyncResource =
|
|
88
|
+
new Nan::AsyncResource("node-oracledb:SubscrCallback");
|
|
89
|
+
asyncResource->runInAsyncScope(Nan::GetCurrentContext()->Global(),
|
|
90
|
+
callback, 1, callbackArgs);
|
|
91
|
+
delete asyncResource;
|
|
92
|
+
if (!subscription->message->registered)
|
|
93
|
+
subscription->StopNotifications();
|
|
94
|
+
subscription->WaitOnBarrier();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
//-----------------------------------------------------------------------------
|
|
99
|
+
// njsSubscription::WaitOnBarrier()
|
|
100
|
+
// Wait on barrier to ensure that only one message is being processed at a
|
|
101
|
+
// time.
|
|
102
|
+
//-----------------------------------------------------------------------------
|
|
103
|
+
void njsSubscription::WaitOnBarrier()
|
|
104
|
+
{
|
|
105
|
+
if (uv_barrier_wait(&barrier) > 0) {
|
|
106
|
+
uv_barrier_destroy(&barrier);
|
|
107
|
+
message = NULL;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
//-----------------------------------------------------------------------------
|
|
113
|
+
// njsSubscription::Init()
|
|
114
|
+
// Initialization function of Subscription class. Maps functions and
|
|
115
|
+
// properties from JS to C++.
|
|
116
|
+
//-----------------------------------------------------------------------------
|
|
117
|
+
void njsSubscription::Init(Local<Object> target)
|
|
118
|
+
{
|
|
119
|
+
Nan::HandleScope scope;
|
|
120
|
+
Local<FunctionTemplate> temp = Nan::New<FunctionTemplate>(New);
|
|
121
|
+
|
|
122
|
+
temp->InstanceTemplate()->SetInternalFieldCount(1);
|
|
123
|
+
temp->SetClassName(Nan::New<v8::String>("Subscription").ToLocalChecked());
|
|
124
|
+
|
|
125
|
+
subscriptionTemplate_s.Reset(temp);
|
|
126
|
+
Nan::Set(target, Nan::New<v8::String>("Subscription").ToLocalChecked(),
|
|
127
|
+
temp->GetFunction());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
//-----------------------------------------------------------------------------
|
|
132
|
+
// njsSubscription::CreateMessage()
|
|
133
|
+
// Create message object that will be passed to the callback.
|
|
134
|
+
//-----------------------------------------------------------------------------
|
|
135
|
+
Local<Object> njsSubscription::CreateMessage(dpiSubscrMessage *message)
|
|
136
|
+
{
|
|
137
|
+
Nan::EscapableHandleScope scope;
|
|
138
|
+
Local<Object> messageObj = Nan::New<Object>();
|
|
139
|
+
Local<Value> temp;
|
|
140
|
+
|
|
141
|
+
// set type, database name, transaction id and registered flag
|
|
142
|
+
Nan::Set(messageObj, Nan::New<String>("type").ToLocalChecked(),
|
|
143
|
+
Nan::New<Integer>(message->eventType));
|
|
144
|
+
if (message->dbNameLength > 0) {
|
|
145
|
+
temp = Nan::New<String>(message->dbName,
|
|
146
|
+
message->dbNameLength).ToLocalChecked();
|
|
147
|
+
Nan::Set(messageObj, Nan::New<String>("dbName").ToLocalChecked(),
|
|
148
|
+
temp);
|
|
149
|
+
}
|
|
150
|
+
if (message->txIdLength > 0) {
|
|
151
|
+
temp = Nan::CopyBuffer((char*) message->txId,
|
|
152
|
+
message->txIdLength).ToLocalChecked();
|
|
153
|
+
Nan::Set(messageObj, Nan::New<String>("txId").ToLocalChecked(), temp);
|
|
154
|
+
}
|
|
155
|
+
Nan::Set(messageObj, Nan::New<String>("registered").ToLocalChecked(),
|
|
156
|
+
Nan::New<Boolean>(message->registered));
|
|
157
|
+
|
|
158
|
+
// set tables, if applicable
|
|
159
|
+
if (message->numTables > 0) {
|
|
160
|
+
Local<Array> arr = Nan::New<Array>(message->numTables);
|
|
161
|
+
Local<Object> element;
|
|
162
|
+
for (uint32_t i = 0; i < message->numTables; i++) {
|
|
163
|
+
element = CreateMessageTable(&message->tables[i]);
|
|
164
|
+
Nan::Set(arr, i, element);
|
|
165
|
+
}
|
|
166
|
+
Nan::Set(messageObj, Nan::New<String>("tables").ToLocalChecked(), arr);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// set queries, if applicable
|
|
170
|
+
if (message->numQueries > 0) {
|
|
171
|
+
Local<Array> arr = Nan::New<Array>(message->numQueries);
|
|
172
|
+
Local<Object> element;
|
|
173
|
+
for (uint32_t i = 0; i < message->numQueries; i++) {
|
|
174
|
+
element = CreateMessageQuery(&message->queries[i]);
|
|
175
|
+
Nan::Set(arr, i, element);
|
|
176
|
+
}
|
|
177
|
+
Nan::Set(messageObj, Nan::New<String>("queries").ToLocalChecked(),
|
|
178
|
+
arr);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// set queue name, if applicable
|
|
182
|
+
if (message->queueNameLength > 0) {
|
|
183
|
+
temp = Nan::New<String>(message->queueName,
|
|
184
|
+
message->queueNameLength).ToLocalChecked();
|
|
185
|
+
Nan::Set(messageObj, Nan::New<String>("queueName").ToLocalChecked(),
|
|
186
|
+
temp);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// set consumer name, if applicable
|
|
190
|
+
if (message->consumerNameLength > 0) {
|
|
191
|
+
temp = Nan::New<String>(message->consumerName,
|
|
192
|
+
message->consumerNameLength).ToLocalChecked();
|
|
193
|
+
Nan::Set(messageObj, Nan::New<String>("consumerName").ToLocalChecked(),
|
|
194
|
+
temp);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return scope.Escape(messageObj);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
//-----------------------------------------------------------------------------
|
|
202
|
+
// njsSubscription::CreateMessageQuery()
|
|
203
|
+
// Create message query object that will be passed to the callback.
|
|
204
|
+
//-----------------------------------------------------------------------------
|
|
205
|
+
Local<Object> njsSubscription::CreateMessageQuery(
|
|
206
|
+
dpiSubscrMessageQuery *query)
|
|
207
|
+
{
|
|
208
|
+
Nan::EscapableHandleScope scope;
|
|
209
|
+
Local<Object> queryObj = Nan::New<Object>();
|
|
210
|
+
|
|
211
|
+
// set tables, if applicable
|
|
212
|
+
if (query->numTables > 0) {
|
|
213
|
+
Local<Array> arr = Nan::New<Array>(query->numTables);
|
|
214
|
+
Local<Object> element;
|
|
215
|
+
for (uint32_t i = 0; i < query->numTables; i++) {
|
|
216
|
+
element = CreateMessageTable(&query->tables[i]);
|
|
217
|
+
Nan::Set(arr, i, element);
|
|
218
|
+
}
|
|
219
|
+
Nan::Set(queryObj, Nan::New<String>("tables").ToLocalChecked(), arr);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return scope.Escape(queryObj);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
//-----------------------------------------------------------------------------
|
|
227
|
+
// njsSubscription::CreateMessageRow()
|
|
228
|
+
// Create message row object that will be passed to the callback.
|
|
229
|
+
//-----------------------------------------------------------------------------
|
|
230
|
+
Local<Object> njsSubscription::CreateMessageRow( dpiSubscrMessageRow *row)
|
|
231
|
+
{
|
|
232
|
+
Nan::EscapableHandleScope scope;
|
|
233
|
+
Local<Object> rowObj = Nan::New<Object>();
|
|
234
|
+
Local<Value> temp;
|
|
235
|
+
|
|
236
|
+
// set operation and rowid
|
|
237
|
+
Nan::Set(rowObj, Nan::New<String>("operation").ToLocalChecked(),
|
|
238
|
+
Nan::New<Integer>(row->operation));
|
|
239
|
+
temp = Nan::New<String>(row->rowid, row->rowidLength).ToLocalChecked();
|
|
240
|
+
Nan::Set(rowObj, Nan::New<String>("rowid").ToLocalChecked(), temp);
|
|
241
|
+
|
|
242
|
+
return scope.Escape(rowObj);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
//-----------------------------------------------------------------------------
|
|
247
|
+
// njsSubscription::CreateMessageTable()
|
|
248
|
+
// Create message table object that will be passed to the callback.
|
|
249
|
+
//-----------------------------------------------------------------------------
|
|
250
|
+
Local<Object> njsSubscription::CreateMessageTable(
|
|
251
|
+
dpiSubscrMessageTable *table)
|
|
252
|
+
{
|
|
253
|
+
Nan::EscapableHandleScope scope;
|
|
254
|
+
Local<Object> tableObj = Nan::New<Object>();
|
|
255
|
+
Local<Value> temp;
|
|
256
|
+
|
|
257
|
+
// set operation and name
|
|
258
|
+
Nan::Set(tableObj, Nan::New<String>("operation").ToLocalChecked(),
|
|
259
|
+
Nan::New<Integer>(table->operation));
|
|
260
|
+
temp = Nan::New<String>(table->name, table->nameLength).ToLocalChecked();
|
|
261
|
+
Nan::Set(tableObj, Nan::New<String>("name").ToLocalChecked(), temp);
|
|
262
|
+
|
|
263
|
+
// set rows, if applicable
|
|
264
|
+
if (table->numRows > 0) {
|
|
265
|
+
Local<Array> arr = Nan::New<Array>(table->numRows);
|
|
266
|
+
Local<Object> element;
|
|
267
|
+
for (uint32_t i = 0; i < table->numRows; i++) {
|
|
268
|
+
element = CreateMessageRow(&table->rows[i]);
|
|
269
|
+
Nan::Set(arr, i, element);
|
|
270
|
+
}
|
|
271
|
+
Nan::Set(tableObj, Nan::New<String>("rows").ToLocalChecked(), arr);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return scope.Escape(tableObj);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
//-----------------------------------------------------------------------------
|
|
279
|
+
// njsSubscription::Create()
|
|
280
|
+
// Create a new subscription object.
|
|
281
|
+
//-----------------------------------------------------------------------------
|
|
282
|
+
Local<Object> njsSubscription::Create()
|
|
283
|
+
{
|
|
284
|
+
Nan::EscapableHandleScope scope;
|
|
285
|
+
Local<Function> func = Nan::GetFunction(Nan::New<FunctionTemplate>(
|
|
286
|
+
subscriptionTemplate_s)).ToLocalChecked();
|
|
287
|
+
Local<Object> obj = Nan::NewInstance(func).ToLocalChecked();
|
|
288
|
+
return scope.Escape(obj);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
//-----------------------------------------------------------------------------
|
|
293
|
+
// njsSubscription::StartNotifications()
|
|
294
|
+
// Start sending notifications to the supplied callback. An async handle is
|
|
295
|
+
// created to ensure the event loop doesn't terminate until the subscription is
|
|
296
|
+
// deregistered in some way (either directly via unsubscribe() or indirectly
|
|
297
|
+
// via the timeout attribute or the quality of service flag that tells a
|
|
298
|
+
// subscription to deregister after the first notification has been received).
|
|
299
|
+
//-----------------------------------------------------------------------------
|
|
300
|
+
void njsSubscription::StartNotifications(njsBaton *baton)
|
|
301
|
+
{
|
|
302
|
+
if (this->name.empty()) {
|
|
303
|
+
this->name = baton->name;
|
|
304
|
+
uv_mutex_init(&this->mutex);
|
|
305
|
+
uv_async_init(uv_default_loop(), &this->async, ProcessNotification);
|
|
306
|
+
this->async.data = this;
|
|
307
|
+
this->dpiSubscrHandle = baton->dpiSubscrHandle;
|
|
308
|
+
baton->dpiSubscrHandle = NULL;
|
|
309
|
+
baton->subscription = NULL;
|
|
310
|
+
Local<Value> subscriptionObj = Nan::New(baton->jsSubscription);
|
|
311
|
+
njsOracledb::SetSubscription(baton->name, subscriptionObj);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
//-----------------------------------------------------------------------------
|
|
317
|
+
// njsSubscription::StopNotifications()
|
|
318
|
+
// Stop sending notifications to the supplied callback. This happens when the
|
|
319
|
+
// subscription is deregistered, either directly via a call to unsubscribe()
|
|
320
|
+
// or indirectly via the timeout attribute or the quality of service flag that
|
|
321
|
+
// tells a subscription to deregister after the first notification has been
|
|
322
|
+
// received.
|
|
323
|
+
//-----------------------------------------------------------------------------
|
|
324
|
+
void njsSubscription::StopNotifications()
|
|
325
|
+
{
|
|
326
|
+
uv_close(reinterpret_cast<uv_handle_t*>(&async), OnStopNotifications);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
//-----------------------------------------------------------------------------
|
|
331
|
+
// njsSubscription::OnStopNotifications()
|
|
332
|
+
// This method is called when the subscription is deregistered. It is called
|
|
333
|
+
// in the main thread and is used to perform any clean up that is necessary.
|
|
334
|
+
//-----------------------------------------------------------------------------
|
|
335
|
+
void njsSubscription::OnStopNotifications(uv_handle_t *handle)
|
|
336
|
+
{
|
|
337
|
+
Nan::HandleScope scope;
|
|
338
|
+
njsSubscription *subscription = (njsSubscription*) handle->data;
|
|
339
|
+
if (subscription->dpiSubscrHandle) {
|
|
340
|
+
dpiSubscr_release(subscription->dpiSubscrHandle);
|
|
341
|
+
subscription->dpiSubscrHandle = NULL;
|
|
342
|
+
}
|
|
343
|
+
uv_mutex_destroy(&subscription->mutex);
|
|
344
|
+
subscription->jsCallback.Reset();
|
|
345
|
+
njsOracledb::ClearSubscription(subscription->name);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
//-----------------------------------------------------------------------------
|
|
350
|
+
// njsSubscription::EventHandler()
|
|
351
|
+
// This method is called by the ODPI-C subscription every time an event is
|
|
352
|
+
// received and is called from outside the event loop in a thread that
|
|
353
|
+
// Javascript does not know anything about. Since multiple calls to
|
|
354
|
+
// uv_async_send() result in only one call to the posted callback, at least
|
|
355
|
+
// until after the callback has completed, a barrier is used. This barrier
|
|
356
|
+
// ensures that uv_async_send() isn't called again until after the message has
|
|
357
|
+
// been successfully processed by the event loop. Note as well that the
|
|
358
|
+
// presence of the OPDI-C subscription handle indicates the subscription is
|
|
359
|
+
// actually ready to receive notifications. There is a short period of time
|
|
360
|
+
// when the subscription is registered but not yet ready to receive
|
|
361
|
+
// notifications.
|
|
362
|
+
//-----------------------------------------------------------------------------
|
|
363
|
+
void njsSubscription::EventHandler(njsSubscription *subscription,
|
|
364
|
+
dpiSubscrMessage *incomingMessage)
|
|
365
|
+
{
|
|
366
|
+
if (subscription->dpiSubscrHandle) {
|
|
367
|
+
uv_mutex_lock(&subscription->mutex);
|
|
368
|
+
uv_barrier_init(&subscription->barrier, 2);
|
|
369
|
+
subscription->message = incomingMessage;
|
|
370
|
+
uv_async_send(&subscription->async);
|
|
371
|
+
subscription->WaitOnBarrier();
|
|
372
|
+
uv_mutex_unlock(&subscription->mutex);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
//-----------------------------------------------------------------------------
|
|
378
|
+
// njsSubscription::New()
|
|
379
|
+
// Create new object accesible from JS. This is always called from within
|
|
380
|
+
// njsSubscription::Create() and never from any external JS.
|
|
381
|
+
//-----------------------------------------------------------------------------
|
|
382
|
+
NAN_METHOD(njsSubscription::New)
|
|
383
|
+
{
|
|
384
|
+
njsSubscription *subscription = new njsSubscription();
|
|
385
|
+
subscription->Wrap(info.Holder());
|
|
386
|
+
info.GetReturnValue().Set(info.Holder());
|
|
387
|
+
}
|
|
388
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
|
|
2
|
+
|
|
3
|
+
/******************************************************************************
|
|
4
|
+
*
|
|
5
|
+
* You may not use the identified files except in compliance with the Apache
|
|
6
|
+
* License, Version 2.0 (the "License.")
|
|
7
|
+
*
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
13
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
*
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
* This file uses NAN:
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) 2015 NAN contributors
|
|
21
|
+
*
|
|
22
|
+
* NAN contributors listed at https://github.com/rvagg/nan#contributors
|
|
23
|
+
*
|
|
24
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
25
|
+
* a copy of this software and associated documentation files (the
|
|
26
|
+
* "Software"), to deal in the Software without restriction, including
|
|
27
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
28
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
29
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
30
|
+
* the following conditions:
|
|
31
|
+
*
|
|
32
|
+
* The above copyright notice and this permission notice shall be
|
|
33
|
+
* included in all copies or substantial portions of the Software.
|
|
34
|
+
*
|
|
35
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
36
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
37
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
38
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
39
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
40
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
41
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
42
|
+
*
|
|
43
|
+
* NAME
|
|
44
|
+
* njsSubscription.h
|
|
45
|
+
*
|
|
46
|
+
* DESCRIPTION
|
|
47
|
+
* Subscription class
|
|
48
|
+
*
|
|
49
|
+
*****************************************************************************/
|
|
50
|
+
|
|
51
|
+
#ifndef __NJSSUBSCRIPTION_H__
|
|
52
|
+
#define __NJSSUBSCRIPTION_H__
|
|
53
|
+
|
|
54
|
+
#include "njsCommon.h"
|
|
55
|
+
|
|
56
|
+
using namespace v8;
|
|
57
|
+
using namespace node;
|
|
58
|
+
|
|
59
|
+
//-----------------------------------------------------------------------------
|
|
60
|
+
// njsSubscription
|
|
61
|
+
// Class exposed to JS for handling subscriptions.
|
|
62
|
+
//-----------------------------------------------------------------------------
|
|
63
|
+
class njsSubscription: public njsCommon {
|
|
64
|
+
public:
|
|
65
|
+
|
|
66
|
+
static void Init(Local<Object> target);
|
|
67
|
+
bool IsValid() const { return true; };
|
|
68
|
+
njsErrorType GetInvalidErrorType() const { return errInvalidSubscription; }
|
|
69
|
+
static Local<Object> Create();
|
|
70
|
+
dpiSubscrNamespace GetNamespace() const { return subscrNamespace; }
|
|
71
|
+
void SetNamespace(dpiSubscrNamespace ns) { subscrNamespace = ns; }
|
|
72
|
+
void SetCallback(Local<Function> callback) { jsCallback.Reset(callback); }
|
|
73
|
+
void SetDPISubscrHandle(njsBaton *baton)
|
|
74
|
+
{ baton->SetDPISubscrHandle(dpiSubscrHandle); }
|
|
75
|
+
void StartNotifications(njsBaton *baton);
|
|
76
|
+
void StopNotifications();
|
|
77
|
+
|
|
78
|
+
// event handler
|
|
79
|
+
static void EventHandler(njsSubscription *subscription,
|
|
80
|
+
dpiSubscrMessage *message);
|
|
81
|
+
|
|
82
|
+
private:
|
|
83
|
+
|
|
84
|
+
njsSubscription() : dpiSubscrHandle(NULL), message(NULL) {}
|
|
85
|
+
~njsSubscription();
|
|
86
|
+
|
|
87
|
+
Local<Object> CreateMessage(dpiSubscrMessage *message);
|
|
88
|
+
Local<Object> CreateMessageQuery(dpiSubscrMessageQuery *query);
|
|
89
|
+
Local<Object> CreateMessageRow(dpiSubscrMessageRow *row);
|
|
90
|
+
Local<Object> CreateMessageTable(dpiSubscrMessageTable *table);
|
|
91
|
+
|
|
92
|
+
static void ProcessNotification(uv_async_t *handle);
|
|
93
|
+
static void OnStopNotifications(uv_handle_t *handle);
|
|
94
|
+
void WaitOnBarrier();
|
|
95
|
+
|
|
96
|
+
static NAN_METHOD(New);
|
|
97
|
+
|
|
98
|
+
dpiSubscr *dpiSubscrHandle;
|
|
99
|
+
uv_async_t async;
|
|
100
|
+
uv_mutex_t mutex;
|
|
101
|
+
uv_barrier_t barrier;
|
|
102
|
+
dpiSubscrMessage *message;
|
|
103
|
+
Nan::Persistent<Function> jsCallback;
|
|
104
|
+
dpiSubscrNamespace subscrNamespace;
|
|
105
|
+
std::string name;
|
|
106
|
+
|
|
107
|
+
static Nan::Persistent<FunctionTemplate> subscriptionTemplate_s;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
#endif
|
|
111
|
+
|