Skip to content

Commit

Permalink
fix merge errors and unify parameter order with options
Browse files Browse the repository at this point in the history
  • Loading branch information
aburmeis committed Sep 9, 2024
1 parent 9320edd commit 7e6f2f3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ default <T> ArangoCursor<T> query(String query, Map<String, Object> 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
Expand Down Expand Up @@ -189,7 +191,9 @@ <T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteAllById(
* @return information about the documents
* @throws DataAccessException
*/
MultiDocumentEntity<DocumentDeleteEntity<?>> deleteAllById(Iterable<?> ids, Class<?> entityClass) throws DataAccessException;
default <T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteAllById(Iterable<?> ids, Class<T> entityClass) throws DataAccessException {
return deleteAllById(ids, new DocumentDeleteOptions(), entityClass);
}

/**
* Deletes the document with the given {@code id} from a collection.
Expand Down Expand Up @@ -365,12 +369,9 @@ default <T> DocumentUpdateEntity<T> 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
*/
Expand All @@ -393,31 +394,28 @@ default <T> Optional<T> find(Object id, Class<T> 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
*/
<T> Iterable<T> findAll(Class<T> entityClass, DocumentReadOptions options) throws DataAccessException;
<T> Iterable<T> findAll(DocumentReadOptions options, Class<T> entityClass) throws DataAccessException;

default <T> Iterable<T> findAll(Class<T> 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
*/
<T> Iterable<T> findAll(final Iterable<?> ids, final Class<T> entityClass, DocumentReadOptions options) throws DataAccessException;
<T> Iterable<T> findAll(final Iterable<?> ids, DocumentReadOptions options, final Class<T> entityClass) throws DataAccessException;

default <T> Iterable<T> findAll(final Iterable<?> ids, final Class<T> entityClass) throws DataAccessException {
return findAll(ids, entityClass, new DocumentReadOptions());
return findAll(ids, new DocumentReadOptions(), entityClass);
}

/**
Expand Down Expand Up @@ -512,17 +510,15 @@ default <T> Iterable<T> repsertAll(Iterable<T> values, Class<? super T> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
*/
public class EdgeFromResolver extends AbstractResolver implements RelationResolver<From> {

private final ArangoOperations template;

public EdgeFromResolver(final ArangoOperations template, QueryTransactionBridge transactionBridge) {
super(template, transactionBridge);
super(template.getConverter().getConversionService(), transactionBridge);
this.template = template;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
*/
public class EdgeToResolver extends AbstractResolver implements RelationResolver<To> {

private final ArangoOperations template;

public EdgeToResolver(final ArangoOperations template, QueryTransactionBridge transactionBridge) {
super(template, transactionBridge);
super(template.getConverter().getConversionService(), transactionBridge);
this.template = template;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,14 @@ public <T> Optional<T> find(final Object id, final Class<T> entityClass, final D
}

@Override
public <T> Iterable<T> findAll(final Class<T> entityClass, DocumentReadOptions options) throws DataAccessException {
public <T> Iterable<T> findAll(DocumentReadOptions options, final Class<T> entityClass) throws DataAccessException {
final String query = "FOR entity IN @@col RETURN entity";
final Map<String, Object> bindVars = Collections.singletonMap("@col", entityClass);
return query(query, bindVars, asQueryOptions(options), entityClass).asListRemaining();
}

@Override
public <T> Iterable<T> findAll(final Iterable<?> ids, final Class<T> entityClass, DocumentReadOptions options)
public <T> Iterable<T> findAll(final Iterable<?> ids, DocumentReadOptions options, final Class<T> entityClass)
throws DataAccessException {
try {
final Collection<String> keys = new ArrayList<>();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -56,8 +54,6 @@
@SuppressWarnings({ "rawtypes", "unchecked" })
public class SimpleArangoRepository<T, ID> implements ArangoRepository<T, ID> {

private static final Logger LOGGER = LoggerFactory.getLogger(SimpleArangoRepository.class);

private final ArangoTemplate arangoTemplate;
private final ArangoConverter converter;
private final ArangoMappingContext mappingContext;
Expand Down Expand Up @@ -108,7 +104,7 @@ public <S extends T> S save(final S entity) {
*/
@Override
public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
Iterable<S> saved = arangoTemplate.repsertAll(entities, domainClass, defaultQueryOptions());
Iterable<S> saved = arangoTemplate.repsertAll(entities, defaultQueryOptions(), domainClass);
return returnOriginalEntities ? entities : saved;
}

Expand All @@ -131,7 +127,7 @@ public Optional<T> findById(final ID id) {
*/
@Override
public boolean existsById(final ID id) {
return arangoTemplate.exists(id, domainClass, defaultExistsOptions());
return arangoTemplate.exists(id, defaultExistsOptions(), domainClass);
}

/**
Expand All @@ -141,7 +137,7 @@ public boolean existsById(final ID id) {
*/
@Override
public Iterable<T> findAll() {
return arangoTemplate.findAll(domainClass, defaultReadOptions());
return arangoTemplate.findAll(defaultReadOptions(), domainClass);
}

/**
Expand All @@ -153,7 +149,7 @@ public Iterable<T> findAll() {
*/
@Override
public Iterable<T> findAllById(final Iterable<ID> ids) {
return arangoTemplate.findAll(ids, domainClass, defaultReadOptions());
return arangoTemplate.findAll(ids, defaultReadOptions(), domainClass);
}

/**
Expand All @@ -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
}
Expand All @@ -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);
}
Expand All @@ -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<? extends ID> ids) {
MultiDocumentEntity<DocumentDeleteEntity<?>> res = arangoTemplate.deleteAllById(ids, domainClass, defaultDeleteOptions());
MultiDocumentEntity<DocumentDeleteEntity<T>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 7e6f2f3

Please sign in to comment.