diff --git a/src/main/java/com/arangodb/springframework/core/ArangoOperations.java b/src/main/java/com/arangodb/springframework/core/ArangoOperations.java index fd290d27..dac51ba1 100644 --- a/src/main/java/com/arangodb/springframework/core/ArangoOperations.java +++ b/src/main/java/com/arangodb/springframework/core/ArangoOperations.java @@ -105,6 +105,8 @@ default ArangoCursor query(String query, Map bindVars, Cl * * @param query * An AQL query string + * @param options + * Additional options that will be passed to the query API, can be null * @param entityClass * The entity type of the result * @return cursor of the results @@ -189,7 +191,9 @@ MultiDocumentEntity> deleteAllById( * @return information about the documents * @throws DataAccessException */ - MultiDocumentEntity> deleteAllById(Iterable ids, Class entityClass) throws DataAccessException; + default MultiDocumentEntity> deleteAllById(Iterable ids, Class entityClass) throws DataAccessException { + return deleteAllById(ids, new DocumentDeleteOptions(), entityClass); + } /** * Deletes the document with the given {@code id} from a collection. @@ -365,12 +369,9 @@ default DocumentUpdateEntity replace(Object id, T value) throws DataAcces /** * Retrieves the document with the given {@code id} from a collection. * - * @param id - * The id or key of the document - * @param entityClass - * The entity class which represents the collection - * @param options - * Additional options, can be null + * @param id The id or key of the document + * @param entityClass The entity class which represents the collection + * @param options Additional options, can be null * @return the document identified by the id * @throws DataAccessException */ @@ -393,31 +394,28 @@ default Optional find(Object id, Class entityClass) throws DataAccessE /** * Retrieves all documents from a collection. * - * @param entityClass - * The entity class which represents the collection + * @param entityClass The entity class which represents the collection * @return the documents * @throws DataAccessException */ - Iterable findAll(Class entityClass, DocumentReadOptions options) throws DataAccessException; + Iterable findAll(DocumentReadOptions options, Class entityClass) throws DataAccessException; default Iterable findAll(Class entityClass) throws DataAccessException { - return findAll(entityClass, new DocumentReadOptions()); + return findAll(new DocumentReadOptions(), entityClass); } /** * Retrieves multiple documents with the given {@code ids} from a collection. * - * @param ids - * The ids or keys of the documents - * @param entityClass - * The entity class which represents the collection + * @param ids The ids or keys of the documents + * @param entityClass The entity class which represents the collection * @return the documents * @throws DataAccessException */ - Iterable findAll(final Iterable ids, final Class entityClass, DocumentReadOptions options) throws DataAccessException; + Iterable findAll(final Iterable ids, DocumentReadOptions options, final Class entityClass) throws DataAccessException; default Iterable findAll(final Iterable ids, final Class entityClass) throws DataAccessException { - return findAll(ids, entityClass, new DocumentReadOptions()); + return findAll(ids, new DocumentReadOptions(), entityClass); } /** @@ -512,17 +510,15 @@ default Iterable repsertAll(Iterable values, Class entityCl /** * Checks whether the document exists by reading a single document head * - * @param id - * The id or key of the document - * @param entityClass - * The entity type representing the collection + * @param id The id or key of the document + * @param entityClass The entity type representing the collection * @return true if the document exists, false if not * @throws DataAccessException */ - boolean exists(Object id, Class entityClass, DocumentExistsOptions options) throws DataAccessException; + boolean exists(Object id, DocumentExistsOptions options, Class entityClass) throws DataAccessException; default boolean exists(Object id, Class entityClass) throws DataAccessException { - return exists(id, entityClass, new DocumentExistsOptions()); + return exists(id, new DocumentExistsOptions(), entityClass); } /** diff --git a/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeFromResolver.java b/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeFromResolver.java index c8157611..71e9e9f3 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeFromResolver.java +++ b/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeFromResolver.java @@ -34,8 +34,11 @@ */ public class EdgeFromResolver extends AbstractResolver implements RelationResolver { + private final ArangoOperations template; + public EdgeFromResolver(final ArangoOperations template, QueryTransactionBridge transactionBridge) { - super(template, transactionBridge); + super(template.getConverter().getConversionService(), transactionBridge); + this.template = template; } @Override diff --git a/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeToResolver.java b/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeToResolver.java index f5d029d2..03d0578b 100644 --- a/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeToResolver.java +++ b/src/main/java/com/arangodb/springframework/core/convert/resolver/EdgeToResolver.java @@ -34,8 +34,11 @@ */ public class EdgeToResolver extends AbstractResolver implements RelationResolver { + private final ArangoOperations template; + public EdgeToResolver(final ArangoOperations template, QueryTransactionBridge transactionBridge) { - super(template, transactionBridge); + super(template.getConverter().getConversionService(), transactionBridge); + this.template = template; } @Override 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 08663926..a55d6c7f 100644 --- a/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java +++ b/src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java @@ -480,14 +480,14 @@ public Optional find(final Object id, final Class entityClass, final D } @Override - public Iterable findAll(final Class entityClass, DocumentReadOptions options) throws DataAccessException { + public Iterable findAll(DocumentReadOptions options, final Class entityClass) throws DataAccessException { final String query = "FOR entity IN @@col RETURN entity"; final Map bindVars = Collections.singletonMap("@col", entityClass); return query(query, bindVars, asQueryOptions(options), entityClass).asListRemaining(); } @Override - public Iterable findAll(final Iterable ids, final Class entityClass, DocumentReadOptions options) + public Iterable findAll(final Iterable ids, DocumentReadOptions options, final Class entityClass) throws DataAccessException { try { final Collection keys = new ArrayList<>(); @@ -678,7 +678,7 @@ private void updateDBFields(final Object value, final DocumentEntity documentEnt } @Override - public boolean exists(final Object id, final Class entityClass, DocumentExistsOptions options) throws DataAccessException { + public boolean exists(final Object id, DocumentExistsOptions options, final Class entityClass) throws DataAccessException { try { boolean transactional = options != null && options.getStreamTransactionId() != null; return _collection(entityClass, transactional).documentExists(determineDocumentKeyFromId(id), options); diff --git a/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java b/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java index 3fd2eaa2..87f0b5d6 100644 --- a/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java +++ b/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java @@ -36,8 +36,6 @@ import com.arangodb.springframework.core.template.ArangoTemplate; import com.arangodb.springframework.core.util.AqlUtils; import com.arangodb.springframework.repository.query.QueryTransactionBridge; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.data.domain.*; import org.springframework.data.repository.query.FluentQuery; @@ -56,8 +54,6 @@ @SuppressWarnings({ "rawtypes", "unchecked" }) public class SimpleArangoRepository implements ArangoRepository { - private static final Logger LOGGER = LoggerFactory.getLogger(SimpleArangoRepository.class); - private final ArangoTemplate arangoTemplate; private final ArangoConverter converter; private final ArangoMappingContext mappingContext; @@ -108,7 +104,7 @@ public S save(final S entity) { */ @Override public Iterable saveAll(final Iterable entities) { - Iterable saved = arangoTemplate.repsertAll(entities, domainClass, defaultQueryOptions()); + Iterable saved = arangoTemplate.repsertAll(entities, defaultQueryOptions(), domainClass); return returnOriginalEntities ? entities : saved; } @@ -131,7 +127,7 @@ public Optional findById(final ID id) { */ @Override public boolean existsById(final ID id) { - return arangoTemplate.exists(id, domainClass, defaultExistsOptions()); + return arangoTemplate.exists(id, defaultExistsOptions(), domainClass); } /** @@ -141,7 +137,7 @@ public boolean existsById(final ID id) { */ @Override public Iterable findAll() { - return arangoTemplate.findAll(domainClass, defaultReadOptions()); + return arangoTemplate.findAll(defaultReadOptions(), domainClass); } /** @@ -153,7 +149,7 @@ public Iterable findAll() { */ @Override public Iterable findAllById(final Iterable ids) { - return arangoTemplate.findAll(ids, domainClass, defaultReadOptions()); + return arangoTemplate.findAll(ids, defaultReadOptions(), domainClass); } /** @@ -175,7 +171,7 @@ public long count() { @Override public void deleteById(final ID id) { try { - arangoTemplate.delete(id, domainClass, defaultDeleteOptions()); + arangoTemplate.delete(id, defaultDeleteOptions(), domainClass); } catch (DocumentNotFoundException unknown) { // silently ignored } @@ -190,14 +186,14 @@ public void deleteById(final ID id) { @Override public void delete(final T entity) { Object id = persistentEntity.getIdentifierAccessor(entity).getRequiredIdentifier(); - DocumentDeleteOptions opts = new DocumentDeleteOptions(); + DocumentDeleteOptions opts = defaultDeleteOptions(); persistentEntity.getRevProperty() .map(persistentEntity.getPropertyAccessor(entity)::getProperty) .map(r -> converter.convertIfNecessary(r, String.class)) .ifPresent(opts::ifMatch); try { - arangoTemplate.delete(id, opts, domainClass, defaultDeleteOptions()); + arangoTemplate.delete(id, opts, domainClass); } catch (DocumentNotFoundException e) { throw new OptimisticLockingFailureException(e.getMessage(), e); } @@ -208,7 +204,7 @@ public void delete(final T entity) { * @implNote do not add @Override annotation to keep backwards compatibility with spring-data-commons 2.4 */ public void deleteAllById(Iterable ids) { - MultiDocumentEntity> res = arangoTemplate.deleteAllById(ids, domainClass, defaultDeleteOptions()); + MultiDocumentEntity> res = arangoTemplate.deleteAllById(ids, defaultDeleteOptions(), domainClass); for (ErrorEntity error : res.getErrors()) { // Entities that aren't found in the persistence store are silently ignored. if (error.getErrorNum() != 1202) { diff --git a/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java b/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java index 52e9ae74..8a1fe19f 100644 --- a/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java +++ b/src/main/java/com/arangodb/springframework/transaction/ArangoTransactionManager.java @@ -114,7 +114,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) thr /** * Commit the current stream transaction. The query bridge is cleared - * afterwards. + * afterward. * * @see ArangoDatabase#commitStreamTransaction(String) * @see QueryTransactionBridge#clearCurrentTransaction() @@ -147,7 +147,7 @@ protected void doCommit(DefaultTransactionStatus status) throws TransactionExcep /** * Roll back the current stream transaction. The query bridge is cleared - * afterwards. + * afterward. * * @see ArangoDatabase#abortStreamTransaction(String) * @see QueryTransactionBridge#clearCurrentTransaction() @@ -169,7 +169,7 @@ protected void doRollback(DefaultTransactionStatus status) throws TransactionExc /** * Check if the transaction object has the bound holder. For new - * transactions the holder will be bound afterwards. + * transactions the holder will be bound afterward. */ @Override protected boolean isExistingTransaction(Object transaction) throws TransactionException { @@ -189,7 +189,6 @@ protected void doSetRollbackOnly(DefaultTransactionStatus status) throws Transac } /** - * Any transaction object is configured according to the definition upfront. * Bind the holder for the first new transaction created. * * @see ArangoTransactionHolder