Skip to content

Commit 9990a6a

Browse files
committed
#80 minor code improvements
1 parent 0ab0fa4 commit 9990a6a

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,24 @@ default <T> ArangoCursor<T> query(String query, Map<String, Object> bindVars, Cl
9797
}
9898

9999
/**
100-
* Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor} instance for the
101-
* result list.
100+
* Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor}
101+
* instance for the result list.
102102
*
103103
* @param query
104104
* An AQL query string
105-
* @param options
106-
* Additional options that will be passed to the query API, can be null
107105
* @param entityClass
108106
* The entity type of the result
109107
* @return cursor of the results
110108
* @throws DataAccessException
111109
*/
112-
<T> ArangoCursor<T> query(String query, AqlQueryOptions options, Class<T> entityClass) throws DataAccessException;
110+
default <T> ArangoCursor<T> query(String query, AqlQueryOptions options, Class<T> entityClass)
111+
throws DataAccessException {
112+
return query(query, null, options, entityClass);
113+
}
113114

114115
/**
115-
* Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor} instance for the
116-
* result list.
116+
* Performs a database query using the given {@code query}, then returns a new {@code ArangoCursor}
117+
* instance for the result list.
117118
*
118119
* @param query
119120
* An AQL query string

src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ private ArangoCollection _collection(final String name, final ArangoPersistentEn
187187

188188
private static void ensureCollectionIndexes(final CollectionOperations collection,
189189
final ArangoPersistentEntity<?> persistentEntity) {
190-
persistentEntity.getHashIndexes().stream().forEach(index -> ensureHashIndex(collection, index));
191-
persistentEntity.getHashIndexedProperties().stream().forEach(p -> ensureHashIndex(collection, p));
192-
persistentEntity.getSkiplistIndexes().stream().forEach(index -> ensureSkiplistIndex(collection, index));
193-
persistentEntity.getSkiplistIndexedProperties().stream().forEach(p -> ensureSkiplistIndex(collection, p));
194-
persistentEntity.getPersistentIndexes().stream().forEach(index -> ensurePersistentIndex(collection, index));
195-
persistentEntity.getPersistentIndexedProperties().stream().forEach(p -> ensurePersistentIndex(collection, p));
196-
persistentEntity.getGeoIndexes().stream().forEach(index -> ensureGeoIndex(collection, index));
197-
persistentEntity.getGeoIndexedProperties().stream().forEach(p -> ensureGeoIndex(collection, p));
198-
persistentEntity.getFulltextIndexes().stream().forEach(index -> ensureFulltextIndex(collection, index));
199-
persistentEntity.getFulltextIndexedProperties().stream().forEach(p -> ensureFulltextIndex(collection, p));
190+
persistentEntity.getHashIndexes().forEach(index -> ensureHashIndex(collection, index));
191+
persistentEntity.getHashIndexedProperties().forEach(p -> ensureHashIndex(collection, p));
192+
persistentEntity.getSkiplistIndexes().forEach(index -> ensureSkiplistIndex(collection, index));
193+
persistentEntity.getSkiplistIndexedProperties().forEach(p -> ensureSkiplistIndex(collection, p));
194+
persistentEntity.getPersistentIndexes().forEach(index -> ensurePersistentIndex(collection, index));
195+
persistentEntity.getPersistentIndexedProperties().forEach(p -> ensurePersistentIndex(collection, p));
196+
persistentEntity.getGeoIndexes().forEach(index -> ensureGeoIndex(collection, index));
197+
persistentEntity.getGeoIndexedProperties().forEach(p -> ensureGeoIndex(collection, p));
198+
persistentEntity.getFulltextIndexes().forEach(index -> ensureFulltextIndex(collection, index));
199+
persistentEntity.getFulltextIndexedProperties().forEach(p -> ensureFulltextIndex(collection, p));
200200
persistentEntity.getTtlIndex().ifPresent(index -> ensureTtlIndex(collection, index));
201201
persistentEntity.getTtlIndexedProperty().ifPresent(p -> ensureTtlIndex(collection, p));
202202
}
@@ -324,12 +324,6 @@ public DbName getDatabaseName() {
324324
: databaseName);
325325
}
326326

327-
@Override
328-
public <T> ArangoCursor<T> query(final String query, final AqlQueryOptions options, final Class<T> entityClass)
329-
throws DataAccessException {
330-
return query(query, null, options, entityClass);
331-
}
332-
333327
@Override
334328
public <T> ArangoCursor<T> query(final String query, final Map<String, Object> bindVars,
335329
final AqlQueryOptions options, final Class<T> entityClass) throws DataAccessException {
@@ -475,7 +469,7 @@ public <T> Iterable<T> findAll(final Class<T> entityClass, DocumentReadOptions o
475469
}
476470

477471
@Override
478-
public <T> Iterable<T> find(final Iterable<? extends Object> ids, final Class<T> entityClass, DocumentReadOptions options)
472+
public <T> Iterable<T> find(final Iterable<?> ids, final Class<T> entityClass, DocumentReadOptions options)
479473
throws DataAccessException {
480474
try {
481475
final Collection<String> keys = new ArrayList<>();
@@ -513,7 +507,7 @@ public DocumentEntity insert(final Object value, final DocumentCreateOptions opt
513507
try {
514508
result = _collection(value.getClass()).insertDocument(toVPack(value), options);
515509
} catch (final ArangoDBException e) {
516-
throw exceptionTranslator.translateExceptionIfPossible(e);
510+
throw translateExceptionIfPossible(e);
517511
}
518512

519513
updateDBFields(value, result);
@@ -530,7 +524,7 @@ public DocumentEntity insert(final String collectionName, final Object value, fi
530524
try {
531525
result = _collection(collectionName).insertDocument(toVPack(value), options);
532526
} catch (final ArangoDBException e) {
533-
throw exceptionTranslator.translateExceptionIfPossible(e);
527+
throw translateExceptionIfPossible(e);
534528
}
535529

536530
updateDBFields(value, result);
@@ -551,7 +545,7 @@ private Object getDocumentKey(final ArangoPersistentEntity<?> entity, final Obje
551545

552546
@Override
553547
public <T> void upsert(final T value, final UpsertStrategy strategy) throws DataAccessException {
554-
final Class<? extends Object> entityClass = value.getClass();
548+
final Class<?> entityClass = value.getClass();
555549
final ArangoPersistentEntity<?> entity = getConverter().getMappingContext().getPersistentEntity(entityClass);
556550

557551
final Object id = getDocumentKey(entity, value);
@@ -570,13 +564,13 @@ public <T> void upsert(final T value, final UpsertStrategy strategy) throws Data
570564
insert(value);
571565
}
572566

573-
@SuppressWarnings("unchecked")
574567
@Override
575568
public <T> void upsert(final Iterable<T> value, final UpsertStrategy strategy) throws DataAccessException {
576569
final Optional<T> first = StreamSupport.stream(value.spliterator(), false).findFirst();
577570
if (!first.isPresent()) {
578571
return;
579572
}
573+
@SuppressWarnings("unchecked")
580574
final Class<T> entityClass = (Class<T>) first.get().getClass();
581575
final ArangoPersistentEntity<?> entity = getConverter().getMappingContext().getPersistentEntity(entityClass);
582576

@@ -624,7 +618,7 @@ public <T> void repsert(final T value, AqlQueryOptions options) throws DataAcces
624618
options, clazz
625619
).first();
626620
} catch (final ArangoDBException e) {
627-
throw exceptionTranslator.translateExceptionIfPossible(e);
621+
throw translateExceptionIfPossible(e);
628622
}
629623

630624
updateDBFieldsFromObject(value, result);
@@ -698,12 +692,12 @@ private <T> void updateDBFields(final Iterable<T> values, final MultiDocumentEnt
698692
final Iterator<T> valueIterator = values.iterator();
699693
if (res.getErrors().isEmpty()) {
700694
final Iterator<? extends DocumentEntity> documentIterator = res.getDocuments().iterator();
701-
for (; valueIterator.hasNext() && documentIterator.hasNext();) {
695+
while (valueIterator.hasNext() && documentIterator.hasNext()) {
702696
updateDBFields(valueIterator.next(), documentIterator.next());
703697
}
704698
} else {
705699
final Iterator<Object> documentIterator = res.getDocumentsAndErrors().iterator();
706-
for (; valueIterator.hasNext() && documentIterator.hasNext();) {
700+
while (valueIterator.hasNext() && documentIterator.hasNext()) {
707701
final Object nextDoc = documentIterator.next();
708702
final Object nextValue = valueIterator.next();
709703
if (nextDoc instanceof DocumentEntity) {
@@ -745,7 +739,7 @@ public void dropDatabase() throws DataAccessException {
745739
}
746740
databaseCache.remove(db.name());
747741
collectionCache.keySet().stream().filter(key -> key.getDb().equals(db.name()))
748-
.forEach(key -> collectionCache.remove(key));
742+
.forEach(collectionCache::remove);
749743
}
750744

751745
@Override

src/main/java/com/arangodb/springframework/repository/query/AbstractArangoQuery.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ public Object execute(final Object[] parameters) {
7878
options.fullCount(true);
7979
}
8080

81-
final QueryWithCollections queryAndCollection = createQuery(accessor, bindVars);
81+
final QueryWithCollections query = createQuery(accessor, bindVars);
8282
if (options.getStreamTransactionId() == null && transactionBridge != null) {
83-
options.streamTransactionId(transactionBridge.getCurrentTransaction(queryAndCollection.getCollections()));
83+
options.streamTransactionId(transactionBridge.getCurrentTransaction(query.getCollections()));
8484
}
8585

8686

8787
final ResultProcessor processor = method.getResultProcessor().withDynamicProjection(accessor);
8888
final Class<?> typeToRead = getTypeToRead(processor);
8989

90-
final ArangoCursor<?> result = operations.query(queryAndCollection.getQuery(), bindVars, options, typeToRead);
90+
final ArangoCursor<?> result = operations.query(query.getQuery(), bindVars, options, typeToRead);
9191
logWarningsIfNecessary(result);
9292
return processor.processResult(convertResult(result, accessor));
9393
}

0 commit comments

Comments
 (0)