Skip to content

Commit 5a73b7c

Browse files
committed
#80 refactor all operations with defaults without options, find also with options
1 parent a6b9462 commit 5a73b7c

File tree

2 files changed

+86
-115
lines changed

2 files changed

+86
-115
lines changed

src/main/java/com/arangodb/springframework/core/ArangoOperations.java

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ <T> ArangoCursor<T> query(String query, Map<String, Object> bindVars, AqlQueryOp
9191
* @return cursor of the results
9292
* @throws DataAccessException
9393
*/
94-
<T> ArangoCursor<T> query(String query, Map<String, Object> bindVars, Class<T> entityClass)
95-
throws DataAccessException;
94+
default <T> ArangoCursor<T> query(String query, Map<String, Object> bindVars, Class<T> entityClass)
95+
throws DataAccessException {
96+
return query(query, bindVars, new AqlQueryOptions(), entityClass);
97+
}
9698

9799
/**
98100
* Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor} instance for the
@@ -120,7 +122,9 @@ <T> ArangoCursor<T> query(String query, Map<String, Object> bindVars, Class<T> e
120122
* @return cursor of the results
121123
* @throws DataAccessException
122124
*/
123-
<T> ArangoCursor<T> query(String query, Class<T> entityClass) throws DataAccessException;
125+
default <T> ArangoCursor<T> query(String query, Class<T> entityClass) throws DataAccessException {
126+
return query(query, new AqlQueryOptions(), entityClass);
127+
}
124128

125129
/**
126130
* Deletes multiple documents from a collection.
@@ -149,8 +153,10 @@ MultiDocumentEntity<? extends DocumentEntity> delete(
149153
* @return information about the documents
150154
* @throws DataAccessException
151155
*/
152-
MultiDocumentEntity<? extends DocumentEntity> delete(Iterable<Object> values, Class<?> entityClass)
153-
throws DataAccessException;
156+
default MultiDocumentEntity<? extends DocumentEntity> delete(Iterable<Object> values, Class<?> entityClass)
157+
throws DataAccessException {
158+
return delete(values, entityClass, new DocumentDeleteOptions());
159+
}
154160

155161
/**
156162
* Deletes the document with the given {@code id} from a collection.
@@ -176,7 +182,9 @@ MultiDocumentEntity<? extends DocumentEntity> delete(Iterable<Object> values, Cl
176182
* @return information about the document
177183
* @throws DataAccessException
178184
*/
179-
DocumentEntity delete(Object id, Class<?> entityClass) throws DataAccessException;
185+
default DocumentEntity delete(Object id, Class<?> entityClass) throws DataAccessException {
186+
return delete(id, entityClass, new DocumentDeleteOptions());
187+
}
180188

181189
/**
182190
* Partially updates documents, the documents to update are specified by the _key attributes in the objects on
@@ -215,8 +223,10 @@ <T> MultiDocumentEntity<? extends DocumentEntity> update(
215223
* @return information about the documents
216224
* @throws DataAccessException
217225
*/
218-
<T> MultiDocumentEntity<? extends DocumentEntity> update(Iterable<T> values, Class<T> entityClass)
219-
throws DataAccessException;
226+
default <T> MultiDocumentEntity<? extends DocumentEntity> update(Iterable<T> values, Class<T> entityClass)
227+
throws DataAccessException {
228+
return update(values, entityClass, new DocumentUpdateOptions());
229+
}
220230

221231
/**
222232
* Partially updates the document identified by document id or key. The value must contain a document with the
@@ -246,7 +256,9 @@ <T> MultiDocumentEntity<? extends DocumentEntity> update(Iterable<T> values, Cla
246256
* @return information about the document
247257
* @throws DataAccessException
248258
*/
249-
<T> DocumentEntity update(Object id, T value) throws DataAccessException;
259+
default <T> DocumentEntity update(Object id, T value) throws DataAccessException {
260+
return update(id, value, new DocumentUpdateOptions());
261+
}
250262

251263
/**
252264
* Replaces multiple documents in the specified collection with the ones in the values, the replaced documents are
@@ -278,13 +290,13 @@ <T> MultiDocumentEntity<? extends DocumentEntity> replace(
278290
* A List of documents
279291
* @param entityClass
280292
* The entity class which represents the collection
281-
* @param options
282-
* Additional options, can be null
283293
* @return information about the documents
284294
* @throws DataAccessException
285295
*/
286-
<T> MultiDocumentEntity<? extends DocumentEntity> replace(Iterable<T> values, Class<T> entityClass)
287-
throws DataAccessException;
296+
default <T> MultiDocumentEntity<? extends DocumentEntity> replace(Iterable<T> values, Class<T> entityClass)
297+
throws DataAccessException {
298+
return replace(values, entityClass, new DocumentReplaceOptions());
299+
}
288300

289301
/**
290302
* Replaces the document with {@code id} with the one in the body, provided there is such a document and no
@@ -312,7 +324,9 @@ <T> MultiDocumentEntity<? extends DocumentEntity> replace(Iterable<T> values, Cl
312324
* @return information about the document
313325
* @throws DataAccessException
314326
*/
315-
<T> DocumentEntity replace(Object id, T value) throws DataAccessException;
327+
default <T> DocumentEntity replace(Object id, T value) throws DataAccessException {
328+
return replace(id, value, new DocumentReplaceOptions());
329+
}
316330

317331
/**
318332
* Retrieves the document with the given {@code id} from a collection.
@@ -338,7 +352,9 @@ <T> MultiDocumentEntity<? extends DocumentEntity> replace(Iterable<T> values, Cl
338352
* @return the document identified by the id
339353
* @throws DataAccessException
340354
*/
341-
<T> Optional<T> find(Object id, Class<T> entityClass) throws DataAccessException;
355+
default <T> Optional<T> find(Object id, Class<T> entityClass) throws DataAccessException {
356+
return find(id, entityClass, new DocumentReadOptions());
357+
}
342358

343359
/**
344360
* Retrieves all documents from a collection.
@@ -348,7 +364,11 @@ <T> MultiDocumentEntity<? extends DocumentEntity> replace(Iterable<T> values, Cl
348364
* @return the documents
349365
* @throws DataAccessException
350366
*/
351-
<T> Iterable<T> findAll(Class<T> entityClass) throws DataAccessException;
367+
<T> Iterable<T> findAll(Class<T> entityClass, DocumentReadOptions options) throws DataAccessException;
368+
369+
default <T> Iterable<T> findAll(Class<T> entityClass) throws DataAccessException {
370+
return findAll(entityClass, new DocumentReadOptions());
371+
}
352372

353373
/**
354374
* Retrieves multiple documents with the given {@code ids} from a collection.
@@ -360,7 +380,11 @@ <T> MultiDocumentEntity<? extends DocumentEntity> replace(Iterable<T> values, Cl
360380
* @return the documents
361381
* @throws DataAccessException
362382
*/
363-
<T> Iterable<T> find(final Iterable<? extends Object> ids, final Class<T> entityClass) throws DataAccessException;
383+
<T> Iterable<T> find(final Iterable<? extends Object> ids, final Class<T> entityClass, DocumentReadOptions options) throws DataAccessException;
384+
385+
default <T> Iterable<T> find(final Iterable<? extends Object> ids, final Class<T> entityClass) throws DataAccessException {
386+
return find(ids, entityClass, new DocumentReadOptions());
387+
}
364388

365389
/**
366390
* Creates new documents from the given documents, unless there is already a document with the _key given. If no
@@ -395,8 +419,10 @@ <T> MultiDocumentEntity<? extends DocumentEntity> insert(
395419
* @return information about the documents
396420
* @throws DataAccessException
397421
*/
398-
<T> MultiDocumentEntity<? extends DocumentEntity> insert(Iterable<T> values, Class<T> entityClass)
399-
throws DataAccessException;
422+
default <T> MultiDocumentEntity<? extends DocumentEntity> insert(Iterable<T> values, Class<T> entityClass)
423+
throws DataAccessException {
424+
return insert(values, entityClass, new DocumentCreateOptions());
425+
}
400426

401427
/**
402428
* Creates a new document from the given document, unless there is already a document with the _key given. If no
@@ -418,7 +444,9 @@ <T> MultiDocumentEntity<? extends DocumentEntity> insert(Iterable<T> values, Cla
418444
* A representation of a single document
419445
* @return information about the document
420446
*/
421-
<T> DocumentEntity insert(T value) throws DataAccessException;
447+
default <T> DocumentEntity insert(T value) throws DataAccessException {
448+
return insert(value, new DocumentCreateOptions());
449+
}
422450

423451
/**
424452
* Creates a new document from the given document, unless there is already a document with the _key given. If no
@@ -448,7 +476,9 @@ DocumentEntity insert(String collectionName, Object value, DocumentCreateOptions
448476
* @return information about the document
449477
* @throws DataAccessException
450478
*/
451-
DocumentEntity insert(String collectionName, Object value) throws DataAccessException;
479+
default DocumentEntity insert(String collectionName, Object value) throws DataAccessException {
480+
return insert(collectionName, value, new DocumentCreateOptions());
481+
}
452482

453483
public enum UpsertStrategy {
454484
REPLACE, UPDATE
@@ -472,7 +502,7 @@ public enum UpsertStrategy {
472502
* Creates new documents from the given documents, unless there already exists. In that case it updates or replaces
473503
* the documents, depending on the chosen strategy.
474504
*
475-
* @deprecated use {@link #repsert(Iterable)} instead
505+
* @deprecated use {@link #repsert(Iterable, Class)} instead
476506
* @param value
477507
* A List of documents
478508
* @param strategy
@@ -491,7 +521,11 @@ public enum UpsertStrategy {
491521
* @throws DataAccessException
492522
* @since ArangoDB 3.4
493523
*/
494-
<T> void repsert(T value) throws DataAccessException;
524+
<T> void repsert(T value, AqlQueryOptions options) throws DataAccessException;
525+
526+
default <T> void repsert(T value) throws DataAccessException {
527+
repsert(value, new AqlQueryOptions());
528+
}
495529

496530
/**
497531
* Creates new documents from the given documents, unless there already exists. In that case it replaces the
@@ -504,7 +538,11 @@ public enum UpsertStrategy {
504538
* @throws DataAccessException
505539
* @since ArangoDB 3.4
506540
*/
507-
<T> void repsert(Iterable<? extends T> values, Class<T> entityClass) throws DataAccessException;
541+
<T> void repsert(Iterable<? extends T> values, Class<T> entityClass, AqlQueryOptions options) throws DataAccessException;
542+
543+
default <T> void repsert(Iterable<? extends T> values, Class<T> entityClass) throws DataAccessException {
544+
repsert(values, entityClass, new AqlQueryOptions());
545+
}
508546

509547
/**
510548
* Checks whether the document exists by reading a single document head
@@ -516,7 +554,11 @@ public enum UpsertStrategy {
516554
* @return true if the document exists, false if not
517555
* @throws DataAccessException
518556
*/
519-
boolean exists(Object id, Class<?> entityClass) throws DataAccessException;
557+
boolean exists(Object id, Class<?> entityClass, DocumentExistsOptions options) throws DataAccessException;
558+
559+
default boolean exists(Object id, Class<?> entityClass) throws DataAccessException {
560+
return exists(id, entityClass, new DocumentExistsOptions());
561+
}
520562

521563
/**
522564
* Drop an existing database
@@ -545,7 +587,9 @@ public enum UpsertStrategy {
545587
* @return {@link CollectionOperations}
546588
* @throws DataAccessException
547589
*/
548-
CollectionOperations collection(String name) throws DataAccessException;
590+
default CollectionOperations collection(String name) throws DataAccessException {
591+
return collection(name, new CollectionCreateOptions());
592+
}
549593

550594
/**
551595
* Returns the operations interface for a collection. If the collection does not exists, it is created

0 commit comments

Comments
 (0)