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 ;
@@ -77,7 +80,7 @@ public SimpleArangoRepository(final ArangoOperations arangoOperations, final Cla
7780 */
7881 @ Override
7982 public <S extends T > S save (final S entity ) {
80- arangoOperations .repsert (entity );
83+ arangoOperations .repsert (entity , defaultQueryOptions () );
8184 return entity ;
8285 }
8386
@@ -90,7 +93,7 @@ public <S extends T> S save(final S entity) {
9093 */
9194 @ Override
9295 public <S extends T > Iterable <S > saveAll (final Iterable <S > entities ) {
93- arangoOperations .repsert (entities , domainClass );
96+ arangoOperations .repsert (entities , domainClass , defaultQueryOptions () );
9497 return entities ;
9598 }
9699
@@ -102,7 +105,7 @@ public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
102105 */
103106 @ Override
104107 public Optional <T > findById (final ID id ) {
105- return arangoOperations .find (id , domainClass );
108+ return arangoOperations .find (id , domainClass , defaultReadOptions () );
106109 }
107110
108111 /**
@@ -113,7 +116,7 @@ public Optional<T> findById(final ID id) {
113116 */
114117 @ Override
115118 public boolean existsById (final ID id ) {
116- return arangoOperations .exists (id , domainClass );
119+ return arangoOperations .exists (id , domainClass , defaultExistsOptions () );
117120 }
118121
119122 /**
@@ -123,7 +126,7 @@ public boolean existsById(final ID id) {
123126 */
124127 @ Override
125128 public Iterable <T > findAll () {
126- return arangoOperations .findAll (domainClass );
129+ return arangoOperations .findAll (domainClass , defaultReadOptions () );
127130 }
128131
129132 /**
@@ -135,7 +138,7 @@ public Iterable<T> findAll() {
135138 */
136139 @ Override
137140 public Iterable <T > findAllById (final Iterable <ID > ids ) {
138- return arangoOperations .find (ids , domainClass );
141+ return arangoOperations .find (ids , domainClass , defaultReadOptions () );
139142 }
140143
141144 /**
@@ -156,7 +159,7 @@ public long count() {
156159 */
157160 @ Override
158161 public void deleteById (final ID id ) {
159- arangoOperations .delete (id , domainClass );
162+ arangoOperations .delete (id , domainClass , defaultDeleteOptions () );
160163 }
161164
162165 /**
@@ -174,15 +177,15 @@ public void delete(final T entity) {
174177 } catch (final IllegalAccessException e ) {
175178 e .printStackTrace ();
176179 }
177- arangoOperations .delete (id , domainClass );
180+ arangoOperations .delete (id , domainClass , defaultDeleteOptions () );
178181 }
179182
180183 /**
181184 * Deletes all instances of the type {@code T} with the given IDs.
182185 * @implNote do not add @Override annotation to keep backwards compatibility with spring-data-commons 2.4
183186 */
184187 public void deleteAllById (Iterable <? extends ID > ids ) {
185- arangoOperations .delete ((Iterable <Object >) ids , domainClass );
188+ arangoOperations .delete ((Iterable <Object >) ids , domainClass , defaultDeleteOptions () );
186189 }
187190
188191 /**
@@ -319,7 +322,7 @@ public <S extends T> long count(final Example<S> example) {
319322 final String filter = predicate .length () == 0 ? "" : " FILTER " + predicate ;
320323 final String query = String .format ("FOR e IN @@col %s COLLECT WITH COUNT INTO length RETURN length" , filter );
321324 arangoOperations .collection (domainClass );
322- final ArangoCursor <Long > cursor = arangoOperations .query (query , bindVars , null , Long .class );
325+ final ArangoCursor <Long > cursor = arangoOperations .query (query , bindVars , defaultQueryOptions () , Long .class );
323326 return cursor .next ();
324327 }
325328
@@ -345,7 +348,7 @@ private <S extends T> ArangoCursor<T> findAllInternal(final Sort sort, @Nullable
345348 final String query = String .format ("FOR e IN @@col %s %s RETURN e" ,
346349 buildFilterClause (example , bindVars ), buildSortClause (sort , "e" ));
347350 arangoOperations .collection (domainClass );
348- return arangoOperations .query (query , bindVars , null , domainClass );
351+ return arangoOperations .query (query , bindVars , defaultQueryOptions () , domainClass );
349352 }
350353
351354 private <S extends T > ArangoCursor <T > findAllInternal (final Pageable pageable , @ Nullable final Example <S > example ,
@@ -355,7 +358,7 @@ private <S extends T> ArangoCursor<T> findAllInternal(final Pageable pageable, @
355358 buildFilterClause (example , bindVars ), buildPageableClause (pageable , "e" ));
356359 arangoOperations .collection (domainClass );
357360 return arangoOperations .query (query , bindVars ,
358- pageable != null ? new AqlQueryOptions ().fullCount (true ) : null , domainClass );
361+ pageable != null ? new AqlQueryOptions ().fullCount (true ) : defaultQueryOptions () , domainClass );
359362 }
360363
361364 private <S extends T > String buildFilterClause (final Example <S > example , final Map <String , Object > bindVars ) {
@@ -383,4 +386,36 @@ private String buildSortClause(final Sort sort, final String varName) {
383386 return sort == null ? "" : AqlUtils .buildSortClause (AqlUtils .toPersistentSort (sort , mappingContext , domainClass ), varName );
384387 }
385388
389+ private DocumentReadOptions defaultReadOptions () {
390+ DocumentReadOptions options = new DocumentReadOptions ();
391+ if (transactionBridge != null ) {
392+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
393+ }
394+ return options ;
395+ }
396+
397+ private AqlQueryOptions defaultQueryOptions () {
398+ AqlQueryOptions options = new AqlQueryOptions ();
399+ if (transactionBridge != null ) {
400+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
401+ }
402+ return options ;
403+ }
404+
405+ private DocumentExistsOptions defaultExistsOptions () {
406+ DocumentExistsOptions options = new DocumentExistsOptions ();
407+ if (transactionBridge != null ) {
408+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
409+ }
410+ return options ;
411+ }
412+
413+ private DocumentDeleteOptions defaultDeleteOptions () {
414+ DocumentDeleteOptions options = new DocumentDeleteOptions ();
415+ if (transactionBridge != null ) {
416+ options .streamTransactionId (transactionBridge .getCurrentTransaction (Collections .singleton (getCollectionName ())));
417+ }
418+ return options ;
419+ }
420+
386421}
0 commit comments