Skip to content

Commit 65cc2a5

Browse files
MarkMark
authored andcommitted
added convenience methods (ArangoDatabase.arango(), ArangoCollection.db(), ArangoGraph.db())
1 parent e363284 commit 65cc2a5

14 files changed

+135
-106
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v4.1.11 (2017-03-xx)
2+
---------------------------
3+
* added convenience methods (ArangoDatabase.arango(), ArangoCollection.db(), ArangoGraph.db())
4+
15
v4.1.10 (2017-02-22)
26
---------------------------
37
* changed velocystream message sending to async

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@
5656
* @author Mark - mark at arangodb.com
5757
*
5858
*/
59-
public class ArangoCollection extends InternalArangoCollection<ArangoExecutorSync, Response, ConnectionSync> {
59+
public class ArangoCollection
60+
extends InternalArangoCollection<ArangoDB, ArangoDatabase, ArangoExecutorSync, Response, ConnectionSync> {
6061

6162
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoCollection.class);
6263

6364
protected ArangoCollection(final ArangoDatabase db, final String name) {
64-
super(db.executor(), db.name(), name);
65+
super(db, name);
6566
}
6667

6768
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class ArangoCursor<T> implements Iterator<T>, Closeable {
4949
private final boolean cached;
5050
private final ArangoCursorExecute execute;
5151

52-
protected ArangoCursor(final InternalArangoDatabase<?, ?, ?> db, final ArangoCursorExecute execute,
52+
protected ArangoCursor(final InternalArangoDatabase<?, ?, ?, ?> db, final ArangoCursorExecute execute,
5353
final Class<T> type, final CursorEntity result) {
5454
super();
5555
this.execute = execute;

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,17 @@
6464
* @author Mark - mark at arangodb.com
6565
*
6666
*/
67-
public class ArangoDatabase extends InternalArangoDatabase<ArangoExecutorSync, Response, ConnectionSync> {
67+
public class ArangoDatabase extends InternalArangoDatabase<ArangoDB, ArangoExecutorSync, Response, ConnectionSync> {
6868

6969
protected ArangoDatabase(final ArangoDB arangoDB, final String name) {
70-
super(arangoDB.executor(), name);
70+
super(arangoDB, arangoDB.executor(), name);
7171
}
7272

7373
protected ArangoDatabase(final Communication<Response, ConnectionSync> communication, final VPack vpacker,
7474
final VPack vpackerNull, final VPackParser vpackParser, final DocumentCache documentCache,
7575
final CollectionCache collectionCache, final String name) {
76-
super(new ArangoExecutorSync(communication, vpacker, vpackerNull, vpackParser, documentCache, collectionCache),
77-
name);
78-
}
79-
80-
protected ArangoExecutorSync executor() {
81-
return executor;
76+
super(null, new ArangoExecutorSync(communication, vpacker, vpackerNull, vpackParser, documentCache,
77+
collectionCache), name);
8278
}
8379

8480
/**

src/main/java/com/arangodb/ArangoEdgeCollection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@
3939
* @author Mark - mark at arangodb.com
4040
*
4141
*/
42-
public class ArangoEdgeCollection extends InternalArangoEdgeCollection<ArangoExecutorSync, Response, ConnectionSync> {
42+
public class ArangoEdgeCollection extends
43+
InternalArangoEdgeCollection<ArangoDB, ArangoDatabase, ArangoGraph, ArangoExecutorSync, Response, ConnectionSync> {
4344

4445
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoEdgeCollection.class);
4546

4647
protected ArangoEdgeCollection(final ArangoGraph graph, final String name) {
47-
super(graph.executor(), graph.db(), graph.name(), name);
48+
super(graph, name);
4849
}
4950

5051
/**

src/main/java/com/arangodb/ArangoGraph.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,11 @@
3333
* @author Mark - mark at arangodb.com
3434
*
3535
*/
36-
public class ArangoGraph extends InternalArangoGraph<ArangoExecutorSync, Response, ConnectionSync> {
36+
public class ArangoGraph
37+
extends InternalArangoGraph<ArangoDB, ArangoDatabase, ArangoExecutorSync, Response, ConnectionSync> {
3738

3839
protected ArangoGraph(final ArangoDatabase db, final String name) {
39-
super(db.executor(), db.name(), name);
40-
}
41-
42-
protected ArangoExecutorSync executor() {
43-
return executor;
40+
super(db, name);
4441
}
4542

4643
/**

src/main/java/com/arangodb/ArangoVertexCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939
* @author Mark - mark at arangodb.com
4040
*
4141
*/
42-
public class ArangoVertexCollection
43-
extends InternalArangoVertexCollection<ArangoExecutorSync, Response, ConnectionSync> {
42+
public class ArangoVertexCollection extends
43+
InternalArangoVertexCollection<ArangoDB, ArangoDatabase, ArangoGraph, ArangoExecutorSync, Response, ConnectionSync> {
4444

4545
private static final Logger LOGGER = LoggerFactory.getLogger(ArangoVertexCollection.class);
4646

4747
protected ArangoVertexCollection(final ArangoGraph graph, final String name) {
48-
super(graph.executor(), graph.db(), graph.name(), name);
48+
super(graph, name);
4949
}
5050

5151
/**

src/main/java/com/arangodb/internal/ArangoCursorIterator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public class ArangoCursorIterator<T> implements Iterator<T> {
3737
private int pos;
3838

3939
private final ArangoCursor<T> cursor;
40-
private final InternalArangoDatabase<?, ?, ?> db;
40+
private final InternalArangoDatabase<?, ?, ?, ?> db;
4141
private final ArangoCursorExecute execute;
4242

4343
public ArangoCursorIterator(final ArangoCursor<T> cursor, final ArangoCursorExecute execute,
44-
final InternalArangoDatabase<?, ?, ?> db, final CursorEntity result) {
44+
final InternalArangoDatabase<?, ?, ?, ?> db, final CursorEntity result) {
4545
super();
4646
this.cursor = cursor;
4747
this.execute = execute;

src/main/java/com/arangodb/internal/ArangoExecuteable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public ArangoExecuteable(final E executor) {
3636
this.executor = executor;
3737
}
3838

39+
protected E executor() {
40+
return executor;
41+
}
42+
3943
public ArangoUtil util() {
4044
return executor.util();
4145
}

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,28 @@
6262
* @author Mark - mark at arangodb.com
6363
*
6464
*/
65-
public class InternalArangoCollection<E extends ArangoExecutor<R, C>, R, C extends Connection>
65+
public class InternalArangoCollection<A extends InternalArangoDB<E, R, C>, D extends InternalArangoDatabase<A, E, R, C>, E extends ArangoExecutor<R, C>, R, C extends Connection>
6666
extends ArangoExecuteable<E, R, C> {
6767

68+
private final D db;
6869
private final String name;
69-
private final String db;
7070

71-
public InternalArangoCollection(final E executor, final String db, final String name) {
72-
super(executor);
71+
public InternalArangoCollection(final D db, final String name) {
72+
super(db.executor());
7373
this.db = db;
7474
this.name = name;
7575
}
7676

77+
public D db() {
78+
return db;
79+
}
80+
7781
public String name() {
7882
return name;
7983
}
8084

8185
protected <T> Request insertDocumentRequest(final T value, final DocumentCreateOptions options) {
82-
final Request request = new Request(db, RequestType.POST,
86+
final Request request = new Request(db.name(), RequestType.POST,
8387
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
8488
final DocumentCreateOptions params = (options != null ? options : new DocumentCreateOptions());
8589
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
@@ -110,7 +114,7 @@ public DocumentCreateEntity<T> deserialize(final Response response) throws VPack
110114
}
111115

112116
protected <T> Request insertDocumentsRequest(final Collection<T> values, final DocumentCreateOptions params) {
113-
final Request request = new Request(db, RequestType.POST,
117+
final Request request = new Request(db.name(), RequestType.POST,
114118
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
115119
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
116120
request.putQueryParam(ArangoDBConstants.RETURN_NEW, params.getReturnNew());
@@ -168,7 +172,7 @@ protected Request importDocumentsRequest(final Collection<?> values, final Docum
168172

169173
protected Request importDocumentsRequest(final DocumentImportOptions options) {
170174
final DocumentImportOptions params = options != null ? options : new DocumentImportOptions();
171-
return new Request(db, RequestType.POST, ArangoDBConstants.PATH_API_IMPORT)
175+
return new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_IMPORT)
172176
.putQueryParam(ArangoDBConstants.COLLECTION, name)
173177
.putQueryParam(ArangoDBConstants.FROM_PREFIX, params.getFromPrefix())
174178
.putQueryParam(ArangoDBConstants.TO_PREFIX, params.getToPrefix())
@@ -180,7 +184,7 @@ protected Request importDocumentsRequest(final DocumentImportOptions options) {
180184
}
181185

182186
protected Request getDocumentRequest(final String key, final DocumentReadOptions options) {
183-
final Request request = new Request(db, RequestType.GET,
187+
final Request request = new Request(db.name(), RequestType.GET,
184188
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
185189
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
186190
request.putHeaderParam(ArangoDBConstants.IF_NONE_MATCH, params.getIfNoneMatch());
@@ -192,7 +196,7 @@ protected <T> Request replaceDocumentRequest(
192196
final String key,
193197
final T value,
194198
final DocumentReplaceOptions options) {
195-
final Request request = new Request(db, RequestType.PUT,
199+
final Request request = new Request(db.name(), RequestType.PUT,
196200
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
197201
final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions());
198202
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
@@ -229,7 +233,8 @@ public DocumentUpdateEntity<T> deserialize(final Response response) throws VPack
229233

230234
protected <T> Request replaceDocumentsRequest(final Collection<T> values, final DocumentReplaceOptions params) {
231235
final Request request;
232-
request = new Request(db, RequestType.PUT, executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
236+
request = new Request(db.name(), RequestType.PUT,
237+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
233238
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
234239
request.putQueryParam(ArangoDBConstants.IGNORE_REVS, params.getIgnoreRevs());
235240
request.putQueryParam(ArangoDBConstants.RETURN_NEW, params.getReturnNew());
@@ -284,7 +289,7 @@ public MultiDocumentEntity<DocumentUpdateEntity<T>> deserialize(final Response r
284289

285290
protected <T> Request updateDocumentRequest(final String key, final T value, final DocumentUpdateOptions options) {
286291
final Request request;
287-
request = new Request(db, RequestType.PATCH,
292+
request = new Request(db.name(), RequestType.PATCH,
288293
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
289294
final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions());
290295
request.putQueryParam(ArangoDBConstants.KEEP_NULL, params.getKeepNull());
@@ -320,7 +325,8 @@ public DocumentUpdateEntity<T> deserialize(final Response response) throws VPack
320325

321326
protected <T> Request updateDocumentsRequest(final Collection<T> values, final DocumentUpdateOptions params) {
322327
final Request request;
323-
request = new Request(db, RequestType.PATCH, executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
328+
request = new Request(db.name(), RequestType.PATCH,
329+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
324330
final Boolean keepNull = params.getKeepNull();
325331
request.putQueryParam(ArangoDBConstants.KEEP_NULL, keepNull);
326332
request.putQueryParam(ArangoDBConstants.MERGE_OBJECTS, params.getMergeObjects());
@@ -378,7 +384,7 @@ public MultiDocumentEntity<DocumentUpdateEntity<T>> deserialize(final Response r
378384

379385
protected Request deleteDocumentRequest(final String key, final DocumentDeleteOptions options) {
380386
final Request request;
381-
request = new Request(db, RequestType.DELETE,
387+
request = new Request(db.name(), RequestType.DELETE,
382388
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
383389
final DocumentDeleteOptions params = (options != null ? options : new DocumentDeleteOptions());
384390
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
@@ -406,7 +412,8 @@ public DocumentDeleteEntity<T> deserialize(final Response response) throws VPack
406412

407413
protected <T> Request deleteDocumentsRequest(final Collection<T> keys, final DocumentDeleteOptions options) {
408414
final Request request;
409-
request = new Request(db, RequestType.DELETE, executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
415+
request = new Request(db.name(), RequestType.DELETE,
416+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
410417
final DocumentDeleteOptions params = (options != null ? options : new DocumentDeleteOptions());
411418
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
412419
request.putQueryParam(ArangoDBConstants.RETURN_OLD, params.getReturnOld());
@@ -447,7 +454,7 @@ public MultiDocumentEntity<DocumentDeleteEntity<T>> deserialize(final Response r
447454

448455
protected Request documentExistsRequest(final String key, final DocumentExistsOptions options) {
449456
final Request request;
450-
request = new Request(db, RequestType.HEAD,
457+
request = new Request(db.name(), RequestType.HEAD,
451458
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
452459
final DocumentExistsOptions params = (options != null ? options : new DocumentExistsOptions());
453460
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
@@ -457,7 +464,7 @@ protected Request documentExistsRequest(final String key, final DocumentExistsOp
457464

458465
protected Request createHashIndexRequest(final Collection<String> fields, final HashIndexOptions options) {
459466
final Request request;
460-
request = new Request(db, RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
467+
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
461468
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
462469
request.setBody(
463470
executor.serialize(OptionsBuilder.build(options != null ? options : new HashIndexOptions(), fields)));
@@ -466,7 +473,7 @@ protected Request createHashIndexRequest(final Collection<String> fields, final
466473

467474
protected Request createSkiplistIndexRequest(final Collection<String> fields, final SkiplistIndexOptions options) {
468475
final Request request;
469-
request = new Request(db, RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
476+
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
470477
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
471478
request.setBody(
472479
executor.serialize(OptionsBuilder.build(options != null ? options : new SkiplistIndexOptions(), fields)));
@@ -477,7 +484,7 @@ protected Request createPersistentIndexRequest(
477484
final Collection<String> fields,
478485
final PersistentIndexOptions options) {
479486
final Request request;
480-
request = new Request(db, RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
487+
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
481488
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
482489
request.setBody(
483490
executor.serialize(OptionsBuilder.build(options != null ? options : new PersistentIndexOptions(), fields)));
@@ -486,7 +493,7 @@ protected Request createPersistentIndexRequest(
486493

487494
protected Request createGeoIndexRequest(final Collection<String> fields, final GeoIndexOptions options) {
488495
final Request request;
489-
request = new Request(db, RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
496+
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
490497
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
491498
request.setBody(
492499
executor.serialize(OptionsBuilder.build(options != null ? options : new GeoIndexOptions(), fields)));
@@ -495,7 +502,7 @@ protected Request createGeoIndexRequest(final Collection<String> fields, final G
495502

496503
protected Request getIndexesRequest() {
497504
final Request request;
498-
request = new Request(db, RequestType.GET, ArangoDBConstants.PATH_API_INDEX);
505+
request = new Request(db.name(), RequestType.GET, ArangoDBConstants.PATH_API_INDEX);
499506
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
500507
return request;
501508
}
@@ -512,66 +519,68 @@ public Collection<IndexEntity> deserialize(final Response response) throws VPack
512519
}
513520

514521
protected Request truncateRequest() {
515-
return new Request(db, RequestType.PUT,
522+
return new Request(db.name(), RequestType.PUT,
516523
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.TRUNCATE));
517524
}
518525

519526
protected Request countRequest() {
520-
return new Request(db, RequestType.GET,
527+
return new Request(db.name(), RequestType.GET,
521528
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.COUNT));
522529
}
523530

524531
protected Request createFulltextIndexRequest(final Collection<String> fields, final FulltextIndexOptions options) {
525532
final Request request;
526-
request = new Request(db, RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
533+
request = new Request(db.name(), RequestType.POST, ArangoDBConstants.PATH_API_INDEX);
527534
request.putQueryParam(ArangoDBConstants.COLLECTION, name);
528535
request.setBody(
529536
executor.serialize(OptionsBuilder.build(options != null ? options : new FulltextIndexOptions(), fields)));
530537
return request;
531538
}
532539

533540
protected Request dropRequest(final Boolean isSystem) {
534-
return new Request(db, RequestType.DELETE, executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name))
535-
.putQueryParam(ArangoDBConstants.IS_SYSTEM, isSystem);
541+
return new Request(db.name(), RequestType.DELETE,
542+
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name))
543+
.putQueryParam(ArangoDBConstants.IS_SYSTEM, isSystem);
536544
}
537545

538546
protected Request loadRequest() {
539-
return new Request(db, RequestType.PUT,
547+
return new Request(db.name(), RequestType.PUT,
540548
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.LOAD));
541549
}
542550

543551
protected Request unloadRequest() {
544-
return new Request(db, RequestType.PUT,
552+
return new Request(db.name(), RequestType.PUT,
545553
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.UNLOAD));
546554
}
547555

548556
protected Request getInfoRequest() {
549-
return new Request(db, RequestType.GET, executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name));
557+
return new Request(db.name(), RequestType.GET,
558+
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name));
550559
}
551560

552561
protected Request getPropertiesRequest() {
553-
return new Request(db, RequestType.GET,
562+
return new Request(db.name(), RequestType.GET,
554563
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.PROPERTIES));
555564
}
556565

557566
protected Request changePropertiesRequest(final CollectionPropertiesOptions options) {
558567
final Request request;
559-
request = new Request(db, RequestType.PUT,
568+
request = new Request(db.name(), RequestType.PUT,
560569
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.PROPERTIES));
561570
request.setBody(executor.serialize(options != null ? options : new CollectionPropertiesOptions()));
562571
return request;
563572
}
564573

565574
protected Request renameRequest(final String newName) {
566575
final Request request;
567-
request = new Request(db, RequestType.PUT,
576+
request = new Request(db.name(), RequestType.PUT,
568577
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.RENAME));
569578
request.setBody(executor.serialize(OptionsBuilder.build(new CollectionRenameOptions(), newName)));
570579
return request;
571580
}
572581

573582
protected Request getRevisionRequest() {
574-
return new Request(db, RequestType.GET,
583+
return new Request(db.name(), RequestType.GET,
575584
executor.createPath(ArangoDBConstants.PATH_API_COLLECTION, name, ArangoDBConstants.REVISION));
576585
}
577586
}

0 commit comments

Comments
 (0)