Skip to content

Commit e43356f

Browse files
author
mpv1989
committed
Revert "move ResolverFactory impl from anon. class to own class (#99)"
This reverts commit 3769bfd.
1 parent fa5d0cb commit e43356f

File tree

3 files changed

+83
-114
lines changed

3 files changed

+83
-114
lines changed

src/main/java/com/arangodb/springframework/config/AbstractArangoConfiguration.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
package com.arangodb.springframework.config;
2222

23+
import java.lang.annotation.Annotation;
2324
import java.util.Collections;
25+
import java.util.Optional;
2426
import java.util.Set;
2527

2628
import org.springframework.context.annotation.Bean;
@@ -30,14 +32,24 @@
3032
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
3133

3234
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;
3340
import com.arangodb.springframework.core.ArangoOperations;
3441
import com.arangodb.springframework.core.convert.ArangoConverter;
3542
import com.arangodb.springframework.core.convert.ArangoCustomConversions;
3643
import com.arangodb.springframework.core.convert.ArangoTypeMapper;
3744
import com.arangodb.springframework.core.convert.DefaultArangoConverter;
3845
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;
4051
import com.arangodb.springframework.core.convert.resolver.ResolverFactory;
52+
import com.arangodb.springframework.core.convert.resolver.ToResolver;
4153
import com.arangodb.springframework.core.mapping.ArangoMappingContext;
4254
import com.arangodb.springframework.core.template.ArangoTemplate;
4355

@@ -97,8 +109,40 @@ protected ArangoTypeMapper arangoTypeMapper() throws Exception {
97109
return new DefaultArangoTypeMapper(typeKey(), arangoMappingContext());
98110
}
99111

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+
};
102146
}
103147

104148
}

src/main/java/com/arangodb/springframework/core/convert/resolver/DefaultResolverFactory.java

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
/*
2-
* DISCLAIMER
3-
*
4-
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
5-
*
6-
* Licensed under the Apache License, Version 2.0 (the "License");
7-
* you may not use this file except in compliance with the License.
8-
* You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
12-
* Unless required by applicable law or agreed to in writing, software
13-
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* See the License for the specific language governing permissions and
16-
* limitations under the License.
17-
*
18-
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19-
*/
20-
21-
package com.arangodb.springframework.core.convert.resolver;
22-
23-
import java.lang.annotation.Annotation;
24-
import java.util.Optional;
25-
26-
/**
27-
* @author Mark Vollmary
28-
*
29-
*/
30-
public interface ResolverFactory {
31-
32-
<A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(A annotation);
33-
34-
<A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(A annotation);
35-
36-
}
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
package com.arangodb.springframework.core.convert.resolver;
22+
23+
import java.lang.annotation.Annotation;
24+
import java.util.Optional;
25+
26+
/**
27+
* @author Mark Vollmary
28+
*
29+
*/
30+
public interface ResolverFactory {
31+
32+
<A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(A annotation);
33+
34+
<A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(A annotation);
35+
36+
}

0 commit comments

Comments
 (0)