33 */
44package com .arangodb .springframework .config ;
55
6- import java .lang .annotation .Annotation ;
76import java .util .Collection ;
87import java .util .Collections ;
9- import java .util .Optional ;
108import java .util .Set ;
119
1210import org .springframework .context .annotation .Bean ;
1614import org .springframework .data .mapping .model .PropertyNameFieldNamingStrategy ;
1715
1816import com .arangodb .ArangoDB ;
19- import com .arangodb .ArangoDBException ;
20- import com .arangodb .springframework .annotation .Document ;
21- import com .arangodb .springframework .annotation .Edge ;
22- import com .arangodb .springframework .annotation .From ;
23- import com .arangodb .springframework .annotation .Ref ;
24- import com .arangodb .springframework .annotation .Relations ;
25- import com .arangodb .springframework .annotation .To ;
2617import com .arangodb .springframework .core .ArangoOperations ;
2718import com .arangodb .springframework .core .convert .ArangoConverter ;
2819import com .arangodb .springframework .core .convert .ArangoCustomConversions ;
2920import com .arangodb .springframework .core .convert .ArangoTypeMapper ;
3021import com .arangodb .springframework .core .convert .DefaultArangoConverter ;
3122import com .arangodb .springframework .core .convert .DefaultArangoTypeMapper ;
32- import com .arangodb .springframework .core .convert .resolver .DocumentFromResolver ;
33- import com .arangodb .springframework .core .convert .resolver .DocumentToResolver ;
34- import com .arangodb .springframework .core .convert .resolver .EdgeFromResolver ;
35- import com .arangodb .springframework .core .convert .resolver .EdgeToResolver ;
36- import com .arangodb .springframework .core .convert .resolver .RefResolver ;
37- import com .arangodb .springframework .core .convert .resolver .ReferenceResolver ;
38- import com .arangodb .springframework .core .convert .resolver .RelationResolver ;
39- import com .arangodb .springframework .core .convert .resolver .RelationsResolver ;
23+ import com .arangodb .springframework .core .convert .resolver .DefaultResolverFactory ;
4024import com .arangodb .springframework .core .convert .resolver .ResolverFactory ;
4125import com .arangodb .springframework .core .mapping .ArangoMappingContext ;
4226import com .arangodb .springframework .core .template .ArangoTemplate ;
@@ -102,49 +86,11 @@ default ArangoTypeMapper arangoTypeMapper() throws Exception {
10286 return new DefaultArangoTypeMapper (typeKey (), arangoMappingContext ());
10387 }
10488
89+ @ Bean
10590 default ResolverFactory resolverFactory () {
106- return new ResolverFactory () {
107- @ SuppressWarnings ("unchecked" )
108- @ Override
109- public <A extends Annotation > Optional <ReferenceResolver <A >> getReferenceResolver (final A annotation ) {
110- ReferenceResolver <A > resolver = null ;
111- try {
112- if (annotation instanceof Ref ) {
113- resolver = (ReferenceResolver <A >) new RefResolver (arangoTemplate (), null );
114- }
115- } catch (final Exception e ) {
116- throw new ArangoDBException (e );
117- }
118- return Optional .ofNullable (resolver );
119- }
120-
121- @ SuppressWarnings ("unchecked" )
122- @ Override
123- public <A extends Annotation > Optional <RelationResolver <A >> getRelationResolver (final A annotation ,
124- final Class <? extends Annotation > collectionType ) {
125- RelationResolver <A > resolver = null ;
126- try {
127- if (annotation instanceof From ) {
128- if (collectionType == Edge .class ) {
129- resolver = (RelationResolver <A >) new EdgeFromResolver (arangoTemplate (), null );
130- } else if (collectionType == Document .class ) {
131- resolver = (RelationResolver <A >) new DocumentFromResolver (arangoTemplate (), null );
132- }
133- } else if (annotation instanceof To ) {
134- if (collectionType == Edge .class ) {
135- resolver = (RelationResolver <A >) new EdgeToResolver (arangoTemplate (), null );
136- } else if (collectionType == Document .class ) {
137- resolver = (RelationResolver <A >) new DocumentToResolver (arangoTemplate (), null );
138- }
139- } else if (annotation instanceof Relations ) {
140- resolver = (RelationResolver <A >) new RelationsResolver (arangoTemplate (), null );
141- }
142- } catch (final Exception e ) {
143- throw new ArangoDBException (e );
144- }
145- return Optional .ofNullable (resolver );
146- }
147- };
91+ return RESOLVER_FACTORY_INSTANCE ;
14892 }
14993
94+ ResolverFactory RESOLVER_FACTORY_INSTANCE = new DefaultResolverFactory ();
95+
15096}
0 commit comments