Skip to content

Commit aadc293

Browse files
authored
Fix delete with revision in ArangoRepository (#317)
* test: CrudRepository.delete() and CrudRepository.deleteAll() should throw OptimisticLockingFailureException * fixed delete with _rev in ArangoRepository * fix maven-surefire-report-plugin version
1 parent 59ef714 commit aadc293

File tree

12 files changed

+305
-143
lines changed

12 files changed

+305
-143
lines changed

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
<properties>
6363
<java-module-name>com.arangodb.springframework</java-module-name>
64-
<arangodb.version>7.7.1</arangodb.version>
64+
<arangodb.version>7.8.0</arangodb.version>
6565

6666
<!-- enforce dependencies convergence -->
6767
<slf4j>2.0.13</slf4j>
@@ -220,6 +220,15 @@
220220

221221
</plugins>
222222

223+
<pluginManagement>
224+
<plugins>
225+
<plugin>
226+
<groupId>org.apache.maven.plugins</groupId>
227+
<artifactId>maven-surefire-report-plugin</artifactId>
228+
<version>3.4.0</version>
229+
</plugin>
230+
</plugins>
231+
</pluginManagement>
223232
</build>
224233

225234
<dependencies>

src/main/java/com/arangodb/springframework/core/convert/ArangoConverter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ void readProperty(
5252

5353
ConversionService getConversionService();
5454

55+
<T> T convertIfNecessary(Object source, Class<T> type);
56+
5557
String convertId(Object id);
5658

5759
}

src/main/java/com/arangodb/springframework/core/convert/DefaultArangoConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ public boolean isEntityType(final Class<?> type) {
829829
}
830830

831831
@SuppressWarnings("unchecked")
832-
private <T> T convertIfNecessary(final Object source, final Class<T> type) {
832+
@Override
833+
public <T> T convertIfNecessary(final Object source, final Class<T> type) {
833834
return (T) (source == null ? null
834835
: type.isAssignableFrom(source.getClass()) ? source : conversionService.convert(source, type));
835836
}

src/main/java/com/arangodb/springframework/core/template/ArangoTemplate.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ private String determineDocumentKeyFromId(final Object id) {
239239
return MetadataUtils.determineDocumentKeyFromId(converter.convertId(id));
240240
}
241241

242+
public RuntimeException translateException(RuntimeException e) {
243+
return DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
244+
}
245+
242246
@Override
243247
public ArangoDB driver() {
244248
return arango;
@@ -252,7 +256,7 @@ public ArangoDBVersion getVersion() throws DataAccessException {
252256
}
253257
return version;
254258
} catch (final ArangoDBException e) {
255-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
259+
throw translateException(e);
256260
}
257261
}
258262

@@ -280,7 +284,7 @@ public <T> ArangoCursor<T> query(final String query, final Map<String, Object> b
280284
ArangoCursor<T> cursor = db().query(query, entityClass, bindVars == null ? null : prepareBindVars(bindVars), options);
281285
return new ArangoExtCursor<>(cursor, entityClass, eventPublisher);
282286
} catch (final ArangoDBException e) {
283-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
287+
throw translateException(e);
284288
}
285289
}
286290

