22
22
import java .util .List ;
23
23
import java .util .Map ;
24
24
25
- import com .arangodb .entity .AdminLogEntity ;
26
- import com .arangodb .entity .AqlFunctionsEntity ;
27
- import com .arangodb .entity .ArangoUnixTime ;
28
- import com .arangodb .entity .ArangoVersion ;
29
- import com .arangodb .entity .BatchResponseEntity ;
30
- import com .arangodb .entity .BooleanResultEntity ;
31
- import com .arangodb .entity .CollectionEntity ;
32
- import com .arangodb .entity .CollectionOptions ;
33
- import com .arangodb .entity .CollectionsEntity ;
34
- import com .arangodb .entity .CursorEntity ;
35
- import com .arangodb .entity .DatabaseEntity ;
36
- import com .arangodb .entity .DefaultEntity ;
37
- import com .arangodb .entity .DeletedEntity ;
38
- import com .arangodb .entity .DocumentEntity ;
39
- import com .arangodb .entity .DocumentResultEntity ;
40
- import com .arangodb .entity .EdgeDefinitionEntity ;
41
- import com .arangodb .entity .EdgeEntity ;
42
- import com .arangodb .entity .Endpoint ;
43
- import com .arangodb .entity .GraphEntity ;
44
- import com .arangodb .entity .GraphsEntity ;
45
- import com .arangodb .entity .ImportResultEntity ;
46
- import com .arangodb .entity .IndexEntity ;
47
- import com .arangodb .entity .IndexType ;
48
- import com .arangodb .entity .IndexesEntity ;
49
- import com .arangodb .entity .JobsEntity ;
50
- import com .arangodb .entity .PlainEdgeEntity ;
51
- import com .arangodb .entity .Policy ;
52
- import com .arangodb .entity .ReplicationApplierConfigEntity ;
53
- import com .arangodb .entity .ReplicationApplierStateEntity ;
54
- import com .arangodb .entity .ReplicationInventoryEntity ;
55
- import com .arangodb .entity .ReplicationLoggerConfigEntity ;
56
- import com .arangodb .entity .ReplicationLoggerStateEntity ;
57
- import com .arangodb .entity .ReplicationSyncEntity ;
58
- import com .arangodb .entity .RestrictType ;
59
- import com .arangodb .entity .ScalarExampleEntity ;
60
- import com .arangodb .entity .SimpleByResultEntity ;
61
- import com .arangodb .entity .StatisticsDescriptionEntity ;
62
- import com .arangodb .entity .StatisticsEntity ;
63
- import com .arangodb .entity .StringsResultEntity ;
64
- import com .arangodb .entity .TransactionEntity ;
65
- import com .arangodb .entity .UserEntity ;
25
+ import com .arangodb .entity .*;
66
26
import com .arangodb .http .BatchHttpManager ;
67
27
import com .arangodb .http .BatchPart ;
68
28
import com .arangodb .http .HttpManager ;
74
34
import com .arangodb .util .ResultSetUtils ;
75
35
76
36
/**
77
- * ArangoDB driver. Most of the functionality to use ArangoDB is provided via
37
+ * ArangoDB driver. All of the functionality to use ArangoDB is provided via
78
38
* this class.
79
39
*
80
40
* @author tamtam180 - kirscheless at gmail.com
81
- * @author gschwab
41
+ * @author gschwab - g.schwab@triagens.de
42
+ * @author fbartels - f.bartels@triagens.de
43
+ * @version 2.2.
82
44
*/
83
45
public class ArangoDriver extends BaseArangoDriver {
84
46
85
- // TODO Cas Operation as eTAG
86
- // TODO Should fixed a Double check args.
87
- // TODO Null check httpResponse.
88
-
89
- // TODO コマンド式の実装に変更する。引数が増える度にメソッド数が爆発するのと、そうしないとバッチ処理も上手く書けないため。
90
- // driver.execute(createDocumentCommand)
91
- // class createDocumentCommand extends Command { }
92
47
93
48
private ArangoConfigure configure ;
94
49
private BatchHttpManager httpManager ;
@@ -98,9 +53,7 @@ public class ArangoDriver extends BaseArangoDriver {
98
53
private InternalBatchDriverImpl batchDriver ;
99
54
private InternalCollectionDriver collectionDriver ;
100
55
private InternalDocumentDriver documentDriver ;
101
- // private InternalKVSDriverImpl kvsDriver;
102
56
private InternalIndexDriver indexDriver ;
103
- // private InternalEdgeDriverImpl edgeDriver;
104
57
private InternalAdminDriver adminDriver ;
105
58
private InternalJobsDriver jobsDriver ;
106
59
private InternalAqlFunctionsDriver aqlFunctionsDriver ;
@@ -116,19 +69,21 @@ public class ArangoDriver extends BaseArangoDriver {
116
69
private String database ;
117
70
118
71
/**
119
- * Constructor
72
+ * Constructor to create an instance of the driver that uses the
73
+ * default database.
120
74
*
121
- * @param configure
75
+ * @param ArangoConfigure configure - A configuration object.
122
76
*/
123
77
public ArangoDriver (ArangoConfigure configure ) {
124
78
this (configure , null );
125
79
}
126
80
127
81
/**
128
- * Constructor
129
- *
130
- * @param configure
131
- * @param database
82
+ * Constructor to create an instance of the driver that uses the
83
+ * provided database.
84
+ *
85
+ * @param ArangoConfigure configure - A configuration object.
86
+ * @param String database - the database that will be used.
132
87
*/
133
88
public ArangoDriver (ArangoConfigure configure , String database ) {
134
89
@@ -225,6 +180,18 @@ private void createModuleDrivers(boolean createProxys) {
225
180
}
226
181
}
227
182
183
+
184
+ /**
185
+ * This method enables batch execution. Until 'cancelBatchMode' or 'executeBatch' is called
186
+ * every other call is stacked and will be either executed or discarded when the batch mode is canceled.
187
+ * Each call will return a 'requestId' in the http response, that can be used to select the matching result from the
188
+ * batch execution.
189
+ *
190
+ * @see com.arangodb.ArangoDriver#cancelBatchMode()
191
+ * @see ArangoDriver#executeBatch()
192
+ * @see ArangoDriver#getBatchResponseByRequestId(String)
193
+ * @throws com.arangodb.ArangoException
194
+ */
228
195
public void startBatchMode () throws ArangoException {
229
196
if (this .httpManager .isBatchModeActive ()) {
230
197
throw new ArangoException ("BatchMode is already active." );
@@ -234,6 +201,19 @@ public void startBatchMode() throws ArangoException {
234
201
235
202
}
236
203
204
+ /**
205
+ * This method sets the driver to asynchronous execution. If the parameter 'fireAndforget' is set to true
206
+ * each call to ArangoDB will be send without a return value. If set to false the return value will be the 'job id'.
207
+ * Each job result can be received by the method 'getJobResult'.
208
+ *
209
+ * @param boolean fireAndForget - if set to true the asynchronous mode is set to 'fire and forget'.
210
+ * @see ArangoDriver#stopAsyncMode()
211
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
212
+ * @see com.arangodb.ArangoDriver#getJobs(com.arangodb.entity.JobsEntity.JobState, int)
213
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
214
+ * @see ArangoDriver#getLastJobId()
215
+ * @throws com.arangodb.ArangoException
216
+ */
237
217
public void startAsyncMode (boolean fireAndForget ) throws ArangoException {
238
218
if (this .httpManager .getHttpMode ().equals (HttpManager .HttpMode .ASYNC )
239
219
|| this .httpManager .getHttpMode ().equals (HttpManager .HttpMode .FIREANDFORGET )) {
@@ -245,6 +225,16 @@ public void startAsyncMode(boolean fireAndForget) throws ArangoException {
245
225
this .httpManager .resetJobs ();
246
226
}
247
227
228
+ /**
229
+ * This method sets the driver back to synchronous execution.
230
+ *
231
+ * @see ArangoDriver#startAsyncMode(boolean)
232
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
233
+ * @see com.arangodb.ArangoDriver#getJobs(com.arangodb.entity.JobsEntity.JobState, int)
234
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
235
+ * @see ArangoDriver#getLastJobId()
236
+ * @throws com.arangodb.ArangoException
237
+ */
248
238
public void stopAsyncMode () throws ArangoException {
249
239
if (this .httpManager .getHttpMode ().equals (HttpManager .HttpMode .SYNC )) {
250
240
throw new ArangoException ("Arango driver already set to synchronous mode." );
@@ -253,39 +243,137 @@ public void stopAsyncMode() throws ArangoException {
253
243
this .createModuleDrivers (false );
254
244
}
255
245
246
+ /**
247
+ * Returns the id of the last asynchronous executed job.
248
+ *
249
+ * @return String
250
+ * @see ArangoDriver#startAsyncMode(boolean)
251
+ * @see ArangoDriver#stopAsyncMode()
252
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
253
+ * @see com.arangodb.ArangoDriver#getJobs(com.arangodb.entity.JobsEntity.JobState, int)
254
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
255
+ * @see ArangoDriver#getLastJobId()
256
+ */
256
257
public String getLastJobId () {
257
258
return this .httpManager .getLastJobId ();
258
259
}
259
260
261
+ /**
262
+ * Returns a list of all job ids of asynchronous executed jobs.
263
+ *
264
+ * @return List<String>
265
+ * @see ArangoDriver#startAsyncMode(boolean)
266
+ * @see ArangoDriver#stopAsyncMode()
267
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
268
+ * @see com.arangodb.ArangoDriver#getJobs(com.arangodb.entity.JobsEntity.JobState, int)
269
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
270
+ * @see ArangoDriver#getLastJobId()
271
+ */
260
272
public List <String > getJobIds () {
261
273
return this .httpManager .getJobIds ();
262
274
}
263
275
276
+ /**
277
+ * Returns a list of all job ids of asynchronous executed jobs, filtered by job state.
278
+ *
279
+ * @param JobsEntity.JobState jobState - the job state as a filter.
280
+ * @param int count - a limit for the result set.
281
+ * @return List<String>
282
+ * @see ArangoDriver#startAsyncMode(boolean)
283
+ * @see ArangoDriver#stopAsyncMode()
284
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
285
+ * @see com.arangodb.ArangoDriver#getJobIds()
286
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
287
+ * @see ArangoDriver#getLastJobId()
288
+ */
264
289
public List <String > getJobs (JobsEntity .JobState jobState , int count ) throws ArangoException {
265
290
return this .jobsDriver .getJobs (getDefaultDatabase (), jobState , count );
266
291
}
267
292
293
+ /**
294
+ * Returns a list of all job ids of asynchronous executed jobs, filtered by job state.
295
+ *
296
+ * @param JobsEntity.JobState jobState - the job state as a filter.
297
+ * @return List<String>
298
+ * @see ArangoDriver#startAsyncMode(boolean)
299
+ * @see ArangoDriver#stopAsyncMode()
300
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
301
+ * @see com.arangodb.ArangoDriver#getJobIds()
302
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
303
+ * @see ArangoDriver#getLastJobId()
304
+ */
268
305
public List <String > getJobs (JobsEntity .JobState jobState ) throws ArangoException {
269
306
return this .jobsDriver .getJobs (getDefaultDatabase (), jobState );
270
307
}
271
308
309
+ /**
310
+ * Deletes all job from ArangoDB.
311
+ *
312
+ * @see ArangoDriver#startAsyncMode(boolean)
313
+ * @see ArangoDriver#stopAsyncMode()
314
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
315
+ * @see com.arangodb.ArangoDriver#getJobIds()
316
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
317
+ * @see ArangoDriver#getLastJobId()
318
+ */
272
319
public void deleteAllJobs () throws ArangoException {
273
320
this .jobsDriver .deleteAllJobs (getDefaultDatabase ());
274
321
this .httpManager .resetJobs ();
275
322
}
276
323
324
+ /**
325
+ * Deletes a job from ArangoDB.
326
+ *
327
+ * @param String jobId - the id of the job
328
+ * @see ArangoDriver#startAsyncMode(boolean)
329
+ * @see ArangoDriver#stopAsyncMode()
330
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
331
+ * @see com.arangodb.ArangoDriver#getJobIds()
332
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
333
+ * @see ArangoDriver#getLastJobId()
334
+ */
277
335
public void deleteJobById (String JobId ) throws ArangoException {
278
336
this .jobsDriver .deleteJobById (getDefaultDatabase (), JobId );
279
337
}
280
338
339
+ /**
340
+ * Deletes all jobs by a provided expiration date.
341
+ *
342
+ * @param int timeStamp - a unix timestamp, every older job is deleted.
343
+ * @see ArangoDriver#startAsyncMode(boolean)
344
+ * @see ArangoDriver#stopAsyncMode()
345
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
346
+ * @see com.arangodb.ArangoDriver#getJobIds()
347
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
348
+ * @see ArangoDriver#getLastJobId()
349
+ */
281
350
public void deleteExpiredJobs (int timeStamp ) throws ArangoException {
282
351
this .jobsDriver .deleteExpiredJobs (getDefaultDatabase (), timeStamp );
283
352
}
284
353
354
+ /**
355
+ * Returns the job result for a given job id.
356
+ *
357
+ * @param String jobId - the job id.
358
+ * @return <T> - A generic return value, containing the job result
359
+ * @see ArangoDriver#startAsyncMode(boolean)
360
+ * @see ArangoDriver#stopAsyncMode()
361
+ * @see com.arangodb.ArangoDriver#getJobResult(String)
362
+ * @see com.arangodb.ArangoDriver#getJobIds()
363
+ * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int)
364
+ * @see ArangoDriver#getLastJobId()
365
+ */
285
366
public <T > T getJobResult (String jobId ) throws ArangoException {
286
367
return this .jobsDriver .getJobResult (getDefaultDatabase (), jobId );
287
368
}
288
369
370
+ /**
371
+ * This method sends all stacked requests as batch to ArangoDB.
372
+ *
373
+ * @see ArangoDriver#startBatchMode()
374
+ * @see com.arangodb.ArangoDriver#cancelBatchMode()
10000
span>
375
+ * @throws com.arangodb.ArangoException
376
+ */
289
377
public DefaultEntity executeBatch () throws ArangoException {
290
378
if (!this .httpManager .isBatchModeActive ()) {
291
379
throw new ArangoException ("BatchMode is not active." );
@@ -296,6 +384,16 @@ public DefaultEntity executeBatch() throws ArangoException {
296
384
return result ;
297
385
}
298
386
387
+ /**
388
+ * This method returns the result of a call to ArangoDB executed within a batch request.
389
+ *
390
+ * @param String requestId - the id of a request.
391
+ * @return <T> - A generic return value, containing the result.
392
+ * @see ArangoDriver#startBatchMode()
393
+ * @see ArangoDriver#executeBatch()
394
+ * @see com.arangodb.ArangoDriver#cancelBatchMode()
395
+ * @throws com.arangodb.ArangoException
396
+ */
299
397
public <T > T getBatchResponseByRequestId (String requestId ) throws ArangoException {
300
398
BatchResponseEntity batchResponseEntity = this .batchDriver .getBatchResponseListEntity ().getResponseFromRequestId (
301
399
requestId );
@@ -312,6 +410,13 @@ public <T> T getBatchResponseByRequestId(String requestId) throws ArangoExceptio
312
410
}
313
411
}
314
412
413
+ /**
414
+ * This method cancels the batch execution mode. All stacked calls are discarded.
415
+ *
416
+ * @see ArangoDriver#startBatchMode()
417
+ * @see ArangoDriver#executeBatch()
418
+ * @throws com.arangodb.ArangoException
419
+ */
315
420
public void cancelBatchMode () throws ArangoException {
316
421
if (!this .httpManager .isBatchModeActive ()) {
317
422
throw new ArangoException ("BatchMode is not active." );
@@ -2638,7 +2743,7 @@ public TransactionEntity createTransaction(String action) {
2638
2743
return this .transactionDriver .createTransaction (action );
2639
2744
};
2640
2745
2641
- public < T > T executeTransaction (TransactionEntity transactionEntity , Class < T > clazz ) throws ArangoException {
2642
- return this .transactionDriver .executeTransaction (getDefaultDatabase (), transactionEntity , clazz );
2643
- }
2746
+ public TransactionResultEntity executeTransaction (TransactionEntity transactionEntity ) throws ArangoException {
2747
+ return this .transactionDriver .executeTransaction (getDefaultDatabase (), transactionEntity );
2748
+ };
2644
2749
}
0 commit comments