|
20 | 20 |
|
21 | 21 | package com.arangodb.springframework.config; |
22 | 22 |
|
| 23 | +import java.lang.annotation.Annotation; |
23 | 24 | import java.util.Collections; |
| 25 | +import java.util.Optional; |
24 | 26 | import java.util.Set; |
25 | 27 |
|
26 | 28 | import org.springframework.context.annotation.Bean; |
|
30 | 32 | import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy; |
31 | 33 |
|
32 | 34 | import com.arangodb.ArangoDB; |
| 35 | +import com.arangodb.ArangoDBException; |
| 36 | +import com.arangodb.springframework.annotation.From; |
| 37 | +import com.arangodb.springframework.annotation.Ref; |
| 38 | +import com.arangodb.springframework.annotation.Relations; |
| 39 | +import com.arangodb.springframework.annotation.To; |
33 | 40 | import com.arangodb.springframework.core.ArangoOperations; |
34 | 41 | import com.arangodb.springframework.core.convert.ArangoConverter; |
35 | 42 | import com.arangodb.springframework.core.convert.ArangoCustomConversions; |
36 | 43 | import com.arangodb.springframework.core.convert.ArangoTypeMapper; |
37 | 44 | import com.arangodb.springframework.core.convert.DefaultArangoConverter; |
38 | 45 | import com.arangodb.springframework.core.convert.DefaultArangoTypeMapper; |
39 | | -import com.arangodb.springframework.core.convert.resolver.DefaultResolverFactory; |
| 46 | +import com.arangodb.springframework.core.convert.resolver.FromResolver; |
| 47 | +import com.arangodb.springframework.core.convert.resolver.RefResolver; |
| 48 | +import com.arangodb.springframework.core.convert.resolver.ReferenceResolver; |
| 49 | +import com.arangodb.springframework.core.convert.resolver.RelationResolver; |
| 50 | +import com.arangodb.springframework.core.convert.resolver.RelationsResolver; |
40 | 51 | import com.arangodb.springframework.core.convert.resolver.ResolverFactory; |
| 52 | +import com.arangodb.springframework.core.convert.resolver.ToResolver; |
41 | 53 | import com.arangodb.springframework.core.mapping.ArangoMappingContext; |
42 | 54 | import com.arangodb.springframework.core.template.ArangoTemplate; |
43 | 55 |
|
@@ -97,8 +109,40 @@ protected ArangoTypeMapper arangoTypeMapper() throws Exception { |
97 | 109 | return new DefaultArangoTypeMapper(typeKey(), arangoMappingContext()); |
98 | 110 | } |
99 | 111 |
|
100 | | - protected ResolverFactory resolverFactory() throws Exception { |
101 | | - return new DefaultResolverFactory(arangoTemplate()); |
| 112 | + protected ResolverFactory resolverFactory() { |
| 113 | + return new ResolverFactory() { |
| 114 | + @SuppressWarnings("unchecked") |
| 115 | + @Override |
| 116 | + public <A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(final A annotation) { |
| 117 | + ReferenceResolver<A> resolver = null; |
| 118 | + try { |
| 119 | + if (annotation instanceof Ref) { |
| 120 | + resolver = (ReferenceResolver<A>) new RefResolver(arangoTemplate()); |
| 121 | + } |
| 122 | + } catch (final Exception e) { |
| 123 | + throw new ArangoDBException(e); |
| 124 | + } |
| 125 | + return Optional.ofNullable(resolver); |
| 126 | + } |
| 127 | + |
| 128 | + @SuppressWarnings("unchecked") |
| 129 | + @Override |
| 130 | + public <A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(final A annotation) { |
| 131 | + RelationResolver<A> resolver = null; |
| 132 | + try { |
| 133 | + if (annotation instanceof From) { |
| 134 | + resolver = (RelationResolver<A>) new FromResolver(arangoTemplate()); |
| 135 | + } else if (annotation instanceof To) { |
| 136 | + resolver = (RelationResolver<A>) new ToResolver(arangoTemplate()); |
| 137 | + } else if (annotation instanceof Relations) { |
| 138 | + resolver = (RelationResolver<A>) new RelationsResolver(arangoTemplate()); |
| 139 | + } |
| 140 | + } catch (final Exception e) { |
| 141 | + throw new ArangoDBException(e); |
| 142 | + } |
| 143 | + return Optional.ofNullable(resolver); |
| 144 | + } |
| 145 | + }; |
102 | 146 | } |
103 | 147 |
|
104 | 148 | } |
0 commit comments