@@ -309,7 +313,7 @@ public <T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteAll(
309313
try {
310314
result = _collection(entityClass).deleteDocuments(toList(values), options, entityClass);
311315
} catch (final ArangoDBException e) {
312-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
316+
throw translateException(e);
313317
}
314318

315319
potentiallyEmitAfterDeleteEvent(values, entityClass, result);
@@ -327,8 +331,14 @@ public MultiDocumentEntity<DocumentDeleteEntity<?>> deleteAll(
327331

328332
@Override
329333
public <T> MultiDocumentEntity<DocumentDeleteEntity<T>> deleteAllById(Iterable<?> ids, DocumentDeleteOptions options, Class<T> entityClass) throws DataAccessException {
334+
if (ids == null) {
335+
throw new IllegalArgumentException("ids must not be null");
336+
}
330337
ArrayList<String> convertedIds = new ArrayList<>();
331338
for (Object id : ids) {
339+
if (id == null) {
340+
throw new IllegalArgumentException("id must not be null");
341+
}
332342
convertedIds.add(converter.convertId(id));
333343
}
334344
return deleteAll(convertedIds, options, entityClass);
@@ -350,7 +360,7 @@ public <T> DocumentDeleteEntity<T> delete(final Object id, final DocumentDeleteO
350360
try {
351361
result = _collection(entityClass, id).deleteDocument(determineDocumentKeyFromId(id), options, entityClass);
352362
} catch (final ArangoDBException e) {
353-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
363+
throw translateException(e);
354364
}
355365

356366
potentiallyEmitEvent(new AfterDeleteEvent<>(id, entityClass));
@@ -375,7 +385,7 @@ public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> updateAll(
375385
try {
376386
result = _collection(entityClass).updateDocuments(toList(values), options, entityClass);
377387
} catch (final ArangoDBException e) {
378-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
388+
throw translateException(e);
379389
}
380390

381391
updateDBFields(values, result);
@@ -402,7 +412,7 @@ public <T> DocumentUpdateEntity<T> update(final Object id, final T value, final
402412
try {
403413
result = _collection(value.getClass(), id).updateDocument(determineDocumentKeyFromId(id), value, options);
404414
} catch (final ArangoDBException e) {
405-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
415+
throw translateException(e);
406416
}
407417

408418
updateDBFields(value, result);
@@ -428,7 +438,7 @@ public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceAll(
428438
try {
429439
result = _collection(entityClass).replaceDocuments(toList(values), options, entityClass);
430440
} catch (final ArangoDBException e) {
431-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
441+
throw translateException(e);
432442
}
433443

434444
updateDBFields(values, result);
@@ -454,7 +464,7 @@ public <T> DocumentUpdateEntity<T> replace(final Object id, final T value, final
454464
try {
455465
result = _collection(value.getClass(), id).replaceDocument(determineDocumentKeyFromId(id), value, options);
456466
} catch (final ArangoDBException e) {
457-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
467+
throw translateException(e);
458468
}
459469

460470
updateDBFields(value, result);
@@ -477,7 +487,7 @@ public <T> Optional<T> find(final Object id, final Class<T> entityClass, final D
477487
}
478488
return Optional.ofNullable(res);
479489
} catch (final ArangoDBException e) {
480-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
490+
throw translateException(e);
481491
}
482492
}
483493

@@ -507,7 +517,7 @@ public <T> Iterable<T> findAll(final Iterable<?> ids, final Class<T> entityClass
507517
}
508518
return docs;
509519
} catch (final ArangoDBException e) {
510-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
520+
throw translateException(e);
511521
}
512522
}
513523

@@ -521,7 +531,7 @@ public <T> MultiDocumentEntity<DocumentCreateEntity<T>> insertAll(
521531
try {
522532
result = _collection(entityClass).insertDocuments(toList(values), options, entityClass);
523533
} catch (final ArangoDBException e) {
524-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
534+
throw translateException(e);
525535
}
526536

527537
updateDBFields(values, result);
@@ -543,7 +553,7 @@ public <T> DocumentCreateEntity<T> insert(final T value, final DocumentCreateOpt
543553
try {
544554
result = _collection(value.getClass()).insertDocument(value, options);
545555
} catch (final ArangoDBException e) {
546-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
556+
throw translateException(e);
547557
}
548558

549559
updateDBFields(value, result);
@@ -576,7 +586,7 @@ public <T> T repsert(final T value) throws DataAccessException {
576586
);
577587
result = it.hasNext() ? it.next() : null;
578588
} catch (final ArangoDBException e) {
579-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
589+
throw translateException(e);
580590
}
581591

582592
updateDBFieldsFromObject(value, result);
@@ -606,7 +616,7 @@ public <T> Iterable<T> repsertAll(final Iterable<T> values, final Class<? super
606616
entityClass
607617
).asListRemaining();
608618
} catch (final ArangoDBException e) {
609-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
619+
throw translateException(e);
610620
}
611621

612622
updateDBFieldsFromObjects(values, result);
@@ -694,7 +704,7 @@ public boolean exists(final Object id, final Class<?> entityClass) throws DataAc
694704
try {
695705
return _collection(entityClass).documentExists(determineDocumentKeyFromId(id));
696706
} catch (final ArangoDBException e) {
697-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
707+
throw translateException(e);
698708
}
699709
}
700710

@@ -704,7 +714,7 @@ public void dropDatabase() throws DataAccessException {
704714
try {
705715
db.drop();
706716
} catch (final ArangoDBException e) {
707-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
717+
throw translateException(e);
708718
}
709719
databaseCache.remove(db.name());
710720
collectionCache.keySet().stream().filter(key -> key.getDb().equals(db.name()))
@@ -741,7 +751,7 @@ public Iterable<UserEntity> getUsers() throws DataAccessException {
741751
try {
742752
return arango.getUsers();
743753
} catch (final ArangoDBException e) {
744-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
754+
throw translateException(e);
745755
}
746756
}
747757

src/main/java/com/arangodb/springframework/core/template/DefaultCollectionOperations.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void drop() throws DataAccessException {
6767
try {
6868
collection.drop();
6969
} catch (final ArangoDBException e) {
70-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
70+
throw translateException(e);
7171
}
7272
}
7373

@@ -76,7 +76,7 @@ public void truncate() throws DataAccessException {
7676
try {
7777
collection.truncate();
7878
} catch (final ArangoDBException e) {
79-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
79+
throw translateException(e);
8080
}
8181
}
8282

@@ -86,7 +86,7 @@ public long count() throws DataAccessException {
8686
final Long count = collection.count().getCount();
8787
return count != null ? count : -1L;
8888
} catch (final ArangoDBException e) {
89-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
89+
throw translateException(e);
9090
}
9191
}
9292

@@ -95,7 +95,7 @@ public CollectionPropertiesEntity getProperties() throws DataAccessException {
9595
try {
9696
return collection.getProperties();
9797
} catch (final ArangoDBException e) {
98-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
98+
throw translateException(e);
9999
}
100100
}
101101

@@ -104,7 +104,7 @@ public Collection<IndexEntity> getIndexes() throws DataAccessException {
104104
try {
105105
return collection.getIndexes();
106106
} catch (final ArangoDBException e) {
107-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
107+
throw translateException(e);
108108
}
109109
}
110110

@@ -114,7 +114,7 @@ public IndexEntity ensurePersistentIndex(final Iterable<String> fields, final Pe
114114
try {
115115
return collection.ensurePersistentIndex(fields, options);
116116
} catch (final ArangoDBException e) {
117-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
117+
throw translateException(e);
118118
}
119119
}
120120

@@ -124,7 +124,7 @@ public IndexEntity ensureGeoIndex(final Iterable<String> fields, final GeoIndexO
124124
try {
125125
return collection.ensureGeoIndex(fields, options);
126126
} catch (final ArangoDBException e) {
127-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
127+
throw translateException(e);
128128
}
129129
}
130130

@@ -135,7 +135,7 @@ public IndexEntity ensureFulltextIndex(final Iterable<String> fields, final Full
135135
try {
136136
return collection.ensureFulltextIndex(fields, options);
137137
} catch (final ArangoDBException e) {
138-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
138+
throw translateException(e);
139139
}
140140
}
141141

@@ -144,7 +144,7 @@ public IndexEntity ensureTtlIndex(Iterable<String> fields, TtlIndexOptions optio
144144
try {
145145
return collection.ensureTtlIndex(fields, options);
146146
} catch (final ArangoDBException e) {
147-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
147+
throw translateException(e);
148148
}
149149
}
150150

@@ -153,7 +153,7 @@ public void dropIndex(final String id) throws DataAccessException {
153153
try {
154154
collection.deleteIndex(id);
155155
} catch (final ArangoDBException e) {
156-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
156+
throw translateException(e);
157157
}
158158
}
159159

@@ -162,7 +162,7 @@ public void grantAccess(final String username, final Permissions permissions) {
162162
try {
163163
collection.grantAccess(username, permissions);
164164
} catch (final ArangoDBException e) {
165-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
165+
throw translateException(e);
166166
}
167167
}
168168

@@ -171,7 +171,7 @@ public void resetAccess(final String username) {
171171
try {
172172
collection.resetAccess(username);
173173
} catch (final ArangoDBException e) {
174-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
174+
throw translateException(e);
175175
}
176176
}
177177

@@ -180,8 +180,12 @@ public Permissions getPermissions(final String username) throws DataAccessExcept
180180
try {
181181
return collection.getPermissions(username);
182182
} catch (final ArangoDBException e) {
183-
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
183+
throw translateException(e);
184184
}
185185
}
186186

187+
private RuntimeException translateException(RuntimeException e) {
188+
return DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
189+
}
190+
187191
}

0 commit comments

Comments
 (0)