-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathjscrund_null.js
154 lines (128 loc) · 4.24 KB
/
jscrund_null.js
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
/*
Copyright (c) 2013, Oracle and/or its affiliates. All rights
reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
'use strict';
var jones = require("database-jones"),
ndb_bin_path = require("jones-ndb").config.binary,
ndb_adapter = require(ndb_bin_path),
os = require('os'),
udebug = unified_debug.getLogger('jscrund_null.js');
function implementation() {
var b = Buffer.alloc(4);
this.inBatchMode = false;
this.batch = null;
this.buffers = null;
this.properties = null;
this.debug_msg = "debug message ";
this.bounds_helper = [ b,1,true,b,1,false,0 ]; // Index Bounds Helper Spec
};
implementation.prototype = {
};
implementation.prototype.getConnectionProperties = function() {
return {
mysql_user : "root", // For CREATE TABLE
database : "test",
debug_messages : 0, // log_debug messages per operation
debug_message_length : 20, // length of debug messages
ndbapi_calls : 0, // NDB API calls per operation
system_calls : 0, // System calls per operation
new_buffers : 0, // Allocate node Buffers per operation
new_buffer_size : 32, // Size of allocation
};
};
implementation.prototype.close = function(callback) {
callback(null);
};
implementation.prototype.initialize = function(options, callback) {
var n;
jones.getDBServiceProvider("ndb"); // To call ndb_init()
this.properties = options.properties;
while(this.debug_msg.length < this.properties.debug_message_length) {
this.debug_msg += "x";
}
callback(null);
};
implementation.prototype.execOneOperation = function(callback, value) {
var b, n;
/* Debug Messages */
for(n = 0 ; n < this.properties.debug_messages ; n++) {
udebug.log(this.debug_msg);
}
/* NDBAPI calls */
/* Marshal/Unmarshal arguments and call into native code */
for(n = 0 ; n < this.properties.ndbapi_calls ; n++) {
ndb_adapter.impl.IndexBound.create(this.bounds_helper);
}
/* System calls */
for(n = 0 ; n < this.properties.system_calls ; n++) {
os.loadavg(); // calls sysctl() or sysinfo()
}
/* Buffers */
for(n = 0 ; n < this.properties.new_buffers ; n++) {
b = Buffer.alloc(this.properties.new_buffer_size);
if(this.inBatchMode) {
this.buffers.push(b);
}
}
/* Run operation or add it to batch */
if(this.inBatchMode) {
this.batch.push({ 'cb': callback, 'val': value });
}
else {
setImmediate(callback, null, value);
}
};
implementation.prototype.persist = function(parameters, callback) {
this.execOneOperation(callback);
};
implementation.prototype.find = function(parameters, callback) {
var object = {
id : parameters.key.id,
cint: parameters.key.id,
clong: parameters.key.id,
cfloat: parameters.key.id,
cdouble: parameters.key.id
}
this.execOneOperation(callback, object);
};
implementation.prototype.remove = function(parameters, callback) {
this.execOneOperation(callback);
};
implementation.prototype.createBatch = function(callback) {
this.batch = [];
this.buffers = [];
this.inBatchMode = true;
callback(null);
};
implementation.prototype.executeBatch = function(callback) {
var batch = this.batch;
function runOperations() {
var item;
while((item = batch.pop())) {
item.cb(null, item.val);
}
callback(null);
}
this.inBatchMode = false;
setImmediate(runOperations);
};
implementation.prototype.begin = function(callback) {
callback(null);
};
implementation.prototype.commit = function(callback) {
callback(null);
};
exports.implementation = implementation;