31
31
import com .arangodb .entity .LogEntity ;
32
32
import com .arangodb .entity .UserEntity ;
33
33
import com .arangodb .internal .ArangoDBConstants ;
34
+ import com .arangodb .internal .InternalArangoDB ;
35
+ import com .arangodb .internal .ArangoExecutor .ResponseDeserializer ;
36
+ import com .arangodb .internal .ArangoExecutorSync ;
34
37
import com .arangodb .internal .CollectionCache ;
35
38
import com .arangodb .internal .CollectionCache .DBAccess ;
36
39
import com .arangodb .internal .DocumentCache ;
37
40
import com .arangodb .internal .velocypack .VPackConfigure ;
38
41
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 ;
40
44
import com .arangodb .model .LogOptions ;
41
- import com .arangodb .model .OptionsBuilder ;
42
45
import com .arangodb .model .UserCreateOptions ;
43
46
import com .arangodb .model .UserUpdateOptions ;
44
- import com .arangodb .velocypack .Type ;
45
47
import com .arangodb .velocypack .VPack ;
46
48
import com .arangodb .velocypack .VPackDeserializer ;
47
49
import com .arangodb .velocypack .VPackInstanceCreator ;
48
50
import com .arangodb .velocypack .VPackParser ;
49
51
import com .arangodb .velocypack .VPackSerializer ;
50
- import com .arangodb .velocypack .VPackSlice ;
51
52
import com .arangodb .velocypack .exception .VPackException ;
52
53
import com .arangodb .velocystream .Request ;
53
- import com .arangodb .velocystream .RequestType ;
54
54
import com .arangodb .velocystream .Response ;
55
55
56
56
/**
57
57
* @author Mark - mark at arangodb.com
58
58
*
59
59
*/
60
- public class ArangoDB extends ArangoExecuteable {
60
+ public class ArangoDB extends InternalArangoDB < ArangoExecutorSync , Response , ConnectionSync > {
61
61
62
62
public static class Builder {
63
63
@@ -180,28 +180,33 @@ public <T> Builder regitserInstanceCreator(final Class<T> clazz, final VPackInst
180
180
181
181
public ArangoDB build () {
182
182
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 )
184
184
.useSsl (useSsl ).sslContext (sslContext ).chunksize (chunksize ),
185
185
vpackBuilder .build (), vpackBuilder .serializeNullValues (true ).build (), vpackParser , collectionCache );
186
186
}
187
187
188
188
}
189
189
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 ,
191
191
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 );
195
195
collectionCache .init (new DBAccess () {
196
196
@ Override
197
197
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 );
199
200
}
200
201
});
201
202
}
202
203
204
+ protected ArangoExecutorSync executor () {
205
+ return executor ;
206
+ }
207
+
203
208
public void shutdown () {
204
- communication .disconnect ();
209
+ executor . communication () .disconnect ();
205
210
}
206
211
207
212
public ArangoDatabase db () {
@@ -223,23 +228,7 @@ public ArangoDatabase db(final String name) {
223
228
* @throws ArangoDBException
224
229
*/
225
230
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 ());
243
232
}
244
233
245
234
/**
@@ -249,22 +238,7 @@ public Boolean deserialize(final Response response) throws VPackException {
249
238
* @throws ArangoDBException
250
239
*/
251
240
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 ());
268
242
}
269
243
270
244
/**
@@ -275,12 +249,7 @@ public Collection<String> deserialize(final Response response) throws VPackExcep
275
249
* @throws ArangoDBException
276
250
*/
277
251
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 ());
284
253
}
285
254
286
255
/**
@@ -292,11 +261,7 @@ private Request getAccessibleDatabasesRequest() {
292
261
* @throws ArangoDBException
293
262
*/
294
263
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 );
300
265
}
301
266
302
267
/**
@@ -312,7 +277,8 @@ private Request getVersionRequest() {
312
277
* @throws ArangoDBException
313
278
*/
314
279
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 );
316
282
}
317
283
318
284
/**
@@ -331,15 +297,7 @@ public UserEntity createUser(final String user, final String passwd) throws Aran
331
297
*/
332
298
public UserEntity createUser (final String user , final String passwd , final UserCreateOptions options )
333
299
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 );
343
301
}
344
302
345
303
/**
@@ -351,11 +309,7 @@ private Request createUserRequest(final String user, final String passwd, final
351
309
* @throws ArangoDBException
352
310
*/
353
311
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 );
359
313
}
360
314
361
315
/**
@@ -369,11 +323,7 @@ private Request deleteUserRequest(final String user) {
369
323
* @throws ArangoDBException
370
324
*/
371
325
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 );
377
327
}
378
328
379
329
/**
@@ -385,22 +335,7 @@ private Request getUserRequest(final String user) {
385
335
* @throws ArangoDBException
386
336
*/
387
337
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 ());
404
339
}
405
340
406
341
/**
@@ -416,14 +351,7 @@ public Collection<UserEntity> deserialize(final Response response) throws VPackE
416
351
* @throws ArangoDBException
417
352
*/
418
353
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 );
427
355
}
428
356
429
357
/**
@@ -440,18 +368,11 @@ private Request updateUserRequest(final String user, final UserUpdateOptions opt
440
368
* @throws ArangoDBException
441
369
*/
442
370
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 );
451
372
}
452
373
453
374
public Response execute (final Request request ) {
454
- return executeSync (request , new ResponseDeserializer <Response >() {
375
+ return executor . execute (request , new ResponseDeserializer <Response >() {
455
376
@ Override
456
377
public Response deserialize (final Response response ) throws VPackException {
457
378
return response ;
@@ -471,19 +392,7 @@ public Response deserialize(final Response response) throws VPackException {
471
392
* @throws ArangoDBException
472
393
*/
473
394
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 );
487
396
}
488
397
489
398
}
0 commit comments