Skip to content

Commit 40ff860

Browse files
committed
cleanup warnings
1 parent 56283fe commit 40ff860

File tree

10 files changed

+34
-48
lines changed

10 files changed

+34
-48
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ public ArangoDatabase db() throws DataAccessException {
130130
});
131131
}
132132

133-
private ArangoCollection _collection(final String name, boolean transactional) {
134-
return _collection(name, null, null, transactional);
135-
}
136-
137133
private ArangoCollection _collection(final Class<?> entityClass, boolean transactional) {
138134
return _collection(entityClass, null, transactional);
139135
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public Collection<Class<?>> getEntities() {
3030
public Collection<IndexEntity> getIndexes() {
3131
return indexes;
3232
}
33+
3334
public boolean addEntityClass(final Class<?> entityClass) {
3435
return entities.add(entityClass);
3536
}

src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ public Iterator<T> iterator() {
257257
*/
258258
@Override
259259
public Page<T> findAll(final Pageable pageable) {
260-
if (pageable == null) {
261-
LOGGER.debug("Pageable in findAll(Pageable) is null");
262-
}
263-
264260
final ArangoCursor<T> result = findAllInternal(pageable, null, new HashMap<>());
265261
final List<T> content = result.asListRemaining();
266262
return new PageImpl<>(content, pageable, ((Number) result.getStats().getFullCount()).longValue());
@@ -342,7 +338,7 @@ public <S extends T> long count(final Example<S> example) {
342338
final Map<String, Object> bindVars = new HashMap<>();
343339
bindVars.put("@col", getCollectionName());
344340
final String predicate = exampleConverter.convertExampleToPredicate(example, bindVars);
345-
final String filter = predicate.length() == 0 ? "" : " FILTER " + predicate;
341+
final String filter = predicate.isEmpty() ? "" : " FILTER " + predicate;
346342
final String query = String.format("FOR e IN @@col %s COLLECT WITH COUNT INTO length RETURN length", filter);
347343
arangoTemplate.collection(domainClass);
348344
final ArangoCursor<Long> cursor = arangoTemplate.query(query, bindVars, defaultQueryOptions(), Long.class);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package com.arangodb.springframework.repository.query;
2222

23-
import java.util.Collection;
2423
import java.util.HashMap;
2524
import java.util.Map;
2625

@@ -94,7 +93,7 @@ public Object execute(final Object[] parameters) {
9493

9594
private void logWarningsIfNecessary(final ArangoCursor<?> result) {
9695
result.getWarnings().forEach(warning -> {
97-
LOGGER.warn("Query warning at [" + method + "]: " + warning.getCode() + " - " + warning.getMessage());
96+
LOGGER.warn("Query warning at [{}]: {} - {}", method, warning.getCode(), warning.getMessage());
9897
});
9998
}
10099

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.arangodb.springframework.repository.query.derived.DerivedQueryCreator;
2929
import org.springframework.data.repository.query.parser.PartTree;
3030

31-
import java.util.Collection;
3231
import java.util.LinkedList;
3332
import java.util.List;
3433
import java.util.Map;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
public class QueryTransactionBridge {
3535

36-
private static final ThreadLocal<Function<Collection<String>, String>> CURRENT_TRANSACTION = new NamedInheritableThreadLocal<Function<Collection<String>, String>>("ArangoTransactionBegin") {
36+
private static final ThreadLocal<Function<Collection<String>, String>> CURRENT_TRANSACTION = new NamedInheritableThreadLocal<>("ArangoTransactionBegin") {
3737
@Override
3838
protected Function<Collection<String>, String> initialValue() {
3939
return any -> null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private void extractBindVars(final ArangoParameterAccessor accessor, final Map<S
171171
final ArangoParameter param = bindableParams.getParameter(i);
172172
final Object value = accessor.getBindableValue(i);
173173
if (param.isNamedParameter()) {
174-
bindVars.put(param.getName().get(), value);
174+
param.getName().ifPresent(name -> bindVars.put(name, value));
175175
} else {
176176
final String key = String.valueOf(param.getIndex());
177177
final String collectionKey = "@" + key;

src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.springframework.util.Assert;
4747

4848
import java.util.*;
49-
import java.util.stream.Collectors;
5049

5150
/**
5251
* Creates a full AQL query from a PartTree and ArangoParameterAccessor
@@ -89,7 +88,7 @@ public DerivedQueryCreator(
8988
super(tree, accessor);
9089
this.context = context;
9190
this.domainClass = domainClass;
92-
collectionName = AqlUtils.buildCollectionName(context.getPersistentEntity(domainClass).getCollection());
91+
collectionName = AqlUtils.buildCollectionName(context.getRequiredPersistentEntity(domainClass).getCollection());
9392
this.tree = tree;
9493
this.accessor = accessor;
9594
this.geoFields = geoFields;
@@ -127,7 +126,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
127126
}
128127
final StringBuilder query = new StringBuilder();
129128

130-
final String with = withCollections.stream().collect(Collectors.joining(", "));
129+
final String with = String.join(", ", withCollections);
131130
if (!with.isEmpty()) {
132131
query.append("WITH ").append(with).append(" ");
133132
}
@@ -160,7 +159,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
160159
if (sort.isUnsorted()) {
161160
sortString = distanceSortKey;
162161
} else {
163-
sortString = distanceSortKey + ", " + sortString.substring(5, sortString.length());
162+
sortString = distanceSortKey + ", " + sortString.substring(5);
164163
}
165164
}
166165
query.append(sortString);
@@ -170,7 +169,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
170169
}
171170

172171
final Pageable pageable = accessor.getPageable();
173-
if (pageable != null && pageable.isPaged()) {
172+
if (pageable.isPaged()) {
174173
query.append(" ").append(AqlUtils.buildLimitClause(pageable));
175174
}
176175
if (tree.isDelete()) {
@@ -261,7 +260,7 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
261260
--propertiesLeft;
262261
final ArangoPersistentProperty property = (ArangoPersistentProperty) object;
263262
if (propertiesLeft == 0) {
264-
simpleProperties.append("." + AqlUtils.buildFieldName(property.getFieldName()));
263+
simpleProperties.append(".").append(AqlUtils.buildFieldName(property.getFieldName()));
265264
break;
266265
}
267266
if (property.getRelations().isPresent()) {
@@ -274,34 +273,34 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
274273
final Class<?>[] edgeClasses = relations.edges();
275274
final StringBuilder edgesBuilder = new StringBuilder();
276275
for (final Class<?> edge : edgeClasses) {
277-
String collection = context.getPersistentEntity(edge).getCollection();
276+
String collection = context.getRequiredPersistentEntity(edge).getCollection();
278277
if (collection.split("-").length > 1) {
279278
collection = "`" + collection + "`";
280279
}
281-
edgesBuilder.append((edgesBuilder.length() == 0 ? "" : ", ") + collection);
280+
edgesBuilder.append(edgesBuilder.isEmpty() ? "" : ", ").append(collection);
282281
}
283282
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer.toString(varsUsed));
284283
final String entity = "e" + Integer.toString(++varsUsed);
285284
final String edges = edgesBuilder.toString();
286285
simpleProperties = new StringBuilder();
287286
final String iteration = format(TEMPLATE, entity, depths, direction, prevEntity, nested, edges);
288287
final String predicate = format(PREDICATE_TEMPLATE, iteration);
289-
predicateTemplate = predicateTemplate.length() == 0 ? predicate : format(predicateTemplate, predicate);
288+
predicateTemplate = predicateTemplate.isEmpty() ? predicate : format(predicateTemplate, predicate);
290289
} else if (property.isCollectionLike()) {
291290
if (property.getRef().isPresent()) {
292291
// collection of references
293292
final String TEMPLATE = "FOR %s IN %s FILTER %s._id IN %s%s";
294293
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer.toString(varsUsed));
295294
final String entity = "e" + Integer.toString(++varsUsed);
296-
String collection = context.getPersistentEntity(property.getComponentType()).getCollection();
295+
String collection = context.getRequiredPersistentEntity(property).getCollection();
297296
if (collection.split("-").length > 1) {
298297
collection = "`" + collection + "`";
299298
}
300-
final String name = simpleProperties.toString() + "." + AqlUtils.buildFieldName(property.getFieldName());
299+
final String name = simpleProperties + "." + AqlUtils.buildFieldName(property.getFieldName());
301300
simpleProperties = new StringBuilder();
302301
final String iteration = format(TEMPLATE, entity, collection, entity, prevEntity, name);
303302
final String predicate = format(PREDICATE_TEMPLATE, iteration);
304-
predicateTemplate = predicateTemplate.length() == 0 ? predicate
303+
predicateTemplate = predicateTemplate.isEmpty() ? predicate
305304
: format(predicateTemplate, predicate);
306305
} else {
307306
// collection
@@ -312,28 +311,28 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
312311
simpleProperties = new StringBuilder();
313312
final String iteration = format(TEMPLATE, entity, prevEntity, name);
314313
final String predicate = format(PREDICATE_TEMPLATE, iteration);
315-
predicateTemplate = predicateTemplate.length() == 0 ? predicate
314+
predicateTemplate = predicateTemplate.isEmpty() ? predicate
316315
: format(predicateTemplate, predicate);
317316
}
318317
} else {
319318
if (property.getRef().isPresent() || property.getFrom().isPresent() || property.getTo().isPresent()) {
320319
// single reference
321320
final String TEMPLATE = "FOR %s IN %s FILTER %s._id == %s%s";
322321
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer.toString(varsUsed));
323-
final String entity = "e" + Integer.toString(++varsUsed);
324-
String collection = context.getPersistentEntity(property.getType()).getCollection();
322+
final String entity = "e" + ++varsUsed;
323+
String collection = context.getRequiredPersistentEntity(property).getCollection();
325324
if (collection.split("-").length > 1) {
326325
collection = "`" + collection + "`";
327326
}
328-
final String name = simpleProperties.toString() + "." + AqlUtils.buildFieldName(property.getFieldName());
327+
final String name = simpleProperties + "." + AqlUtils.buildFieldName(property.getFieldName());
329328
simpleProperties = new StringBuilder();
330329
final String iteration = format(TEMPLATE, entity, collection, entity, prevEntity, name);
331330
final String predicate = format(PREDICATE_TEMPLATE, iteration);
332-
predicateTemplate = predicateTemplate.length() == 0 ? predicate
331+
predicateTemplate = predicateTemplate.isEmpty() ? predicate
333332
: format(predicateTemplate, predicate);
334333
} else {
335334
// simple property
336-
simpleProperties.append("." + AqlUtils.buildFieldName(property.getFieldName()));
335+
simpleProperties.append(".").append(AqlUtils.buildFieldName(property.getFieldName()));
337336
}
338337
}
339338
}
@@ -385,7 +384,7 @@ private void checkUniquePoint(final Point point) {
385384
* @param part
386385
*/
387386
private void checkUniqueLocation(final Part part) {
388-
isUnique = isUnique == null ? true : isUnique;
387+
isUnique = isUnique == null || isUnique;
389388
isUnique = (uniqueLocation == null || uniqueLocation.equals(ignorePropertyCase(part))) ? isUnique : false;
390389
if (!geoFields.isEmpty()) {
391390
Assert.isTrue(isUnique, "Different location fields are used - Distance is ambiguous");
@@ -398,8 +397,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
398397
final String[] templateAndProperty = createPredicateTemplateAndPropertyString(part);
399398
final String template = templateAndProperty[0];
400399
final String property = templateAndProperty[1];
401-
Criteria criteria = null;
402-
final boolean checkUnique = part.getProperty().toDotPath().split(".").length <= 1;
400+
final boolean checkUnique = part.getProperty().toDotPath().split("\\.").length <= 1;
403401
Class<?> type = part.getProperty().getType();
404402

405403
// whether the current field type is a type encoded as geoJson
@@ -410,6 +408,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
410408
hasGeoJsonType = true;
411409
}
412410

411+
Criteria criteria = null;
413412
switch (part.getType()) {
414413
case SIMPLE_PROPERTY:
415414
criteria = Criteria.eql(ignorePropertyCase(part, property), bind(part, iterator));
@@ -431,7 +430,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
431430
break;
432431
case EXISTS:
433432
final String document = property.substring(0, property.lastIndexOf("."));
434-
final String attribute = property.substring(property.lastIndexOf(".") + 1, property.length());
433+
final String attribute = property.substring(property.lastIndexOf(".") + 1);
435434
criteria = Criteria.exists(document, attribute);
436435
break;
437436
case BEFORE:
@@ -492,10 +491,9 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
492491
if (nearValue instanceof Point point) {
493492
checkUniquePoint(point);
494493
} else {
495-
bindingCounter = binding.bind(nearValue, shouldIgnoreCase(part), null, point -> checkUniquePoint(point),
494+
bindingCounter = binding.bind(nearValue, shouldIgnoreCase(part), null, this::checkUniquePoint,
496495
bindingCounter);
497496
}
498-
criteria = null;
499497
break;
500498
case WITHIN:
501499
if (checkUnique) {
@@ -588,24 +586,24 @@ private int bind(final Part part, final Iterator<Object> iterator, final Boolean
588586

589587
private int bind(final Part part, final Object value, final Boolean borderStatus) {
590588
final int index = bindingCounter;
591-
bindingCounter = binding.bind(value, shouldIgnoreCase(part), borderStatus, point -> checkUniquePoint(point),
589+
bindingCounter = binding.bind(value, shouldIgnoreCase(part), borderStatus, this::checkUniquePoint,
592590
bindingCounter);
593591
return index;
594592
}
595593

596594
private int bind(final Object value) {
597595
final int index = bindingCounter;
598-
bindingCounter = binding.bind(value, false, null, point -> checkUniquePoint(point), bindingCounter);
596+
bindingCounter = binding.bind(value, false, null, this::checkUniquePoint, bindingCounter);
599597
return index;
600598
}
601599

602600
private void bindPoint(final Part part, final Object value, final boolean toGeoJson) {
603-
bindingCounter = binding.bindPoint(value, shouldIgnoreCase(part), point -> checkUniquePoint(point),
601+
bindingCounter = binding.bindPoint(value, shouldIgnoreCase(part), this::checkUniquePoint,
604602
bindingCounter, toGeoJson);
605603
}
606604

607605
private void bindCircle(final Part part, final Object value, final boolean toGeoJson) {
608-
bindingCounter = binding.bindCircle(value, shouldIgnoreCase(part), point -> checkUniquePoint(point),
606+
bindingCounter = binding.bindCircle(value, shouldIgnoreCase(part), this::checkUniquePoint,
609607
bindingCounter, toGeoJson);
610608
}
611609

@@ -614,7 +612,7 @@ private void bindRange(final Part part, final Object value) {
614612
}
615613

616614
private void bindRing(final Part part, final Object value, final boolean toGeoJson) {
617-
bindingCounter = binding.bindRing(value, shouldIgnoreCase(part), point -> checkUniquePoint(point),
615+
bindingCounter = binding.bindRing(value, shouldIgnoreCase(part), this::checkUniquePoint,
618616
bindingCounter, toGeoJson);
619617
}
620618

@@ -632,7 +630,6 @@ private void collectWithCollections(final PropertyPath propertyPath) {
632630
propertyPath.stream()
633631
.filter(property -> {
634632
ArangoPersistentProperty p = context.getPersistentPropertyPath(property).getBaseProperty();
635-
if (p == null) return false;
636633
Optional<Ref> ref = p.getRef();
637634
Optional<Relations> rels = p.getRelations();
638635
return ref.isPresent() || rels.isPresent();

src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.arangodb.springframework.core.template.CollectionCallback;
2727
import com.arangodb.springframework.repository.query.QueryTransactionBridge;
2828
import org.springframework.beans.factory.InitializingBean;
29-
import org.springframework.lang.Nullable;
3029
import org.springframework.transaction.*;
3130
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
3231
import org.springframework.transaction.support.DefaultTransactionStatus;
@@ -80,7 +79,7 @@ public void afterPropertiesSet() {
8079
* Creates a new transaction object. Any holder bound will be reused.
8180
*/
8281
@Override
83-
protected ArangoTransactionObject doGetTransaction() {
82+
protected Object doGetTransaction() {
8483
ArangoTransactionHolder holder = (ArangoTransactionHolder) TransactionSynchronizationManager.getResource(this);
8584
try {
8685
return new ArangoTransactionObject(operations.db(), CollectionCallback.fromOperations(operations), getDefaultTimeout(), holder);

src/main/java/com/arangodb/springframework/transaction/TransactionAttributeTemplate.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public TransactionAttributeTemplate(PlatformTransactionManager transactionManage
5454

5555
public TransactionAttributeTemplate(PlatformTransactionManager transactionManager, TransactionDefinition transactionDefinition) {
5656
super(transactionManager, transactionDefinition);
57-
if (transactionDefinition instanceof TransactionAttribute) {
58-
TransactionAttribute transactionAttribute = (TransactionAttribute) transactionDefinition;
57+
if (transactionDefinition instanceof TransactionAttribute transactionAttribute) {
5958
setQualifier(transactionAttribute.getQualifier());
6059
setLabels(transactionAttribute.getLabels());
6160
setRollbackOn(transactionAttribute::rollbackOn);

0 commit comments

Comments
 (0)