23
23
import java .lang .annotation .Annotation ;
24
24
import java .util .Optional ;
25
25
26
+ import com .arangodb .ArangoDBException ;
26
27
import org .springframework .beans .BeansException ;
27
28
import org .springframework .beans .factory .ObjectProvider ;
28
29
import org .springframework .context .ApplicationContext ;
@@ -45,32 +46,39 @@ public class DefaultResolverFactory implements ResolverFactory, ApplicationConte
45
46
@ SuppressWarnings ("unchecked" )
46
47
@ Override
47
48
public <A extends Annotation > Optional <ReferenceResolver <A >> getReferenceResolver (final A annotation ) {
48
- ReferenceResolver <A > resolver = null ;
49
- if (annotation instanceof Ref ) {
50
- resolver = (ReferenceResolver <A >) new RefResolver (template .getObject (), transactionBridge .getIfUnique ());
49
+ try {
50
+ if (annotation instanceof Ref ) {
51
+ return Optional .of ((ReferenceResolver <A >) new RefResolver (template .getObject (), transactionBridge .getIfUnique ()));
52
+ }
53
+ } catch (final Exception e ) {
54
+ throw new ArangoDBException (e );
51
55
}
52
- return Optional .ofNullable ( resolver );
56
+ return Optional .empty ( );
53
57
}
54
58
55
59
@ SuppressWarnings ("unchecked" )
56
60
@ Override
57
61
public <A extends Annotation > Optional <RelationResolver <A >> getRelationResolver (final A annotation ,
58
62
final Class <? extends Annotation > collectionType ) {
59
63
RelationResolver <A > resolver = null ;
60
- if (annotation instanceof From ) {
61
- if (collectionType == Edge .class ) {
62
- resolver = (RelationResolver <A >) new EdgeFromResolver (template .getObject (), transactionBridge .getIfUnique ());
63
- } else if (collectionType == Document .class ) {
64
- resolver = (RelationResolver <A >) new DocumentFromResolver (template .getObject (), transactionBridge .getIfUnique ());
65
- }
66
- } else if (annotation instanceof To ) {
67
- if (collectionType == Edge .class ) {
68
- resolver = (RelationResolver <A >) new EdgeToResolver (template .getObject (), transactionBridge .getIfUnique ());
69
- } else if (collectionType == Document .class ) {
70
- resolver = (RelationResolver <A >) new DocumentToResolver (template .getObject (), transactionBridge .getIfUnique ());
64
+ try {
65
+ if (annotation instanceof From ) {
66
+ if (collectionType == Edge .class ) {
67
+ resolver = (RelationResolver <A >) new EdgeFromResolver (template .getObject (), null );
68
+ } else if (collectionType == Document .class ) {
69
+ resolver = (RelationResolver <A >) new DocumentFromResolver (template .getObject (), null );
70
+ }
71
+ } else if (annotation instanceof To ) {
72
+ if (collectionType == Edge .class ) {
73
+ resolver = (RelationResolver <A >) new EdgeToResolver (template .getObject (), null );
74
+ } else if (collectionType == Document .class ) {
75
+ resolver = (RelationResolver <A >) new DocumentToResolver (template .getObject (), null );
76
+ }
77
+ } else if (annotation instanceof Relations ) {
78
+ resolver = (RelationResolver <A >) new RelationsResolver (template .getObject (), null );
71
79
}
72
- } else if ( annotation instanceof Relations ) {
73
- resolver = ( RelationResolver < A >) new RelationsResolver ( template . getObject (), transactionBridge . getIfUnique () );
80
+ } catch ( final Exception e ) {
81
+ throw new ArangoDBException ( e );
74
82
}
75
83
return Optional .ofNullable (resolver );
76
84
}
0 commit comments