Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

package com.arangodb.springframework.config;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

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

import com.arangodb.ArangoDB;
import com.arangodb.ArangoDBException;
import com.arangodb.springframework.annotation.From;
import com.arangodb.springframework.annotation.Ref;
import com.arangodb.springframework.annotation.Relations;
import com.arangodb.springframework.annotation.To;
import com.arangodb.springframework.core.ArangoOperations;
import com.arangodb.springframework.core.convert.ArangoConverter;
import com.arangodb.springframework.core.convert.ArangoCustomConversions;
import com.arangodb.springframework.core.convert.ArangoTypeMapper;
import com.arangodb.springframework.core.convert.DefaultArangoConverter;
import com.arangodb.springframework.core.convert.DefaultArangoTypeMapper;
import com.arangodb.springframework.core.convert.resolver.FromResolver;
import com.arangodb.springframework.core.convert.resolver.RefResolver;
import com.arangodb.springframework.core.convert.resolver.ReferenceResolver;
import com.arangodb.springframework.core.convert.resolver.RelationResolver;
import com.arangodb.springframework.core.convert.resolver.RelationsResolver;
import com.arangodb.springframework.core.convert.resolver.DefaultResolverFactory;
import com.arangodb.springframework.core.convert.resolver.ResolverFactory;
import com.arangodb.springframework.core.convert.resolver.ToResolver;
import com.arangodb.springframework.core.mapping.ArangoMappingContext;
import com.arangodb.springframework.core.template.ArangoTemplate;

Expand Down Expand Up @@ -109,40 +97,8 @@ protected ArangoTypeMapper arangoTypeMapper() throws Exception {
return new DefaultArangoTypeMapper(typeKey(), arangoMappingContext());
}

protected ResolverFactory resolverFactory() {
return new ResolverFactory() {
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(final A annotation) {
ReferenceResolver<A> resolver = null;
try {
if (annotation instanceof Ref) {
resolver = (ReferenceResolver<A>) new RefResolver(arangoTemplate());
}
} catch (final Exception e) {
throw new ArangoDBException(e);
}
return Optional.ofNullable(resolver);
}

@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(final A annotation) {
RelationResolver<A> resolver = null;
try {
if (annotation instanceof From) {
resolver = (RelationResolver<A>) new FromResolver(arangoTemplate());
} else if (annotation instanceof To) {
resolver = (RelationResolver<A>) new ToResolver(arangoTemplate());
} else if (annotation instanceof Relations) {
resolver = (RelationResolver<A>) new RelationsResolver(arangoTemplate());
}
} catch (final Exception e) {
throw new ArangoDBException(e);
}
return Optional.ofNullable(resolver);
}
};
protected ResolverFactory resolverFactory() throws Exception {
return new DefaultResolverFactory(arangoTemplate());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* DISCLAIMER
*
* Copyright 2018 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.springframework.core.convert.resolver;

import java.lang.annotation.Annotation;
import java.util.Optional;

import com.arangodb.springframework.annotation.From;
import com.arangodb.springframework.annotation.Ref;
import com.arangodb.springframework.annotation.Relations;
import com.arangodb.springframework.annotation.To;
import com.arangodb.springframework.core.ArangoOperations;

/**
*
* @author Mark Vollmary
* @author Christian Lechner
*/
public class DefaultResolverFactory implements ResolverFactory {

private final RefResolver refResolver;
private final RelationsResolver relationsResolver;
private final FromResolver fromResolver;
private final ToResolver toResolver;

public DefaultResolverFactory(final ArangoOperations template) {
refResolver = new RefResolver(template);
relationsResolver = new RelationsResolver(template);
fromResolver = new FromResolver(template);
toResolver = new ToResolver(template);
}

@Override
@SuppressWarnings("unchecked")
public <A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(final A annotation) {
ReferenceResolver<A> resolver = null;
if (Ref.class.equals(annotation)) {
resolver = (ReferenceResolver<A>) refResolver;
}
return Optional.ofNullable(resolver);
}

@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(final A annotation) {
RelationResolver<A> resolver = null;
if (From.class.equals(annotation)) {
resolver = (RelationResolver<A>) fromResolver;
} else if (To.class.equals(annotation)) {
resolver = (RelationResolver<A>) toResolver;
} else if (Relations.class.equals(annotation)) {
resolver = (RelationResolver<A>) relationsResolver;
}
return Optional.ofNullable(resolver);
}

}
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
/*
* DISCLAIMER
*
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/
package com.arangodb.springframework.core.convert.resolver;
import java.lang.annotation.Annotation;
import java.util.Optional;
/**
* @author Mark Vollmary
*
*/
public interface ResolverFactory {
<A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(A annotation);
<A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(A annotation);
}
/*
* DISCLAIMER
*
* Copyright 2017 ArangoDB GmbH, Cologne, Germany
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright holder is ArangoDB GmbH, Cologne, Germany
*/

package com.arangodb.springframework.core.convert.resolver;

import java.lang.annotation.Annotation;
import java.util.Optional;

/**
* @author Mark Vollmary
*
*/
public interface ResolverFactory {

<A extends Annotation> Optional<ReferenceResolver<A>> getReferenceResolver(A annotation);

<A extends Annotation> Optional<RelationResolver<A>> getRelationResolver(A annotation);

}