diff --git a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java index a55d6c7ff..508d6c425 100644 --- a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java +++ b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java @@ -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); } diff --git a/src/main/java/com/arangodb/springframework/core/template/CollectionCacheValue.java b/src/main/java/com/arangodb/springframework/core/template/CollectionCacheValue.java index bbaece017..5a8e4ebb8 100644 --- a/src/main/java/com/arangodb/springframework/core/template/CollectionCacheValue.java +++ b/src/main/java/com/arangodb/springframework/core/template/CollectionCacheValue.java @@ -30,6 +30,7 @@ public Collection> getEntities() { public Collection getIndexes() { return indexes; } + public boolean addEntityClass(final Class entityClass) { return entities.add(entityClass); } diff --git a/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java b/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java index 87f0b5d6b..ae0902cec 100644 --- a/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java +++ b/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java @@ -257,10 +257,6 @@ public Iterator iterator() { */ @Override public Page findAll(final Pageable pageable) { - if (pageable == null) { - LOGGER.debug("Pageable in findAll(Pageable) is null"); - } - final ArangoCursor result = findAllInternal(pageable, null, new HashMap<>()); final List content = result.asListRemaining(); return new PageImpl<>(content, pageable, ((Number) result.getStats().getFullCount()).longValue()); @@ -342,7 +338,7 @@ public long count(final Example example) { final Map 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 cursor = arangoTemplate.query(query, bindVars, defaultQueryOptions(), Long.class); diff --git a/src/main/java/com/arangodb/springframework/repository/query/AbstractArangoQuery.java b/src/main/java/com/arangodb/springframework/repository/query/AbstractArangoQuery.java index 56647bfd7..01c78f8c6 100644 --- a/src/main/java/com/arangodb/springframework/repository/query/AbstractArangoQuery.java +++ b/src/main/java/com/arangodb/springframework/repository/query/AbstractArangoQuery.java @@ -20,7 +20,6 @@ package com.arangodb.springframework.repository.query; -import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -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()); }); } diff --git a/src/main/java/com/arangodb/springframework/repository/query/DerivedArangoQuery.java b/src/main/java/com/arangodb/springframework/repository/query/DerivedArangoQuery.java index f36dfb936..d970c5d47 100644 --- a/src/main/java/com/arangodb/springframework/repository/query/DerivedArangoQuery.java +++ b/src/main/java/com/arangodb/springframework/repository/query/DerivedArangoQuery.java @@ -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; diff --git a/src/main/java/com/arangodb/springframework/repository/query/QueryTransactionBridge.java b/src/main/java/com/arangodb/springframework/repository/query/QueryTransactionBridge.java index 621b9e297..c22fca964 100644 --- a/src/main/java/com/arangodb/springframework/repository/query/QueryTransactionBridge.java +++ b/src/main/java/com/arangodb/springframework/repository/query/QueryTransactionBridge.java @@ -33,7 +33,7 @@ */ public class QueryTransactionBridge { - private static final ThreadLocal, String>> CURRENT_TRANSACTION = new NamedInheritableThreadLocal, String>>("ArangoTransactionBegin") { + private static final ThreadLocal, String>> CURRENT_TRANSACTION = new NamedInheritableThreadLocal<>("ArangoTransactionBegin") { @Override protected Function, String> initialValue() { return any -> null; diff --git a/src/main/java/com/arangodb/springframework/repository/query/StringBasedArangoQuery.java b/src/main/java/com/arangodb/springframework/repository/query/StringBasedArangoQuery.java index 07cd9b501..bacf9c113 100644 --- a/src/main/java/com/arangodb/springframework/repository/query/StringBasedArangoQuery.java +++ b/src/main/java/com/arangodb/springframework/repository/query/StringBasedArangoQuery.java @@ -171,7 +171,7 @@ private void extractBindVars(final ArangoParameterAccessor accessor, final Map bindVars.put(name, value)); } else { final String key = String.valueOf(param.getIndex()); final String collectionKey = "@" + key; diff --git a/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java b/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java index 1cc8cfa03..d6e8c8b8b 100644 --- a/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java +++ b/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java @@ -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 @@ -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; @@ -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(" "); } @@ -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); @@ -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()) { @@ -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()) { @@ -274,11 +273,11 @@ 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); @@ -286,22 +285,22 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) { 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 @@ -312,7 +311,7 @@ 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 { @@ -320,20 +319,20 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) { // 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())); } } } @@ -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"); @@ -398,8 +397,7 @@ private Criteria createCriteria(final Part part, final Iterator 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 @@ -410,6 +408,7 @@ private Criteria createCriteria(final Part part, final Iterator iterator hasGeoJsonType = true; } + Criteria criteria = null; switch (part.getType()) { case SIMPLE_PROPERTY: criteria = Criteria.eql(ignorePropertyCase(part, property), bind(part, iterator)); @@ -431,7 +430,7 @@ private Criteria createCriteria(final Part part, final Iterator 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: @@ -492,10 +491,9 @@ private Criteria createCriteria(final Part part, final Iterator 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) { @@ -588,24 +586,24 @@ private int bind(final Part part, final Iterator 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); } @@ -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); } @@ -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 = p.getRef(); Optional rels = p.getRelations(); return ref.isPresent() || rels.isPresent(); diff --git a/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java b/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java index 8a1fe19f6..324be60d6 100644 --- a/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java +++ b/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java @@ -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; @@ -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); diff --git a/src/main/java/com/arangodb/springframework/transaction/TransactionAttributeTemplate.java b/src/main/java/com/arangodb/springframework/transaction/TransactionAttributeTemplate.java index 4f75c851e..0f7afb3b6 100644 --- a/src/main/java/com/arangodb/springframework/transaction/TransactionAttributeTemplate.java +++ b/src/main/java/com/arangodb/springframework/transaction/TransactionAttributeTemplate.java @@ -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);