4949import com .arangodb .springframework .core .util .MetadataUtils ;
5050import com .arangodb .util .MapBuilder ;
5151import com .arangodb .velocypack .VPackSlice ;
52+ import org .slf4j .Logger ;
53+ import org .slf4j .LoggerFactory ;
5254import org .springframework .beans .BeansException ;
5355import org .springframework .context .ApplicationContext ;
5456import org .springframework .context .ApplicationContextAware ;
7274import java .util .Collections ;
7375import java .util .HashMap ;
7476import java .util .Iterator ;
77+ import java .util .List ;
7578import java .util .Map ;
7679import java .util .Map .Entry ;
7780import java .util .Optional ;
@@ -97,6 +100,7 @@ public class ArangoTemplate implements ArangoOperations, CollectionCallback, App
97100 private static final String REPSERT_QUERY = "LET doc = @doc " + REPSERT_QUERY_BODY ;
98101 private static final String REPSERT_MANY_QUERY = "FOR doc IN @docs " + REPSERT_QUERY_BODY ;
99102
103+ private static final Logger LOGGER = LoggerFactory .getLogger (ArangoTemplate .class );
100104 private static final SpelExpressionParser PARSER = new SpelExpressionParser ();
101105
102106 private volatile ArangoDBVersion version ;
@@ -190,7 +194,9 @@ private ArangoCollection _collection(final String name, final ArangoPersistentEn
190194 final ArangoCollection collection = value .getCollection ();
191195 if (persistentEntity != null && !entities .contains (entityClass )) {
192196 value .addEntityClass (entityClass );
193- if (!transactional ) {
197+ if (transactional ) {
198+ LOGGER .debug ("Not ensuring any indexes of collection {} for {} during transaction" , collection .name (), entityClass );
199+ } else {
194200 ensureCollectionIndexes (collection (collection ), persistentEntity );
195201 }
196202 }
@@ -761,11 +767,12 @@ public CollectionOperations collection(final Class<?> entityClass) throws DataAc
761767
762768 @ Override
763769 public CollectionOperations collection (String name ) throws DataAccessException {
764- ArangoPersistentEntity <?> persistentEntity = converter .getMappingContext ().getPersistentEntities ().stream ()
765- .filter (e -> name .equals (e .getCollection ()))
766- .findAny ()
767- .orElse (null );
768- return collection (_collection (name , persistentEntity , persistentEntity == null ? new CollectionCreateOptions () : persistentEntity .getCollectionOptions (), false ));
770+ List <ArangoCollection > collections = converter .getMappingContext ().getPersistentEntities ().stream ()
771+ .filter (persistentEntity -> name .equals (persistentEntity .getCollection ()))
772+ .map (persistentEntity -> _collection (name , persistentEntity , persistentEntity .getCollectionOptions (), false ))
773+ .collect (Collectors .toList ());
774+ ArangoCollection result = collections .isEmpty () ? _collection (name , null , null , false ) : collections .get (0 );
775+ return collection (result );
769776 }
770777
771778 @ Override
0 commit comments