|
37 | 37 | import com.arangodb.entity.GraphEntity; |
38 | 38 | import com.arangodb.entity.IndexEntity; |
39 | 39 | import com.arangodb.entity.PathEntity; |
| 40 | +import com.arangodb.entity.QueryCachePropertiesEntity; |
40 | 41 | import com.arangodb.entity.TraversalEntity; |
41 | 42 | import com.arangodb.internal.ArangoDBConstants; |
42 | 43 | import com.arangodb.internal.CollectionCache; |
@@ -157,11 +158,8 @@ public CompletableFuture<CollectionEntity> createCollectionAsync( |
157 | 158 | } |
158 | 159 |
|
159 | 160 | private Request createCollectionRequest(final String name, final CollectionCreateOptions options) { |
160 | | - final Request request; |
161 | | - request = new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION); |
162 | | - request.setBody( |
| 161 | + return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION).setBody( |
163 | 162 | serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name))); |
164 | | - return request; |
165 | 163 | } |
166 | 164 |
|
167 | 165 | /** |
@@ -353,11 +351,9 @@ public CompletableFuture<Void> grantAccessAync(final String user) { |
353 | 351 | } |
354 | 352 |
|
355 | 353 | private Request grantAccessRequest(final String user) { |
356 | | - final Request request; |
357 | | - request = new Request(ArangoDBConstants.SYSTEM, RequestType.PUT, |
358 | | - createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name)); |
359 | | - request.setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.RW))); |
360 | | - return request; |
| 354 | + return new Request(ArangoDBConstants.SYSTEM, RequestType.PUT, |
| 355 | + createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name)) |
| 356 | + .setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.RW))); |
361 | 357 | } |
362 | 358 |
|
363 | 359 | /** |
@@ -389,11 +385,9 @@ public CompletableFuture<Void> revokeAccessAsync(final String user) { |
389 | 385 | } |
390 | 386 |
|
391 | 387 | private Request revokeAccessRequest(final String user) { |
392 | | - final Request request; |
393 | | - request = new Request(ArangoDBConstants.SYSTEM, RequestType.PUT, |
394 | | - createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name)); |
395 | | - request.setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.NONE))); |
396 | | - return request; |
| 388 | + return new Request(ArangoDBConstants.SYSTEM, RequestType.PUT, |
| 389 | + createPath(ArangoDBConstants.PATH_API_USER, user, ArangoDBConstants.DATABASE, name)) |
| 390 | + .setBody(serialize(OptionsBuilder.build(new UserAccessOptions(), ArangoDBConstants.NONE))); |
397 | 391 | } |
398 | 392 |
|
399 | 393 | /** |
@@ -440,8 +434,7 @@ public <T> CompletableFuture<ArangoCursor<T>> queryAsync( |
440 | 434 | final Map<String, Object> bindVars, |
441 | 435 | final AqlQueryOptions options, |
442 | 436 | final Class<T> type) throws ArangoDBException { |
443 | | - final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_CURSOR); |
444 | | - request.setBody( |
| 437 | + final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_CURSOR).setBody( |
445 | 438 | serialize(OptionsBuilder.build(options != null ? options : new AqlQueryOptions(), query, bindVars))); |
446 | 439 | final CompletableFuture<CursorEntity> execution = executeAsync(request, CursorEntity.class); |
447 | 440 | return execution.thenApply(result -> { |
@@ -494,10 +487,8 @@ private Request explainQueryRequest( |
494 | 487 | final String query, |
495 | 488 | final Map<String, Object> bindVars, |
496 | 489 | final AqlQueryExplainOptions options) { |
497 | | - final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_EXPLAIN); |
498 | | - request.setBody( |
| 490 | + return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_EXPLAIN).setBody( |
499 | 491 | serialize(OptionsBuilder.build(options != null ? options : new AqlQueryExplainOptions(), query, bindVars))); |
500 | | - return request; |
501 | 492 | } |
502 | 493 |
|
503 | 494 | /** |
@@ -530,9 +521,103 @@ public CompletableFuture<AqlParseEntity> parseQueryAsync(final String query) { |
530 | 521 | } |
531 | 522 |
|
532 | 523 | private Request parseQueryRequest(final String query) { |
533 | | - final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_QUERY); |
534 | | - request.setBody(serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); |
535 | | - return request; |
| 524 | + return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_QUERY) |
| 525 | + .setBody(serialize(OptionsBuilder.build(new AqlQueryParseOptions(), query))); |
| 526 | + } |
| 527 | + |
| 528 | + /** |
| 529 | + * Clears the AQL query cache |
| 530 | + * |
| 531 | + * @see <a href= |
| 532 | + * "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#clears-any-results-in-the-aql-query-cache">API |
| 533 | + * Documentation</a> |
| 534 | + * @throws ArangoDBException |
| 535 | + */ |
| 536 | + public void clearQueryCache() throws ArangoDBException { |
| 537 | + executeSync(clearQueryCacheRequest(), Void.class); |
| 538 | + } |
| 539 | + |
| 540 | + /** |
| 541 | + * Clears the AQL query cache |
| 542 | + * |
| 543 | + * @see <a href= |
| 544 | + * "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#clears-any-results-in-the-aql-query-cache">API |
| 545 | + * Documentation</a> |
| 546 | + * @return void |
| 547 | + */ |
| 548 | + public CompletableFuture<Void> clearQueryCacheAsync() { |
| 549 | + return executeAsync(clearQueryCacheRequest(), Void.class); |
| 550 | + } |
| 551 | + |
| 552 | + private Request clearQueryCacheRequest() { |
| 553 | + return new Request(name, RequestType.DELETE, ArangoDBConstants.PATH_API_QUERY_CACHE); |
| 554 | + } |
| 555 | + |
| 556 | + /** |
| 557 | + * Returns the global configuration for the AQL query cache |
| 558 | + * |
| 559 | + * @see <a href= |
| 560 | + * "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#returns-the-global-properties-for-the-aql-query-cache">API |
| 561 | + * Documentation</a> |
| 562 | + * @return configuration for the AQL query cache |
| 563 | + * @throws ArangoDBException |
| 564 | + */ |
| 565 | + public QueryCachePropertiesEntity getQueryCacheProperties() throws ArangoDBException { |
| 566 | + return executeSync(getQueryCachePropertiesRequest(), QueryCachePropertiesEntity.class); |
| 567 | + } |
| 568 | + |
| 569 | + /** |
| 570 | + * Returns the global configuration for the AQL query cache |
| 571 | + * |
| 572 | + * @see <a href= |
| 573 | + * "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#returns-the-global-properties-for-the-aql-query-cache">API |
| 574 | + * Documentation</a> |
| 575 | + * @return configuration for the AQL query cache |
| 576 | + */ |
| 577 | + public CompletableFuture<QueryCachePropertiesEntity> getQueryCachePropertiesAsync() { |
| 578 | + return executeAsync(getQueryCachePropertiesRequest(), QueryCachePropertiesEntity.class); |
| 579 | + } |
| 580 | + |
| 581 | + private Request getQueryCachePropertiesRequest() { |
| 582 | + return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_QUERY_CACHE_PROPERTIES); |
| 583 | + } |
| 584 | + |
| 585 | + /** |
| 586 | + * Changes the configuration for the AQL query cache. Note: changing the properties may invalidate all results in |
| 587 | + * the cache. |
| 588 | + * |
| 589 | + * @see <a href= |
| 590 | + * "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#globally-adjusts-the-aql-query-result-cache-properties">API |
| 591 | + * Documentation</a> |
| 592 | + * @param properties |
| 593 | + * properties to be set |
| 594 | + * @return current set of properties |
| 595 | + * @throws ArangoDBException |
| 596 | + */ |
| 597 | + public QueryCachePropertiesEntity setQueryCacheProperties(final QueryCachePropertiesEntity properties) |
| 598 | + throws ArangoDBException { |
| 599 | + return executeSync(setQueryCachePropertiesRequest(properties), QueryCachePropertiesEntity.class); |
| 600 | + } |
| 601 | + |
| 602 | + /** |
| 603 | + * Changes the configuration for the AQL query cache. Note: changing the properties may invalidate all results in |
| 604 | + * the cache. |
| 605 | + * |
| 606 | + * @see <a href= |
| 607 | + * "https://docs.arangodb.com/current/HTTP/AqlQueryCache/index.html#globally-adjusts-the-aql-query-result-cache-properties">API |
| 608 | + * Documentation</a> |
| 609 | + * @param properties |
| 610 | + * properties to be set |
| 611 | + * @return current set of properties |
| 612 | + */ |
| 613 | + public CompletableFuture<QueryCachePropertiesEntity> setQueryCachePropertiesAsync( |
| 614 | + final QueryCachePropertiesEntity properties) { |
| 615 | + return executeAsync(setQueryCachePropertiesRequest(properties), QueryCachePropertiesEntity.class); |
| 616 | + } |
| 617 | + |
| 618 | + private Request setQueryCachePropertiesRequest(final QueryCachePropertiesEntity properties) { |
| 619 | + return new Request(name, RequestType.PUT, ArangoDBConstants.PATH_API_QUERY_CACHE_PROPERTIES) |
| 620 | + .setBody(serialize(properties)); |
536 | 621 | } |
537 | 622 |
|
538 | 623 | /** |
@@ -578,10 +663,8 @@ private Request createAqlFunctionRequest( |
578 | 663 | final String name, |
579 | 664 | final String code, |
580 | 665 | final AqlFunctionCreateOptions options) { |
581 | | - final Request request = new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_AQLFUNCTION); |
582 | | - request.setBody( |
| 666 | + return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_AQLFUNCTION).setBody( |
583 | 667 | serialize(OptionsBuilder.build(options != null ? options : new AqlFunctionCreateOptions(), name, code))); |
584 | | - return request; |
585 | 668 | } |
586 | 669 |
|
587 | 670 | /** |
@@ -751,11 +834,8 @@ private Request createGraphRequest( |
751 | 834 | final String name, |
752 | 835 | final Collection<EdgeDefinition> edgeDefinitions, |
753 | 836 | final GraphCreateOptions options) { |
754 | | - final Request request; |
755 | | - request = new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_GHARIAL); |
756 | | - request.setBody(serialize( |
| 837 | + return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_GHARIAL).setBody(serialize( |
757 | 838 | OptionsBuilder.build(options != null ? options : new GraphCreateOptions(), name, edgeDefinitions))); |
758 | | - return request; |
759 | 839 | } |
760 | 840 |
|
761 | 841 | private ResponseDeserializer<GraphEntity> createGraphResponseDeserializer() { |
@@ -835,10 +915,8 @@ public <T> CompletableFuture<T> transactionAsync( |
835 | 915 | } |
836 | 916 |
|
837 | 917 | private Request transactionRequest(final String action, final TransactionOptions options) { |
838 | | - final Request request; |
839 | | - request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRANSACTION); |
840 | | - request.setBody(serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); |
841 | | - return request; |
| 918 | + return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRANSACTION) |
| 919 | + .setBody(serialize(OptionsBuilder.build(options != null ? options : new TransactionOptions(), action))); |
842 | 920 | } |
843 | 921 |
|
844 | 922 | private <T> ResponseDeserializer<T> transactionResponseDeserializer(final Class<T> type) { |
@@ -932,9 +1010,8 @@ public <V, E> CompletableFuture<TraversalEntity<V, E>> executeTraversalAsync( |
932 | 1010 | } |
933 | 1011 |
|
934 | 1012 | private Request executeTraversalRequest(final TraversalOptions options) { |
935 | | - final Request request = new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRAVERSAL); |
936 | | - request.setBody(serialize(options != null ? options : new TransactionOptions())); |
937 | | - return request; |
| 1013 | + return new Request(name, RequestType.POST, ArangoDBConstants.PATH_API_TRAVERSAL) |
| 1014 | + .setBody(serialize(options != null ? options : new TransactionOptions())); |
938 | 1015 | } |
939 | 1016 |
|
940 | 1017 | private <E, V> ResponseDeserializer<TraversalEntity<V, E>> executeTraversalResponseDeserializer( |
|
0 commit comments