2222
2323import com .arangodb .ArangoCursor ;
2424import com .arangodb .model .AqlQueryOptions ;
25+ import com .arangodb .model .DocumentDeleteOptions ;
26+ import com .arangodb .model .DocumentExistsOptions ;
27+ import com .arangodb .model .DocumentReadOptions ;
2528import com .arangodb .springframework .core .ArangoOperations ;
2629import com .arangodb .springframework .core .mapping .ArangoMappingContext ;
2730import com .arangodb .springframework .core .util .AqlUtils ;
@@ -75,7 +78,7 @@ public SimpleArangoRepository(final ArangoOperations arangoOperations, final Cla
7578 */
7679 @ Override
7780 public <S extends T > S save (final S entity ) {
78- arangoOperations .repsert (entity );
81+ arangoOperations .repsert (entity , defaultQueryOptions () );
7982 return entity ;
8083 }
8184
@@ -88,7 +91,7 @@ public <S extends T> S save(final S entity) {
8891 */
8992 @ Override
9093 public <S extends T > Iterable <S > saveAll (final Iterable <S > entities ) {
91- arangoOperations .repsert (entities , domainClass );
94+ arangoOperations .repsert (entities , domainClass , defaultQueryOptions () );
9295 return entities ;
9396 }
9497
@@ -100,7 +103,7 @@ public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
100103 */
101104 @ Override
102105 public Optional <T > findById (final ID id ) {
103- return arangoOperations .find (id , domainClass );
106+ return arangoOperations .find (id , domainClass , defaultReadOptions () );
104107 }
105108
106109 /**
@@ -111,7 +114,7 @@ public Optional<T> findById(final ID id) {
111114 */
112115 @ Override
113116 public boolean existsById (final ID id ) {
114- return arangoOperations .exists (id , domainClass );
117+ return arangoOperations .exists (id , domainClass , defaultExistsOptions () );
115118 }
116119
117120 /**
@@ -121,7 +124,7 @@ public boolean existsById(final ID id) {
121124 */
122125 @ Override
123126 public Iterable <T > findAll () {
124- return arangoOperations .findAll (domainClass );
127+ return arangoOperations .findAll (domainClass , defaultReadOptions () );
125128 }
126129
127130 /**
@@ -133,7 +136,7 @@ public Iterable<T> findAll() {
133136 */
134137 @ Override
135138 public Iterable <T > findAllById (final Iterable <ID > ids ) {
136- return arangoOperations .find (ids , domainClass );
139+ return arangoOperations .find (ids , domainClass , defaultReadOptions () );
137140 }
138141
139142 /**
@@ -154,7 +157,7 @@ public long count() {
154157 */
155158 @ Override
156159 public void deleteById (final ID id ) {
157- arangoOperations .delete (id , domainClass );
160+ arangoOperations .delete (id , domainClass , defaultDeleteOptions () );
158161 }
159162
160163 /**
@@ -172,15 +175,15 @@ public void delete(final T entity) {
172175 } catch (final IllegalAccessException e ) {
173176 e .printStackTrace ();
174177 }
175- arangoOperations .delete (id , domainClass );
178+ arangoOperations .delete (id , domainClass , defaultDeleteOptions () );
176179 }
177180
178181 /**
179182 * Deletes all instances of the type {@code T} with the given IDs.
180183 * @implNote do not add @Override annotation to keep backwards compatibility with spring-data-commons 2.4
181184 */
182185 public void deleteAllById (Iterable <? extends ID > ids ) {
183- arangoOperations .delete ((Iterable <Object >) ids , domainClass );
186+ arangoOperations .delete ((Iterable <Object >) ids , domainClass , defaultDeleteOptions () );
184187 }
185188
186189 /**
@@ -317,7 +320,7 @@ public <S extends T> long count(final Example<S> example) {
317320 final String filter = predicate .length () == 0 ? "" : " FILTER " + predicate ;
318321 final String query = String .format ("FOR e IN @@col %s COLLECT WITH COUNT INTO length RETURN length" , filter );
319322 arangoOperations .collection (domainClass );
320- final ArangoCursor <Long > cursor = arangoOperations .query (query , bindVars , null , Long .class );
323+ final ArangoCursor <Long > cursor = arangoOperations .query (query , bindVars , defaultQueryOptions () , Long .class );
321324 return cursor .next ();
322325 }
323326
@@ -339,7 +342,7 @@ private <S extends T> ArangoCursor<T> findAllInternal(final Sort sort, @Nullable
339342 final String query = String .format ("FOR e IN @@col %s %s RETURN e" ,
340343 buildFilterClause (example , bindVars ), buildSortClause (sort , "e" ));
341344 arangoOperations .collection (domainClass );
342- return arangoOperations .query (query , bindVars , null , domainClass );
345+ return arangoOperations .query (query , bindVars , defaultQueryOptions () , domainClass );
343346 }
344347
345348 private <S extends T > ArangoCursor <T > findAllInternal (final Pageable pageable , @ Nullable final Example <S > example ,
@@ -349,7 +352,7 @@ private <S extends T> ArangoCursor<T> findAllInternal(final Pageable pageable, @
349352 buildFilterClause (example , bindVars ), buildPageableClause (pageable , "e" ));
350353 arangoOperations .collection (domainClass );
351354 return arangoOperations .query (query , bindVars ,
352- pageable != null && pageable . isPaged () ? new AqlQueryOptions ().fullCount (true ) : null , domainClass );
355+ pageable != null ? defaultQueryOptions ().fullCount (true ) : defaultQueryOptions () , domainClass );
353356 }
354357
355358 private <S extends T > String buildFilterClause (final Example <S > example , final Map <String , Object > bindVars ) {
@@ -372,4 +375,36 @@ private String buildSortClause(final Sort sort, final String varName) {
372375 return sort == null ? "" : AqlUtils .buildSortClause (AqlUtils .toPersistentSort (sort , mappingContext , domainClass ), varName );
373376 }
374377
378+ private DocumentReadOptions defaultReadOptions () {
379+ DocumentReadOptions options = new DocumentReadOptions ();
380+ if (transactionBridge != null ) {
381+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
382+ }
383+ return options ;
384+ }
385+
386+ private AqlQueryOptions defaultQueryOptions () {
387+ AqlQueryOptions options = new AqlQueryOptions ();
388+ if (transactionBridge != null ) {
389+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
390+ }
391+ return options ;
392+ }
393+
394+ private DocumentExistsOptions defaultExistsOptions () {
395+ DocumentExistsOptions options = new DocumentExistsOptions ();
396+ if (transactionBridge != null ) {
397+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
398+ }
399+ return options ;
400+ }
401+
402+ private DocumentDeleteOptions defaultDeleteOptions () {
403+ DocumentDeleteOptions options = new DocumentDeleteOptions ();
404+ if (transactionBridge != null ) {
405+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
406+ }
407+ return options ;
408+ }
409+
375410}
0 commit comments