1 /*
2 Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25
26 #include <NdbApi.hpp>
27
28 #include <node_buffer.h>
29
30 #include "adapter_global.h"
31 #include "js_wrapper_macros.h"
32 #include "JsWrapper.h"
33
34 using namespace v8;
35
36
37 enum {
38 BOUND_LOW_KEY = 0,
39 BOUND_LOW_KEY_COUNT,
40 BOUND_LOW_INCLUSIVE,
41 BOUND_HIGH_KEY,
42 BOUND_HIGH_KEY_COUNT,
43 BOUND_HIGH_INCLUSIVE,
44 BOUND_RANGE_NO
45 };
46
47 Envelope IndexBoundEnvelope("IndexBound");
48
debug_print_bound(NdbIndexScanOperation::IndexBound * bound)49 void debug_print_bound(NdbIndexScanOperation::IndexBound * bound) {
50 DEBUG_PRINT("Range %d: %s-%d-part-%s -> %d-part-%s-%s",
51 bound->range_no,
52 bound->low_inclusive ? "[inc" : "(exc",
53 bound->low_key_count,
54 bound->low_key ? "value" : "NULL",
55 bound->high_key_count,
56 bound->high_key ? "value" : "NULL",
57 bound->high_inclusive ? "inc]" : "exc)");
58 }
59
newIndexBound(const Arguments & args)60 void newIndexBound(const Arguments &args) {
61 EscapableHandleScope scope(args.GetIsolate());
62
63 NdbIndexScanOperation::IndexBound * bound =
64 new NdbIndexScanOperation::IndexBound;
65 Local<Value> jsBound = IndexBoundEnvelope.wrap(bound);
66
67 const Local<Object> spec = args[0]->ToObject();
68 Local<Value> v;
69 Local<Object> o;
70
71
72 bound->low_key = 0;
73 v = spec->Get(BOUND_LOW_KEY);
74 if(v->IsNull()) {
75 bound->low_key = 0;
76 } else {
77 o = v->ToObject();
78 bound->low_key = node::Buffer::Data(o);
79 }
80
81 bound->low_key_count = 0;
82 v = spec->Get(BOUND_LOW_KEY_COUNT);
83 if(! v->IsNull()) {
84 bound->low_key_count = v->Uint32Value();
85 }
86
87 bound->low_inclusive = false;
88 v = spec->Get(BOUND_LOW_INCLUSIVE);
89 if(! v->IsNull()) {
90 bound->low_inclusive = v->BooleanValue();
91 }
92
93 bound->high_key = 0;
94 v = spec->Get(BOUND_HIGH_KEY);
95 if(v->IsNull()) {
96 bound->high_key = 0;
97 } else {
98 o = v->ToObject();
99 bound->high_key = node::Buffer::Data(o);
100 }
101
102 bound->high_key_count = 0;
103 v = spec->Get(BOUND_HIGH_KEY_COUNT);
104 if(! v->IsNull()) {
105 bound->high_key_count = v->Uint32Value();
106 }
107
108 bound->high_inclusive = false;
109 v = spec->Get(BOUND_HIGH_INCLUSIVE);
110 if(! v->IsNull()) {
111 bound->high_inclusive = v->BooleanValue();
112 }
113
114 bound->range_no = 0;
115 v = spec->Get(BOUND_RANGE_NO);
116 if(! v->IsNull()) {
117 bound->range_no = v->Uint32Value();
118 }
119
120 debug_print_bound(bound);
121
122 args.GetReturnValue().Set(scope.Escape(jsBound));
123 }
124
125
126
IndexBound_initOnLoad(Handle<Object> target)127 void IndexBound_initOnLoad(Handle<Object> target) {
128 Local<Object> ibObj = Object::New(Isolate::GetCurrent());
129 Local<String> ibKey = NEW_SYMBOL("IndexBound");
130 target->Set(ibKey, ibObj);
131
132 DEFINE_JS_FUNCTION(ibObj, "create", newIndexBound);
133
134 Local<Object> BoundHelper = Object::New(Isolate::GetCurrent());
135 ibObj->Set(NEW_SYMBOL("helper"), BoundHelper);
136
137 DEFINE_JS_INT(BoundHelper, "low_key", BOUND_LOW_KEY);
138 DEFINE_JS_INT(BoundHelper, "low_key_count", BOUND_LOW_KEY_COUNT);
139 DEFINE_JS_INT(BoundHelper, "low_inclusive", BOUND_LOW_INCLUSIVE);
140 DEFINE_JS_INT(BoundHelper, "high_key", BOUND_HIGH_KEY);
141 DEFINE_JS_INT(BoundHelper, "high_key_count", BOUND_HIGH_KEY_COUNT);
142 DEFINE_JS_INT(BoundHelper, "high_inclusive", BOUND_HIGH_INCLUSIVE);
143 DEFINE_JS_INT(BoundHelper, "range_no", BOUND_RANGE_NO);
144 }
145
146