Skip to content

Commit

Permalink
cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aburmeis committed Sep 9, 2024
1 parent 7e6f2f3 commit 63b0557
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ public ArangoDatabase db() throws DataAccessException {
});
}

private ArangoCollection _collection(final String name, boolean transactional) {
return _collection(name, null, null, transactional);
}

private ArangoCollection _collection(final Class<?> entityClass, boolean transactional) {
return _collection(entityClass, null, transactional);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public Collection<Class<?>> getEntities() {
public Collection<IndexEntity> getIndexes() {
return indexes;
}

public boolean addEntityClass(final Class<?> entityClass) {
return entities.add(entityClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ public Iterator<T> iterator() {
*/
@Override
public Page<T> findAll(final Pageable pageable) {
if (pageable == null) {
LOGGER.debug("Pageable in findAll(Pageable) is null");
}

final ArangoCursor<T> result = findAllInternal(pageable, null, new HashMap<>());
final List<T> content = result.asListRemaining();
return new PageImpl<>(content, pageable, ((Number) result.getStats().getFullCount()).longValue());
Expand Down Expand Up @@ -342,7 +338,7 @@ public <S extends T> long count(final Example<S> example) {
final Map<String, Object> bindVars = new HashMap<>();
bindVars.put("@col", getCollectionName());
final String predicate = exampleConverter.convertExampleToPredicate(example, bindVars);
final String filter = predicate.length() == 0 ? "" : " FILTER " + predicate;
final String filter = predicate.isEmpty() ? "" : " FILTER " + predicate;
final String query = String.format("FOR e IN @@col %s COLLECT WITH COUNT INTO length RETURN length", filter);
arangoTemplate.collection(domainClass);
final ArangoCursor<Long> cursor = arangoTemplate.query(query, bindVars, defaultQueryOptions(), Long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package com.arangodb.springframework.repository.query;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.arangodb.springframework.repository.query.derived.DerivedQueryCreator;
import org.springframework.data.repository.query.parser.PartTree;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class QueryTransactionBridge {

private static final ThreadLocal<Function<Collection<String>, String>> CURRENT_TRANSACTION = new NamedInheritableThreadLocal<Function<Collection<String>, String>>("ArangoTransactionBegin") {
private static final ThreadLocal<Function<Collection<String>, String>> CURRENT_TRANSACTION = new NamedInheritableThreadLocal<>("ArangoTransactionBegin") {
@Override
protected Function<Collection<String>, String> initialValue() {
return any -> null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void extractBindVars(final ArangoParameterAccessor accessor, final Map<S
final ArangoParameter param = bindableParams.getParameter(i);
final Object value = accessor.getBindableValue(i);
if (param.isNamedParameter()) {
bindVars.put(param.getName().get(), value);
param.getName().ifPresent(name -> bindVars.put(name, value));
} else {
final String key = String.valueOf(param.getIndex());
final String collectionKey = "@" + key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.springframework.util.Assert;

import java.util.*;
import java.util.stream.Collectors;

/**
* Creates a full AQL query from a PartTree and ArangoParameterAccessor
Expand Down Expand Up @@ -89,7 +88,7 @@ public DerivedQueryCreator(
super(tree, accessor);
this.context = context;
this.domainClass = domainClass;
collectionName = AqlUtils.buildCollectionName(context.getPersistentEntity(domainClass).getCollection());
collectionName = AqlUtils.buildCollectionName(context.getRequiredPersistentEntity(domainClass).getCollection());
this.tree = tree;
this.accessor = accessor;
this.geoFields = geoFields;
Expand Down Expand Up @@ -127,7 +126,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
}
final StringBuilder query = new StringBuilder();

final String with = withCollections.stream().collect(Collectors.joining(", "));
final String with = String.join(", ", withCollections);
if (!with.isEmpty()) {
query.append("WITH ").append(with).append(" ");
}
Expand Down Expand Up @@ -160,7 +159,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
if (sort.isUnsorted()) {
sortString = distanceSortKey;
} else {
sortString = distanceSortKey + ", " + sortString.substring(5, sortString.length());
sortString = distanceSortKey + ", " + sortString.substring(5);
}
}
query.append(sortString);
Expand All @@ -170,7 +169,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
}

final Pageable pageable = accessor.getPageable();
if (pageable != null && pageable.isPaged()) {
if (pageable.isPaged()) {
query.append(" ").append(AqlUtils.buildLimitClause(pageable));
}
if (tree.isDelete()) {
Expand Down Expand Up @@ -261,7 +260,7 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
--propertiesLeft;
final ArangoPersistentProperty property = (ArangoPersistentProperty) object;
if (propertiesLeft == 0) {
simpleProperties.append("." + AqlUtils.buildFieldName(property.getFieldName()));
simpleProperties.append(".").append(AqlUtils.buildFieldName(property.getFieldName()));
break;
}
if (property.getRelations().isPresent()) {
Expand All @@ -274,34 +273,34 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
final Class<?>[] edgeClasses = relations.edges();
final StringBuilder edgesBuilder = new StringBuilder();
for (final Class<?> edge : edgeClasses) {
String collection = context.getPersistentEntity(edge).getCollection();
String collection = context.getRequiredPersistentEntity(edge).getCollection();
if (collection.split("-").length > 1) {
collection = "`" + collection + "`";
}
edgesBuilder.append((edgesBuilder.length() == 0 ? "" : ", ") + collection);
edgesBuilder.append(edgesBuilder.isEmpty() ? "" : ", ").append(collection);
}
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer.toString(varsUsed));
final String entity = "e" + Integer.toString(++varsUsed);
final String edges = edgesBuilder.toString();
simpleProperties = new StringBuilder();
final String iteration = format(TEMPLATE, entity, depths, direction, prevEntity, nested, edges);
final String predicate = format(PREDICATE_TEMPLATE, iteration);
predicateTemplate = predicateTemplate.length() == 0 ? predicate : format(predicateTemplate, predicate);
predicateTemplate = predicateTemplate.isEmpty() ? predicate : format(predicateTemplate, predicate);
} else if (property.isCollectionLike()) {
if (property.getRef().isPresent()) {
// collection of references
final String TEMPLATE = "FOR %s IN %s FILTER %s._id IN %s%s";
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer.toString(varsUsed));
final String entity = "e" + Integer.toString(++varsUsed);
String collection = context.getPersistentEntity(property.getComponentType()).getCollection();
String collection = context.getRequiredPersistentEntity(property).getCollection();
if (collection.split("-").length > 1) {
collection = "`" + collection + "`";
}
final String name = simpleProperties.toString() + "." + AqlUtils.buildFieldName(property.getFieldName());
final String name = simpleProperties + "." + AqlUtils.buildFieldName(property.getFieldName());
simpleProperties = new StringBuilder();
final String iteration = format(TEMPLATE, entity, collection, entity, prevEntity, name);
final String predicate = format(PREDICATE_TEMPLATE, iteration);
predicateTemplate = predicateTemplate.length() == 0 ? predicate
predicateTemplate = predicateTemplate.isEmpty() ? predicate
: format(predicateTemplate, predicate);
} else {
// collection
Expand All @@ -312,28 +311,28 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
simpleProperties = new StringBuilder();
final String iteration = format(TEMPLATE, entity, prevEntity, name);
final String predicate = format(PREDICATE_TEMPLATE, iteration);
predicateTemplate = predicateTemplate.length() == 0 ? predicate
predicateTemplate = predicateTemplate.isEmpty() ? predicate
: format(predicateTemplate, predicate);
}
} else {
if (property.getRef().isPresent() || property.getFrom().isPresent() || property.getTo().isPresent()) {
// single reference
final String TEMPLATE = "FOR %s IN %s FILTER %s._id == %s%s";
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer.toString(varsUsed));
final String entity = "e" + Integer.toString(++varsUsed);
String collection = context.getPersistentEntity(property.getType()).getCollection();
final String entity = "e" + ++varsUsed;
String collection = context.getRequiredPersistentEntity(property).getCollection();
if (collection.split("-").length > 1) {
collection = "`" + collection + "`";
}
final String name = simpleProperties.toString() + "." + AqlUtils.buildFieldName(property.getFieldName());
final String name = simpleProperties + "." + AqlUtils.buildFieldName(property.getFieldName());
simpleProperties = new StringBuilder();
final String iteration = format(TEMPLATE, entity, collection, entity, prevEntity, name);
final String predicate = format(PREDICATE_TEMPLATE, iteration);
predicateTemplate = predicateTemplate.length() == 0 ? predicate
predicateTemplate = predicateTemplate.isEmpty() ? predicate
: format(predicateTemplate, predicate);
} else {
// simple property
simpleProperties.append("." + AqlUtils.buildFieldName(property.getFieldName()));
simpleProperties.append(".").append(AqlUtils.buildFieldName(property.getFieldName()));
}
}
}
Expand Down Expand Up @@ -385,7 +384,7 @@ private void checkUniquePoint(final Point point) {
* @param part
*/
private void checkUniqueLocation(final Part part) {
isUnique = isUnique == null ? true : isUnique;
isUnique = isUnique == null || isUnique;
isUnique = (uniqueLocation == null || uniqueLocation.equals(ignorePropertyCase(part))) ? isUnique : false;
if (!geoFields.isEmpty()) {
Assert.isTrue(isUnique, "Different location fields are used - Distance is ambiguous");
Expand All @@ -398,8 +397,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
final String[] templateAndProperty = createPredicateTemplateAndPropertyString(part);
final String template = templateAndProperty[0];
final String property = templateAndProperty[1];
Criteria criteria = null;
final boolean checkUnique = part.getProperty().toDotPath().split(".").length <= 1;
final boolean checkUnique = part.getProperty().toDotPath().split("\\.").length <= 1;
Class<?> type = part.getProperty().getType();

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

Criteria criteria = null;
switch (part.getType()) {
case SIMPLE_PROPERTY:
criteria = Criteria.eql(ignorePropertyCase(part, property), bind(part, iterator));
Expand All @@ -431,7 +430,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
break;
case EXISTS:
final String document = property.substring(0, property.lastIndexOf("."));
final String attribute = property.substring(property.lastIndexOf(".") + 1, property.length());
final String attribute = property.substring(property.lastIndexOf(".") + 1);
criteria = Criteria.exists(document, attribute);
break;
case BEFORE:
Expand Down Expand Up @@ -492,10 +491,9 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
if (nearValue instanceof Point point) {
checkUniquePoint(point);
} else {
bindingCounter = binding.bind(nearValue, shouldIgnoreCase(part), null, point -> checkUniquePoint(point),
bindingCounter = binding.bind(nearValue, shouldIgnoreCase(part), null, this::checkUniquePoint,
bindingCounter);
}
criteria = null;
break;
case WITHIN:
if (checkUnique) {
Expand Down Expand Up @@ -588,24 +586,24 @@ private int bind(final Part part, final Iterator<Object> iterator, final Boolean

private int bind(final Part part, final Object value, final Boolean borderStatus) {
final int index = bindingCounter;
bindingCounter = binding.bind(value, shouldIgnoreCase(part), borderStatus, point -> checkUniquePoint(point),
bindingCounter = binding.bind(value, shouldIgnoreCase(part), borderStatus, this::checkUniquePoint,
bindingCounter);
return index;
}

private int bind(final Object value) {
final int index = bindingCounter;
bindingCounter = binding.bind(value, false, null, point -> checkUniquePoint(point), bindingCounter);
bindingCounter = binding.bind(value, false, null, this::checkUniquePoint, bindingCounter);
return index;
}

private void bindPoint(final Part part, final Object value, final boolean toGeoJson) {
bindingCounter = binding.bindPoint(value, shouldIgnoreCase(part), point -> checkUniquePoint(point),
bindingCounter = binding.bindPoint(value, shouldIgnoreCase(part), this::checkUniquePoint,
bindingCounter, toGeoJson);
}

private void bindCircle(final Part part, final Object value, final boolean toGeoJson) {
bindingCounter = binding.bindCircle(value, shouldIgnoreCase(part), point -> checkUniquePoint(point),
bindingCounter = binding.bindCircle(value, shouldIgnoreCase(part), this::checkUniquePoint,
bindingCounter, toGeoJson);
}

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

private void bindRing(final Part part, final Object value, final boolean toGeoJson) {
bindingCounter = binding.bindRing(value, shouldIgnoreCase(part), point -> checkUniquePoint(point),
bindingCounter = binding.bindRing(value, shouldIgnoreCase(part), this::checkUniquePoint,
bindingCounter, toGeoJson);
}

Expand All @@ -632,7 +630,6 @@ private void collectWithCollections(final PropertyPath propertyPath) {
propertyPath.stream()
.filter(property -> {
ArangoPersistentProperty p = context.getPersistentPropertyPath(property).getBaseProperty();
if (p == null) return false;
Optional<Ref> ref = p.getRef();
Optional<Relations> rels = p.getRelations();
return ref.isPresent() || rels.isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.arangodb.springframework.core.template.CollectionCallback;
import com.arangodb.springframework.repository.query.QueryTransactionBridge;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.transaction.*;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
import org.springframework.transaction.support.DefaultTransactionStatus;
Expand Down Expand Up @@ -80,7 +79,7 @@ public void afterPropertiesSet() {
* Creates a new transaction object. Any holder bound will be reused.
*/
@Override
protected ArangoTransactionObject doGetTransaction() {
protected Object doGetTransaction() {
ArangoTransactionHolder holder = (ArangoTransactionHolder) TransactionSynchronizationManager.getResource(this);
try {
return new ArangoTransactionObject(operations.db(), CollectionCallback.fromOperations(operations), getDefaultTimeout(), holder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public TransactionAttributeTemplate(PlatformTransactionManager transactionManage

public TransactionAttributeTemplate(PlatformTransactionManager transactionManager, TransactionDefinition transactionDefinition) {
super(transactionManager, transactionDefinition);
if (transactionDefinition instanceof TransactionAttribute) {
TransactionAttribute transactionAttribute = (TransactionAttribute) transactionDefinition;
if (transactionDefinition instanceof TransactionAttribute transactionAttribute) {
setQualifier(transactionAttribute.getQualifier());
setLabels(transactionAttribute.getLabels());
setRollbackOn(transactionAttribute::rollbackOn);
Expand Down

0 comments on commit 63b0557

Please sign in to comment.