Skip to content

Commit 57a9acf

Browse files
committed
#80 minor code improvements
1 parent b36ca00 commit 57a9acf

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
}
@@ -330,12 +330,6 @@ public DbName getDatabaseName() {
330330
: databaseName);
331331
}
332332

333-
@Override
334-
public <T> ArangoCursor<T> query(final String query, final AqlQueryOptions options, final Class<T> entityClass)
335-
throws DataAccessException {
336-
return query(query, null, options, entityClass);
337-
}
338-
339333
@Override
340334
public <T> ArangoCursor<T> query(final String query, final Map<String, Object> bindVars,
341335
final AqlQueryOptions options, final Class<T> entityClass) throws DataAccessException {
@@ -481,7 +475,7 @@ public <T> Iterable<T> findAll(final Class<T> entityClass, DocumentReadOptions o
481475
}
482476

483477
@Override
484-
public <T> Iterable<T> find(final Iterable<? extends Object> ids, final Class<T> entityClass, DocumentReadOptions options)
478+
public <T> Iterable<T> find(final Iterable<?> ids, final Class<T> entityClass, DocumentReadOptions options)
485479
throws DataAccessException {
486480
try {
487481
final Collection<String> keys = new ArrayList<>();
@@ -519,7 +513,7 @@ public DocumentEntity insert(final Object value, final DocumentCreateOptions opt
519513
try {
520514
result = _collection(value.getClass()).insertDocument(toVPack(value), options);
521515
} catch (final ArangoDBException e) {
522-
throw exceptionTranslator.translateExceptionIfPossible(e);
516+
throw translateExceptionIfPossible(e);
523517
}
524518

525519
updateDBFields(value, result);
@@ -536,7 +530,7 @@ public DocumentEntity insert(final String collectionName, final Object value, fi
536530
try {
537531
result = _collection(collectionName).insertDocument(toVPack(value), options);
538532
} catch (final ArangoDBException e) {
539-
throw exceptionTranslator.translateExceptionIfPossible(e);
533+
throw translateExceptionIfPossible(e);
540534
}
541535

542536
updateDBFields(value, result);
@@ -557,7 +551,7 @@ private Object getDocumentKey(final ArangoPersistentEntity<?> entity, final Obje
557551

558552
@Override
559553
public <T> void upsert(final T value, final UpsertStrategy strategy) throws DataAccessException {
560-
final Class<? extends Object> entityClass = value.getClass();
554+
final Class<?> entityClass = value.getClass();
561555
final ArangoPersistentEntity<?> entity = getConverter().getMappingContext().getPersistentEntity(entityClass);
562556

563557
final Object id = getDocumentKey(entity, value);
@@ -576,13 +570,13 @@ public <T> void upsert(final T value, final UpsertStrategy strategy) throws Data
576570
insert(value);
577571
}
578572

579-
@SuppressWarnings("unchecked")
580573
@Override
581574
public <T> void upsert(final Iterable<T> value, final UpsertStrategy strategy) throws DataAccessException {
582575
final Optional<T> first = StreamSupport.stream(value.spliterator(), false).findFirst();
583576
if (!first.isPresent()) {
584577
return;
585578
}
579+
@SuppressWarnings("unchecked")
586580
final Class<T> entityClass = (Class<T>) first.get().getClass();
587581
final ArangoPersistentEntity<?> entity = getConverter().getMappingContext().getPersistentEntity(entityClass);
588582

@@ -630,7 +624,7 @@ public <T> void repsert(final T value, AqlQueryOptions options) throws DataAcces
630624
options, clazz
631625
).first();
632626
} catch (final ArangoDBException e) {
633-
throw exceptionTranslator.translateExceptionIfPossible(e);
627+
throw translateExceptionIfPossible(e);
634628
}
635629

636630
updateDBFieldsFromObject(value, result);
@@ -704,12 +698,12 @@ private <T> void updateDBFields(final Iterable<T> values, final MultiDocumentEnt
704698
final Iterator<T> valueIterator = values.iterator();
705699
if (res.getErrors().isEmpty()) {
706700
final Iterator<? extends DocumentEntity> documentIterator = res.getDocuments().iterator();
707-
for (; valueIterator.hasNext() && documentIterator.hasNext();) {
701+
while (valueIterator.hasNext() && documentIterator.hasNext()) {
708702
updateDBFields(valueIterator.next(), documentIterator.next());
709703
}
710704
} else {
711705
final Iterator<Object> documentIterator = res.getDocumentsAndErrors().iterator();
712-
for (; valueIterator.hasNext() && documentIterator.hasNext();) {
706+
while (valueIterator.hasNext() && documentIterator.hasNext()) {
713707
final Object nextDoc = documentIterator.next();
714708
final Object nextValue = valueIterator.next();
715709
if (nextDoc instanceof DocumentEntity) {
@@ -751,7 +745,7 @@ public void dropDatabase() throws DataAccessException {
751745
}
752746
databaseCache.remove(db.name());
753747
collectionCache.keySet().stream().filter(key -> key.getDb().equals(db.name()))
754-
.forEach(key -> collectionCache.remove(key));
748+
.forEach(collectionCache::remove);
755749
}
756750

757751
@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)