Skip to content

Commit e251615

Browse files
author
Mark
committed
removed async
1 parent 2173301 commit e251615

26 files changed

+2125
-1558
lines changed

ChangeLog

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ v4.0.0 (2016-XX-XX)
33
* replaced API with new (inspired by arango shell)
44
* replaced protocol http with VelocyStream
55
* added VelocyPack support
6-
* added asynchronous support
76
* added multi document operations (insert, delete, update, replace)
87
* changed required Java version from 1.6 to 1.8
98

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ master: [![Build Status](https://secure.travis-ci.org/arangodb/arangodb-java-dri
1313

1414
<table>
1515
<tr><th>arangodb-java-driver</th><th>ArangoDB</th><th>network protocol</th><th>Java version</th></tr>
16-
<tr><td>4.0.x</td><td>3.1.x</td><td>VelocyStream</td><td>1.8</td></tr>
17-
<tr><td>3.1.x</td><td>3.1.x</td><td>HTTP</td><td>1.6</td></tr>
18-
<tr><td>3.0.x</td><td>3.0.x</td><td>HTTP</td><td>1.6</td></tr>
19-
<tr><td>2.7.4</td><td>2.7.x and 2.8.x</td><td>HTTP</td><td>1.6</td></tr>
16+
<tr><td>4.0.x</td><td>3.1.x</td><td>VelocyStream</td><td>1.6+</td></tr>
17+
<tr><td>3.1.x</td><td>3.1.x</td><td>HTTP</td><td>1.6+</td></tr>
18+
<tr><td>3.0.x</td><td>3.0.x</td><td>HTTP</td><td>1.6+</td></tr>
19+
<tr><td>2.7.4</td><td>2.7.x and 2.8.x</td><td>HTTP</td><td>1.6+</td></tr>
2020
</table>
2121

2222
## Maven

src/main/java/com/arangodb/ArangoCollection.java

Lines changed: 47 additions & 543 deletions
Large diffs are not rendered by default.

src/main/java/com/arangodb/ArangoCursor.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,38 @@
3131
import com.arangodb.entity.CursorEntity.Extras;
3232
import com.arangodb.entity.CursorEntity.Stats;
3333
import com.arangodb.entity.CursorEntity.Warning;
34-
import com.arangodb.internal.ArangoDBConstants;
35-
import com.arangodb.velocystream.Request;
36-
import com.arangodb.velocystream.RequestType;
34+
import com.arangodb.internal.ArangoCursorExecute;
35+
import com.arangodb.internal.ArangoCursorIterator;
36+
import com.arangodb.internal.InternalArangoDatabase;
3737

3838
/**
3939
* @author Mark - mark at arangodb.com
4040
*
4141
*/
4242
public class ArangoCursor<T> implements Iterator<T>, Closeable {
4343

44-
private final ArangoDatabase db;
4544
private final Class<T> type;
4645
private final ArangoCursorIterator<T> iterator;
4746
private final String id;
4847
private final Integer count;
4948
private final Extras extra;
5049
private final boolean cached;
50+
private final ArangoCursorExecute execute;
5151

52-
public ArangoCursor(final ArangoDatabase db, final Class<T> type, final CursorEntity result) {
52+
public ArangoCursor(final InternalArangoDatabase<?, ?, ?> db, final ArangoCursorExecute execute,
53+
final Class<T> type, final CursorEntity result) {
5354
super();
54-
this.db = db;
55+
this.execute = execute;
5556
this.type = type;
5657
count = result.getCount();
5758
extra = result.getExtra();
5859
cached = result.getCached().booleanValue();
59-
iterator = new ArangoCursorIterator<T>(this, result);
60+
iterator = new ArangoCursorIterator<T>(this, execute, db, result);
6061
id = result.getId();
6162
}
6263

63-
protected ArangoDatabase getDb() {
64-
return db;
64+
public String getId() {
65+
return id;
6566
}
6667

6768
public Class<T> getType() {
@@ -85,15 +86,12 @@ public boolean isCached() {
8586
}
8687

8788
protected CursorEntity executeNext() {
88-
return db.executeSync(
89-
new Request(db.name(), RequestType.PUT, db.createPath(ArangoDBConstants.PATH_API_CURSOR, id)),
90-
CursorEntity.class);
89+
return execute.next(id);
9190
}
9291

9392
@Override
9493
public void close() throws IOException {
95-
db.executeSync(new Request(db.name(), RequestType.DELETE, db.createPath(ArangoDBConstants.PATH_API_CURSOR, id)),
96-
Void.class);
94+
execute.close(id);
9795
}
9896

9997
@Override

src/main/java/com/arangodb/ArangoDB.java

Lines changed: 32 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@
3131
import com.arangodb.entity.LogEntity;
3232
import com.arangodb.entity.UserEntity;
3333
import com.arangodb.internal.ArangoDBConstants;
34+
import com.arangodb.internal.InternalArangoDB;
35+
import com.arangodb.internal.ArangoExecutor.ResponseDeserializer;
36+
import com.arangodb.internal.ArangoExecutorSync;
3437
import com.arangodb.internal.CollectionCache;
3538
import com.arangodb.internal.CollectionCache.DBAccess;
3639
import com.arangodb.internal.DocumentCache;
3740
import com.arangodb.internal.velocypack.VPackConfigure;
3841
import com.arangodb.internal.velocystream.Communication;
39-
import com.arangodb.model.DBCreateOptions;
42+
import com.arangodb.internal.velocystream.CommunicationSync;
43+
import com.arangodb.internal.velocystream.ConnectionSync;
4044
import com.arangodb.model.LogOptions;
41-
import com.arangodb.model.OptionsBuilder;
4245
import com.arangodb.model.UserCreateOptions;
4346
import com.arangodb.model.UserUpdateOptions;
44-
import com.arangodb.velocypack.Type;
4547
import com.arangodb.velocypack.VPack;
4648
import com.arangodb.velocypack.VPackDeserializer;
4749
import com.arangodb.velocypack.VPackInstanceCreator;
4850
import com.arangodb.velocypack.VPackParser;
4951
import com.arangodb.velocypack.VPackSerializer;
50-
import com.arangodb.velocypack.VPackSlice;
5152
import com.arangodb.velocypack.exception.VPackException;
5253
import com.arangodb.velocystream.Request;
53-
import com.arangodb.velocystream.RequestType;
5454
import com.arangodb.velocystream.Response;
5555

5656
/**
5757
* @author Mark - mark at arangodb.com
5858
*
5959
*/
60-
public class ArangoDB extends ArangoExecuteable {
60+
public class ArangoDB extends InternalArangoDB<ArangoExecutorSync, Response, ConnectionSync> {
6161

6262
public static class Builder {
6363

@@ -180,28 +180,33 @@ public <T> Builder regitserInstanceCreator(final Class<T> clazz, final VPackInst
180180

181181
public ArangoDB build() {
182182
return new ArangoDB(
183-
new Communication.Builder().host(host).port(port).timeout(timeout).user(user).password(password)
183+
new CommunicationSync.Builder().host(host).port(port).timeout(timeout).user(user).password(password)
184184
.useSsl(useSsl).sslContext(sslContext).chunksize(chunksize),
185185
vpackBuilder.build(), vpackBuilder.serializeNullValues(true).build(), vpackParser, collectionCache);
186186
}
187187

188188
}
189189

190-
public ArangoDB(final Communication.Builder commBuilder, final VPack vpack, final VPack vpackNull,
190+
public ArangoDB(final CommunicationSync.Builder commBuilder, final VPack vpack, final VPack vpackNull,
191191
final VPackParser vpackParser, final CollectionCache collectionCache) {
192-
super(commBuilder.build(vpack, collectionCache), vpack, vpackNull, vpackParser, new DocumentCache(),
193-
collectionCache);
194-
final Communication cacheCom = commBuilder.build(vpack, collectionCache);
192+
super(new ArangoExecutorSync(commBuilder.build(vpack, collectionCache), vpack, vpackNull, vpackParser,
193+
new DocumentCache(), collectionCache));
194+
final Communication<Response, ConnectionSync> cacheCom = commBuilder.build(vpack, collectionCache);
195195
collectionCache.init(new DBAccess() {
196196
@Override
197197
public ArangoDatabase db(final String name) {
198-
return new ArangoDatabase(cacheCom, vpackNull, vpack, vpackParser, documentCache, null, name);
198+
return new ArangoDatabase(cacheCom, vpackNull, vpack, vpackParser, executor.documentCache(), null,
199+
name);
199200
}
200201
});
201202
}
202203

204+
protected ArangoExecutorSync executor() {
205+
return executor;
206+
}
207+
203208
public void shutdown() {
204-
communication.disconnect();
209+
executor.communication().disconnect();
205210
}
206211

207212
public ArangoDatabase db() {
@@ -223,23 +228,7 @@ public ArangoDatabase db(final String name) {
223228
* @throws ArangoDBException
224229
*/
225230
public Boolean createDatabase(final String name) throws ArangoDBException {
226-
return executeSync(createDatabaseRequest(name), createDatabaseResponseDeserializer());
227-
}
228-
229-
private Request createDatabaseRequest(final String name) {
230-
final Request request = new Request(ArangoDBConstants.SYSTEM, RequestType.POST,
231-
ArangoDBConstants.PATH_API_DATABASE);
232-
request.setBody(serialize(OptionsBuilder.build(new DBCreateOptions(), name)));
233-
return request;
234-
}
235-
236-
private ResponseDeserializer<Boolean> createDatabaseResponseDeserializer() {
237-
return new ResponseDeserializer<Boolean>() {
238-
@Override
239-
public Boolean deserialize(final Response response) throws VPackException {
240-
return response.getBody().get(ArangoDBConstants.RESULT).getAsBoolean();
241-
}
242-
};
231+
return executor.execute(createDatabaseRequest(name), createDatabaseResponseDeserializer());
243232
}
244233

245234
/**
@@ -249,22 +238,7 @@ public Boolean deserialize(final Response response) throws VPackException {
249238
* @throws ArangoDBException
250239
*/
251240
public Collection<String> getDatabases() throws ArangoDBException {
252-
return executeSync(getDatabasesRequest(), getDatabaseResponseDeserializer());
253-
}
254-
255-
private Request getDatabasesRequest() {
256-
return new Request(db().name(), RequestType.GET, ArangoDBConstants.PATH_API_DATABASE);
257-
}
258-
259-
private ResponseDeserializer<Collection<String>> getDatabaseResponseDeserializer() {
260-
return new ResponseDeserializer<Collection<String>>() {
261-
@Override
262-
public Collection<String> deserialize(final Response response) throws VPackException {
263-
final VPackSlice result = response.getBody().get(ArangoDBConstants.RESULT);
264-
return ArangoDB.this.deserialize(result, new Type<Collection<String>>() {
265-
}.getType());
266-
}
267-
};
241+
return executor.execute(getDatabasesRequest(db().name()), getDatabaseResponseDeserializer());
268242
}
269243

270244
/**
@@ -275,12 +249,7 @@ public Collection<String> deserialize(final Response response) throws VPackExcep
275249
* @throws ArangoDBException
276250
*/
277251
public Collection<String> getAccessibleDatabases() throws ArangoDBException {
278-
return executeSync(getAccessibleDatabasesRequest(), getDatabaseResponseDeserializer());
279-
}
280-
281-
private Request getAccessibleDatabasesRequest() {
282-
return new Request(db().name(), RequestType.GET,
283-
createPath(ArangoDBConstants.PATH_API_DATABASE, ArangoDBConstants.USER));
252+
return executor.execute(getAccessibleDatabasesRequest(db().name()), getDatabaseResponseDeserializer());
284253
}
285254

286255
/**
@@ -292,11 +261,7 @@ private Request getAccessibleDatabasesRequest() {
292261
* @throws ArangoDBException
293262
*/
294263
public ArangoDBVersion getVersion() throws ArangoDBException {
295-
return executeSync(getVersionRequest(), ArangoDBVersion.class);
296-
}
297-
298-
private Request getVersionRequest() {
299-
return new Request(ArangoDBConstants.SYSTEM, RequestType.GET, ArangoDBConstants.PATH_API_VERSION);
264+
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
300265
}
301266

302267
/**
@@ -312,7 +277,8 @@ private Request getVersionRequest() {
312277
* @throws ArangoDBException
313278
*/
314279
public UserEntity createUser(final String user, final String passwd) throws ArangoDBException {
315-
return executeSync(createUserRequest(user, passwd, new UserCreateOptions()), UserEntity.class);
280+
return executor.execute(createUserRequest(db().name(), user, passwd, new UserCreateOptions()),
281+
UserEntity.class);
316282
}
317283

318284
/**
@@ -331,15 +297,7 @@ public UserEntity createUser(final String user, final String passwd) throws Aran
331297
*/
332298
public UserEntity createUser(final String user, final String passwd, final UserCreateOptions options)
333299
throws ArangoDBException {
334-
return executeSync(createUserRequest(user, passwd, options), UserEntity.class);
335-
}
336-
337-
private Request createUserRequest(final String user, final String passwd, final UserCreateOptions options) {
338-
final Request request;
339-
request = new Request(db().name(), RequestType.POST, ArangoDBConstants.PATH_API_USER);
340-
request.setBody(
341-
serialize(OptionsBuilder.build(options != null ? options : new UserCreateOptions(), user, passwd)));
342-
return request;
300+
return executor.execute(createUserRequest(db().name(), user, passwd, options), UserEntity.class);
343301
}
344302

345303
/**
@@ -351,11 +309,7 @@ private Request createUserRequest(final String user, final String passwd, final
351309
* @throws ArangoDBException
352310
*/
353311
public void deleteUser(final String user) throws ArangoDBException {
354-
executeSync(deleteUserRequest(user), Void.class);
355-
}
356-
357-
private Request deleteUserRequest(final String user) {
358-
return new Request(db().name(), RequestType.DELETE, createPath(ArangoDBConstants.PATH_API_USER, user));
312+
executor.execute(deleteUserRequest(db().name(), user), Void.class);
359313
}
360314

361315
/**
@@ -369,11 +323,7 @@ private Request deleteUserRequest(final String user) {
369323
* @throws ArangoDBException
370324
*/
371325
public UserEntity getUser(final String user) throws ArangoDBException {
372-
return executeSync(getUserRequest(user), UserEntity.class);
373-
}
374-
375-
private Request getUserRequest(final String user) {
376-
return new Request(db().name(), RequestType.GET, createPath(ArangoDBConstants.PATH_API_USER, user));
326+
return executor.execute(getUserRequest(db().name(), user), UserEntity.class);
377327
}
378328

379329
/**
@@ -385,22 +335,7 @@ private Request getUserRequest(final String user) {
385335
* @throws ArangoDBException
386336
*/
387337
public Collection<UserEntity> getUsers() throws ArangoDBException {
388-
return executeSync(getUsersRequest(), getUsersResponseDeserializer());
389-
}
390-
391-
private Request getUsersRequest() {
392-
return new Request(db().name(), RequestType.GET, ArangoDBConstants.PATH_API_USER);
393-
}
394-
395-
private ResponseDeserializer<Collection<UserEntity>> getUsersResponseDeserializer() {
396-
return new ResponseDeserializer<Collection<UserEntity>>() {
397-
@Override
398-
public Collection<UserEntity> deserialize(final Response response) throws VPackException {
399-
final VPackSlice result = response.getBody().get(ArangoDBConstants.RESULT);
400-
return ArangoDB.this.deserialize(result, new Type<Collection<UserEntity>>() {
401-
}.getType());
402-
}
403-
};
338+
return executor.execute(getUsersRequest(db().name()), getUsersResponseDeserializer());
404339
}
405340

406341
/**
@@ -416,14 +351,7 @@ public Collection<UserEntity> deserialize(final Response response) throws VPackE
416351
* @throws ArangoDBException
417352
*/
418353
public UserEntity updateUser(final String user, final UserUpdateOptions options) throws ArangoDBException {
419-
return executeSync(updateUserRequest(user, options), UserEntity.class);
420-
}
421-
422-
private Request updateUserRequest(final String user, final UserUpdateOptions options) {
423-
final Request request;
424-
request = new Request(db().name(), RequestType.PATCH, createPath(ArangoDBConstants.PATH_API_USER, user));
425-
request.setBody(serialize(options != null ? options : new UserUpdateOptions()));
426-
return request;
354+
return executor.execute(updateUserRequest(db().name(), user, options), UserEntity.class);
427355
}
428356

429357
/**
@@ -440,18 +368,11 @@ private Request updateUserRequest(final String user, final UserUpdateOptions opt
440368
* @throws ArangoDBException
441369
*/
442370
public UserEntity replaceUser(final String user, final UserUpdateOptions options) throws ArangoDBException {
443-
return executeSync(replaceUserRequest(user, options), UserEntity.class);
444-
}
445-
446-
private Request replaceUserRequest(final String user, final UserUpdateOptions options) {
447-
final Request request;
448-
request = new Request(db().name(), RequestType.PUT, createPath(ArangoDBConstants.PATH_API_USER, user));
449-
request.setBody(serialize(options != null ? options : new UserUpdateOptions()));
450-
return request;
371+
return executor.execute(replaceUserRequest(db().name(), user, options), UserEntity.class);
451372
}
452373

453374
public Response execute(final Request request) {
454-
return executeSync(request, new ResponseDeserializer<Response>() {
375+
return executor.execute(request, new ResponseDeserializer<Response>() {
455376
@Override
456377
public Response deserialize(final Response response) throws VPackException {
457378
return response;
@@ -471,19 +392,7 @@ public Response deserialize(final Response response) throws VPackException {
471392
* @throws ArangoDBException
472393
*/
473394
public LogEntity getLogs(final LogOptions options) throws ArangoDBException {
474-
return executeSync(getLogsRequest(options), LogEntity.class);
475-
}
476-
477-
private Request getLogsRequest(final LogOptions options) {
478-
final LogOptions params = options != null ? options : new LogOptions();
479-
return new Request(ArangoDBConstants.SYSTEM, RequestType.GET, ArangoDBConstants.PATH_API_ADMIN_LOG)
480-
.putQueryParam(LogOptions.PROPERTY_UPTO, params.getUpto())
481-
.putQueryParam(LogOptions.PROPERTY_LEVEL, params.getLevel())
482-
.putQueryParam(LogOptions.PROPERTY_START, params.getStart())
483-
.putQueryParam(LogOptions.PROPERTY_SIZE, params.getSize())
484-
.putQueryParam(LogOptions.PROPERTY_OFFSET, params.getOffset())
485-
.putQueryParam(LogOptions.PROPERTY_SEARCH, params.getSearch())
486-
.putQueryParam(LogOptions.PROPERTY_SORT, params.getSort());
395+
return executor.execute(getLogsRequest(options), LogEntity.class);
487396
}
488397

489398
}

0 commit comments

Comments
 (0)