8000 #281 use data access utils for exception handling · aburmeis/spring-data@d051d54 · GitHub
[go: up one dir, main page]

Skip to content

Commit d051d54

Browse files
committed
arangodb#281 use data access utils for exception handling
1 parent fa6ca92 commit d051d54

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.springframework.context.expression.BeanFactoryAccessor;
6565
import org.springframework.context.expression.BeanFactoryResolver;
6666
import org.springframework.dao.DataAccessException;
67+
import org.springframework.dao.support.DataAccessUtils;
6768
import org.springframework.dao.support.PersistenceExceptionTranslator;
6869
import org.springframework.data.mapping.PersistentPropertyAccessor;
6970
import org.springframework.expression.Expression;
@@ -150,10 +151,6 @@ private ArangoDatabase db() {
150151
});
151152
}
152153

153-
private DataAccessException translateExceptionIfPossible(final RuntimeException exception) {
154-
return exceptionTranslator.translateExceptionIfPossible(exception);
155-
}
156-
157154
private ArangoCollection _collection(final String name) {
158155
return _collection(name, null, null);
159156
}
@@ -299,7 +296,7 @@ public ArangoDBVersion getVersion() throws DataAccessException {
299296
}
300297
return version;
301298
} catch (final ArangoDBException e) {
302-
throw translateExceptionIfPossible(e);
299+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
303300
}
304301
}
305302

@@ -349,7 +346,7 @@ public MultiDocumentEntity<? extends DocumentEntity> delete(final Iterable<Objec
349346
try {
350347
result = _collection(entityClass).deleteDocuments(toJsonNodeCollection(values), options, entityClass);
351348
} catch (final ArangoDBException e) {
352-
throw translateExceptionIfPossible(e);
349+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
353350
}
354351

355352
potentiallyEmitAfterDeleteEvent(values, entityClass, result);
@@ -372,7 +369,7 @@ public DocumentEntity delete(final Object id, final Class<?> entityClass, final
372369
try {
373370
result = _collection(entityClass, id).deleteDocument(determineDocumentKeyFromId(id), options, entityClass);
374371
} catch (final ArangoDBException e) {
375-
throw translateExceptionIfPossible(e);
372+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
376373
}
377374

378375
potentiallyEmitEvent(new AfterDeleteEvent<>(id, entityClass));
@@ -394,7 +391,7 @@ public <T> MultiDocumentEntity<? extends DocumentEntity> update(final Iterable<T
394391
try {
395392
result = _collection(entityClass).updateDocuments(toJsonNodeCollection(values), options);
396393
} catch (final ArangoDBException e) {
397-
throw translateExceptionIfPossible(e);
394+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
398395
}
399396

400397
updateDBFields(values, result);
@@ -419,7 +416,7 @@ public DocumentEntity update(final Object id, final Object value, final Document
419416
result = _collection(value.getClass(), id).updateDocument(determineDocumentKeyFromId(id), toJsonNode(value),
420417
options);
421418
} catch (final ArangoDBException e) {
422-
throw translateExceptionIfPossible(e);
419+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
423420
}
424421

425422
updateDBFields(value, result);
@@ -442,7 +439,7 @@ public <T> MultiDocumentEntity<? extends DocumentEntity> replace(final Iterable<
442439
try {
443440
result = _collection(entityClass).replaceDocuments(toJsonNodeCollection(values), options);
444441
} catch (final ArangoDBException e) {
445-
throw translateExceptionIfPossible(e);
442+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
446443
}
447444

448445
updateDBFields(values, result);
@@ -466,7 +463,7 @@ public DocumentEntity replace(final Object id, final Object value, final Documen
466463
result = _collection(value.getClass(), id).replaceDocument(determineDocumentKeyFromId(id), toJsonNode(value),
467464
options);
468465
} catch (final ArangoDBException e) {
469-
throw translateExceptionIfPossible(e);
466+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
470467
}
471468

472469
updateDBFields(value, result);
@@ -487,7 +484,7 @@ public <T> Optional<T> find(final Object id, final Class<T> entityClass, final D
487484
JsonNode.class, options);
488485
return Optional.ofNullable(fromJsonNode(entityClass, doc));
489486
} catch (final ArangoDBException e) {
490-
throw translateExceptionIfPossible(e);
487+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
491488
}
492489
}
493490

@@ -512,7 +509,7 @@ public <T> Iterable<T> find(final Iterable<?> ids, final Class<T> entityClass)
512509
final MultiDocumentEntity<JsonNode> docs = _collection(entityClass).getDocuments(keys, JsonNode.class);
513510
return docs.getDocuments().stream().map(doc -> fromJsonNode(entityClass, doc)).collect(Collectors.toList());
514511
} catch (final ArangoDBException e) {
515-
throw translateExceptionIfPossible(e);
512+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
516513
}
517514
}
518515

@@ -526,7 +523,7 @@ public <T> MultiDocumentEntity<? extends DocumentEntity> insert(final Iterable<T
526523
try {
527524
result = _collection(entityClass).insertDocuments(toJsonNodeCollection(values), options);
528525
} catch (final ArangoDBException e) {
529-
throw translateExceptionIfPossible(e);
526+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
530527
}
531528

532529
updateDBFields(values, result);
@@ -631,7 +628,7 @@ public <T> void repsert(final Iterable<? extends T> values, final Class<T> entit
631628
entityClass
632629
).asListRemaining();
633630
} catch (final ArangoDBException e) {
634-
throw translateExceptionIfPossible(e);
631+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
635632
}
636633

637634
updateDBFieldsFromObjects(values, result);
@@ -711,7 +708,7 @@ public boolean exists(final Object id, final Class<?> entityClass) throws DataAc
711708
try {
712709
return _collection(entityClass).documentExists(determineDocumentKeyFromId(id));
713710
} catch (final ArangoDBException e) {
714-
throw translateExceptionIfPossible(e);
711+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
715712
}
716713
}
717714

@@ -721,7 +718,7 @@ public void dropDatabase() throws DataAccessException {
721718
try {
722719
db.drop();
723720
} catch (final ArangoDBException e) {
724-
throw translateExceptionIfPossible(e);
721+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
725722
}
726723
databaseCache.remove(db.name());
727724
collectionCache.keySet().stream().filter(key -> key.getDb().equals(db.name()))
@@ -758,7 +755,7 @@ public Iterable<UserEntity> getUsers() throws DataAccessException {
758755
try {
759756
return arango.getUsers();
760757
} catch (final ArangoDBException e) {
761-
throw translateExceptionIfPossible(e);
758+
throw DataAccessUtils.translateIfNecessary(e, exceptionTranslator);
762759
}
763760
}
764761

0 commit comments

Comments
 (0)
0