3131import com .arangodb .entity .LogEntity ;
3232import com .arangodb .entity .UserEntity ;
3333import com .arangodb .internal .ArangoDBConstants ;
34+ import com .arangodb .internal .InternalArangoDB ;
35+ import com .arangodb .internal .ArangoExecutor .ResponseDeserializer ;
36+ import com .arangodb .internal .ArangoExecutorSync ;
3437import com .arangodb .internal .CollectionCache ;
3538import com .arangodb .internal .CollectionCache .DBAccess ;
3639import com .arangodb .internal .DocumentCache ;
3740import com .arangodb .internal .velocypack .VPackConfigure ;
3841import 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 ;
4044import com .arangodb .model .LogOptions ;
41- import com .arangodb .model .OptionsBuilder ;
4245import com .arangodb .model .UserCreateOptions ;
4346import com .arangodb .model .UserUpdateOptions ;
44- import com .arangodb .velocypack .Type ;
4547import com .arangodb .velocypack .VPack ;
4648import com .arangodb .velocypack .VPackDeserializer ;
4749import com .arangodb .velocypack .VPackInstanceCreator ;
4850import com .arangodb .velocypack .VPackParser ;
4951import com .arangodb .velocypack .VPackSerializer ;
50- import com .arangodb .velocypack .VPackSlice ;
5152import com .arangodb .velocypack .exception .VPackException ;
5253import com .arangodb .velocystream .Request ;
53- import com .arangodb .velocystream .RequestType ;
5454import 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