8000 Merge branch 'master' of https://github.com/arangodb/arangodb-java-dr… · anderick/arangodb-java-driver@0371287 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0371287

Browse files
committed
2 parents f8e39f9 + e8c6db1 commit 0371287

12 files changed

+267
-93
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 166 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,7 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

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.*;
6626
import com.arangodb.http.BatchHttpManager;
6727
import com.arangodb.http.BatchPart;
6828
import com.arangodb.http.HttpManager;
@@ -74,21 +34,16 @@
7434
import com.arangodb.util.ResultSetUtils;
7535

7636
/**
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
7838
* this class.
7939
*
8040
* @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.
8244
*/
8345
public class ArangoDriver extends BaseArangoDriver {
8446

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 { }
9247

9348
private ArangoConfigure configure;
9449
private BatchHttpManager httpManager;
@@ -98,9 +53,7 @@ public class ArangoDriver extends BaseArangoDriver {
9853
private InternalBatchDriverImpl batchDriver;
9954
private InternalCollectionDriver collectionDriver;
10055
private InternalDocumentDriver documentDriver;
101-
// private InternalKVSDriverImpl kvsDriver;
10256
private InternalIndexDriver indexDriver;
103-
// private InternalEdgeDriverImpl edgeDriver;
10457
private InternalAdminDriver adminDriver;
10558
private InternalJobsDriver jobsDriver;
10659
private InternalAqlFunctionsDriver aqlFunctionsDriver;
@@ -116,19 +69,21 @@ public class ArangoDriver extends BaseArangoDriver {
11669
private String database;
11770

11871
/**
119-
* Constructor
72+
* Constructor to create an instance of the driver that uses the
73+
* default database.
12074
*
121-
* @param configure
75+
* @param ArangoConfigure configure - A configuration object.
12276
*/
12377
public ArangoDriver(ArangoConfigure configure) {
12478
this(configure, null);
12579
}
12680

12781
/**
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.
13287
*/
13388
public ArangoDriver(ArangoConfigure configure, String database) {
13489

@@ -225,6 +180,18 @@ private void createModuleDrivers(boolean createProxys) {
225180
}
226181
}
227182

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+
*/
228195
public void startBatchMode() throws ArangoException {
229196
if (this.httpManager.isBatchModeActive()) {
230197
throw new ArangoException("BatchMode is already active.");
@@ -234,6 +201,19 @@ public void startBatchMode() throws ArangoException {
234201

235202
}
236203

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+
*/
237217
public void startAsyncMode(boolean fireAndForget) throws ArangoException {
238218
if (this.httpManager.getHttpMode().equals(HttpManager.HttpMode.ASYNC)
239219
|| this.httpManager.getHttpMode().equals(HttpManager.HttpMode.FIREANDFORGET)) {
@@ -245,6 +225,16 @@ public void startAsyncMode(boolean fireAndForget) throws ArangoException {
245225
this.httpManager.resetJobs();
246226
}
247227

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+
*/
248238
public void stopAsyncMode() throws ArangoException {
249239
if (this.httpManager.getHttpMode().equals(HttpManager.HttpMode.SYNC)) {
250240
throw new ArangoException("Arango driver already set to synchronous mode.");
@@ -253,39 +243,137 @@ public void stopAsyncMode() throws ArangoException {
253243
this.createModuleDrivers(false);
254244
}
255245

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+
*/
256257
public String getLastJobId() {
257258
return this.httpManager.getLastJobId();
258259
}
259260

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+
*/
260272
public List<String> getJobIds() {
261273
return this.httpManager.getJobIds();
262274
}
263275

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+
*/
264289
public List<String> getJobs(JobsEntity.JobState jobState, int count) throws ArangoException {
265290
return this.jobsDriver.getJobs(getDefaultDatabase(), jobState, count);
266291
}
267292

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+
*/
268305
public List<String> getJobs(JobsEntity.JobState jobState) throws ArangoException {
269306
return this.jobsDriver.getJobs(getDefaultDatabase(), jobState);
270307
}
271308

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+
*/
272319
public void deleteAllJobs() throws ArangoException {
273320
this.jobsDriver.deleteAllJobs(getDefaultDatabase());
274321
this.httpManager.resetJobs();
275322
}
276323

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+
*/
277335
public void deleteJobById(String JobId) throws ArangoException {
278336
this.jobsDriver.deleteJobById(getDefaultDatabase(), JobId);
279337
}
280338

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+
*/
281350
public void deleteExpiredJobs(int timeStamp) throws ArangoException {
282351
this.jobsDriver.deleteExpiredJobs(getDefaultDatabase(), timeStamp);
283352
}
284353

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+
*/
285366
public <T> T getJobResult(String jobId) throws ArangoException {
286367
return this.jobsDriver.getJobResult(getDefaultDatabase(), jobId);
287368
}
288369

370+
/**
371+
* This method sends all stacked requests as batch to ArangoDB.
372+
*
373+
* @see ArangoDriver#startBatchMode()
374+
* @see com.arangodb.ArangoDriver#cancelBatchMode()
375+
* @throws com.arangodb.ArangoException
376+
*/
289377
public DefaultEntity executeBatch() throws ArangoException {
290378
if (!this.httpManager.isBatchModeActive()) {
291379
throw new ArangoException("BatchMode is not active.");
@@ -296,6 +384,16 @@ public DefaultEntity executeBatch() throws ArangoException {
296384
return result;
297385
}
298386

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+
*/
299397
public <T> T getBatchResponseByRequestId(String requestId) throws ArangoException {
300398
BatchResponseEntity batchResponseEntity = this.batchDriver.getBatchResponseListEntity().getResponseFromRequestId(
301399
requestId);
@@ -312,6 +410,13 @@ public <T> T getBatchResponseByRequestId(String requestId) throws ArangoExceptio
312410
}
313411
}
314412

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+
*/
315420
public void cancelBatchMode() throws ArangoException {
316421
if (!this.httpManager.isBatchModeActive()) {
317422
throw new ArangoException("BatchMode is not active.");
@@ -2638,7 +2743,7 @@ public TransactionEntity createTransaction(String action) {
26382743
return this.transactionDriver.createTransaction(action);
26392744
};
26402745

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+
};
26442749
}

src/main/java/com/arangodb/InternalTransactionDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface InternalTransactionDriver extends BaseDriverInterface {
1616
TransactionEntity createTransaction (String action);
1717

1818

19-
<T> T executeTransaction(String database, TransactionEntity transactionEntity, Class clazz) throws ArangoException;
19+
TransactionResultEntity executeTransaction(String database, TransactionEntity transactionEntity) throws ArangoException;
2020

2121

2222
}

src/main/java/com/arangodb/entity/EntityDeserializers.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,37 @@ public SimpleByResultEntity deserialize(JsonElement json, Type typeOfT, JsonDese
921921

922922
}
923923

924+
public static class TransactionResultEntityDeserializer implements JsonDeserializer<TransactionResultEntity> {
925+
926+
@Override
927+
public TransactionResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
928+
throws JsonParseException {
929+
930+
if (json.isJsonNull()) {
931+
return null;
932+
}
933+
934+
JsonObject obj = json.getAsJsonObject();
935+
TransactionResultEntity entity = deserializeBaseParameter(obj, new TransactionResultEntity());
936+
937+
if (obj.has("result")) { // MEMO:
938+
if (obj.get("result") instanceof JsonObject) {
939+
entity.setResult((Object) obj.get("result"));
940+
} else if (obj.getAsJsonPrimitive("result").isBoolean()) {
941+
entity.setResult((Boolean) (obj.getAsJsonPrimitive("result").getAsBoolean()));
942+
} else if (obj.getAsJsonPrimitive("result").isNumber()) {
943+
entity.setResult(obj.getAsJsonPrimitive("result").getAsNumber());
944+
} else if (obj.getAsJsonPrimitive("result").isString()) {
945+
entity.setResult((String) (obj.getAsJsonPrimitive("result").getAsString()));
946+
}
947+
}
948+
949+
950+
return entity;
951+
}
952+
953+
}
954+
924955
public static class UserEntityDeserializer implements JsonDeserializer<UserEntity> {
925956

926957
@Override

0 commit comments

Comments
 (0)
0