-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathBatch
380 lines (357 loc) · 15.5 KB
/
Batch
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
/** Find a specific instance based on primary or unique key value.
* ASYNC
*
* The constructor parameter is the constructor function of a mapped domain
* object.
*
* The parameter "keys" may be of any type. Keys must uniquely identify
* a single row in the database.
* If keys is a simple type (number or string), then the parameter type must
* be the same type as or compatible with the primary key type of the mapped
* object.
* Otherwise, properties are taken from the parameter and matched against
* property names in the mapping. Primary key properties will be used if all
* are present, and other properties will be ignored.
* If keys cannot identify the primary key, property names corresponding to
* unique key columns will be used. If no complete primary or unique key
* properties are found, an error is reported.
*
* For multi-column primary or unique keys, all key fields must be set.
*
* The returned object will be loaded based on the mapping and the current
* values in the database.
*
* This function returns a promise. On success, the promise will be fulfilled
* with the found object. The optional callback receives an error value and the
* found object. Any extra arguments passed after the callback will
* be passed to the callback function verbatim as parameters following
* the found instance value.
*
* @method find
* @param constructor the constructor function of a mapped domain object
* @param keys the instance to find in the database
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* instance: the domain model object or null if not found
* @return promise
*/
find(Function constructor, Object keys, [callback], [...]);
/** Find a specific instance based on primary or unique key value.
* See other variant for semantics.
* ASYNC
*
* @method find
* @param tableName the table name
* @param keys the instance to find in the database
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* instance: the domain model object or null if not found
* @return promise
*/
find(String tableName, Object keys, [callback], [...]);
/** Load a specific instance by matching its primary or unique key with
* a database row. Load will never create a new domain object.
* ASYNC
*
* The parameter "instance" must have its primary or unique key value(s) set.
* The mapped values in the object will be loaded based on the current
* values in the database. Unmapped properties in the object will be unchanged.
*
* Primary key properties will be used if all are present,
* and all other properties will be ignored.
* Otherwise, property names corresponding to unique key columns
* will be used. If no complete primary or unique key properties
* are found, an error is reported.
*
* This function returns a promise. On success, the promise will be fulfilled
* with the loaded instance. The optional callback receives an error value and
* the loaded instance. Any extra arguments passed after the callback will
* be passed to the callback function verbatim as parameters following
* the loaded instance value.
*
* @method load
* @param instance the instance to load from the database
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* instance: the domain model object or null if not found
* @return promise
*/
load(Object instance, [callback], [...]);
/** Insert the instance into the database.
* ASYNC
*
* If the instance already exists in the database, an exception is
* reported in the callback.
*
* For autogenerated values, the values will be present in the instance
* when the callback is called.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param instance the instance to insert
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
*/
persist(Object instance, [callback], [...]);
/** Insert the instance into the database. See the other variant for semantics.
* ASYNC
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param constructor the constructor function for a mapped domain object
* @param values: values for the new instance
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
*/
persist(Function constructor, Object values, [callback], [...]);
/** Insert the instance into the database. See the other variant for semantics.
* ASYNC
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param tableName the table name
* @param values: values for the new instance
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
*/
persist(String tableName, Object values, [callback]. [...]);
/** Delete an instance of a class from the database by a primary or unique key.
* ASYNC
* The key values in the object must uniquely identify
* a single row in the database.
* If the instance does not exist in the database,
* an error is reported in the callback.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param the instance of a mapped domain object to delete from the database
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
*/
remove(Object instance, [callback], [...]);
/** Delete a row from the database by a unique or primary key.
* ASYNC
* The constructor parameter is the constructor function for a mapped domain
* object. If keys is a simple type (number or string), then the parameter type
* must be the same type as or compatible with the primary key type
* of the mapped object.
* Otherwise, properties are taken from the parameter and matched against
* property names in the mapping.
* If all Primary Key properties are present, they will be used,
* and other properties will be ignored.
* Otherwise, if keys cannot identify the primary key, property names
* corresponding to unique key columns will be used.
* If no complete primary or unique key properties are found, an error
* is reported.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param constructor the constructor for a mapped domain object
* @param keys object containing the keys of the object to delete
* @param callback function to be called when operation has completed, with parameters:
* err: the node.js Error object
* @return promise
*/
remove(Function constructor, Object keys, [callback], [...]);
/** Delete a row from the database by a unique or primary key.
* ASYNC
* See other variant for semantics.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param tableName the table name
* @param keys object containing the keys of the object to delete
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
*/
remove(String tableName, Object keys, [callback], [...]);
/** Update the instance in the database without necessarily retrieving it.
* The primary key field is used to determine which instance is to be updated.
* If the instance does not exist in the database, an error is reported.
* This method cannot be used to change the primary key.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param instance the instance to update
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
* ASYNC
*/
update(Object instance, [callback], [...]);
/** Update the instance in the database without necessarily retrieving it.
* Unique key field(s) of the keys object determine which instance
* is to be updated. The values object provides values to be updated.
* If the keys object contains all fields corresponding to the primary key,
* the primary key will identify the instance. If not, unique keys will be
* chosen non-deterministically.
* If the instance does not exist in the database, an error is reported.
* This method cannot be used to change the primary key.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param constructor constructor function of a mapped domain object
* @param keys an object containing unique keys for the instance to update
* @param values an object containing values to update
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
* ASYNC
*/
update(Function constructor, keys, values, [callback], [...]);
/** Update the instance in the database without necessarily retrieving it.
* See other variant for semantics.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param tableName the table name
* @param keys an object containing unique keys for the instance to update
* @param values an object containing values to update
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
* ASYNC
*/
update(String tableName, keys, values, [callback], [...]);
/** Save the instance in the database without checking for existence.
* The id field is used to determine which instance is to be saved.
* If the instance exists in the database it will be updated.
* If the instance does not exist, it will be created.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param instance the instance to insert or update
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
* ASYNC
*/
save(Object instance, [callback], [...]);
/** Save the instance in the database without checking for existence.
* See other variant for semantics.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param constructor the constructor function of a mapped domain object
* @param values the values to insert or update
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
* ASYNC
*/
save(Function constructor, Object values, [callback], [...]);
/** Save the instance in the database without checking for existence.
* See other variant for semantics.
*
* This function returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value. Any extra arguments
* passed after the callback will be passed to the callback function verbatim
* as parameters following the error value.
*
* @param tableName the name of the table
* @param values the values to insert or update
* @param callback function to be called when operation has completed,
* with parameters:
* err: the node.js Error object
* @return promise
* ASYNC
*/
save(String tableName, Object values, [callback], [...]);
/** Is this context a batch?
* @return true if this context is a batch; false if this context is a session
* IMMEDIATE
*/
isBatch();
/** How many operations are currently defined in this batch?
* @return number of operations in batch
* IMMEDIATE
*/
getOperationCount();
/** execute()
* ASYNC
* Execute this batch. All operations are executed and for each operation
* the callback for that operation is called (in no particular order).
* The execute function's callback is also called.
* The batch is executed in the context of the session's current state:
* autocommit if a transaction has not been started;
*
* execute() returns a promise. On success, the promise will be fulfilled.
* The optional callback receives only an error value and any extra arguments.
* Extra arguments passed after the callback will be passed to the callback
* function verbatim as parameters following the error.
*
* @method execute
* @param callback
* @return promise
*/
execute([callback], [...]);
/** clear()
* IMMEDIATE
* Clear this batch. The transaction state is unaffected.
* The batch is still valid, but all operations previously defined
* are removed, restoring the batch to a clean state.
* If operations are defined, the callback for each operation will be called
* with an error indicating that the batch has been cleared.
*/
clear();
/** getSession()
* IMMEDIATE
* Get the session from which this batch was created.
* @return the session
*/
getSession();
/*
* Users may find useful a "user" property of session and batch.
* The jones implementation will not ever define a property called "user".
*/