DATACOUCH-330 - Improved detectability of Couchbase repositories in strict configuration mode.

We now make sure that repositories for domain types annotated with @Document or extending CouchbaseRepository are considered strict repository candidates.
This commit is contained in:
Oliver Gierke
2017-08-28 11:24:03 +02:00
parent 8a34eb82c1
commit 9cb7b44594
2 changed files with 96 additions and 1 deletions

View File

@@ -16,18 +16,24 @@
package org.springframework.data.couchbase.repository.config;
import org.w3c.dom.Element;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Collections;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.data.config.ParsingUtils;
import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactoryBean;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
import org.springframework.data.repository.config.XmlRepositoryConfigurationSource;
import org.w3c.dom.Element;
/**
* @author Michael Nitschinger
* @author Oliver Gierke
*/
public class CouchbaseRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport {
@@ -60,4 +66,22 @@ public class CouchbaseRepositoryConfigurationExtension extends RepositoryConfigu
builder.addPropertyReference("couchbaseOperationsMapping", BeanNames.COUCHBASE_OPERATIONS_MAPPING);
builder.addPropertyReference("indexManager", BeanNames.COUCHBASE_INDEX_MANAGER);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingAnnotations()
*/
@Override
protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() {
return Collections.<Class<? extends Annotation>> singleton(Document.class);
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getIdentifyingTypes()
*/
@Override
protected Collection<Class<?>> getIdentifyingTypes() {
return Collections.<Class<?>> singleton(CouchbaseRepository.class);
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2017 the original author or authors.
*
* 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.
*/
package org.springframework.data.couchbase.repository.config;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.io.Serializable;
import org.junit.Test;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.repository.CouchbaseRepository;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
/**
* Unit tests for {@link CouchbaseRepositoryConfigurationExtension}.
*
* @author Oliver Gierke
*/
public class CouchbaseRepositoryConfigurationExtensionUnitTests {
@Test // DATACOUCH-330
public void atDocumentIsIdentifyingAnnotation() {
CustomCouchbaseRepositoryConfigurationExtension extension = new CustomCouchbaseRepositoryConfigurationExtension();
assertThat(extension.isStrictRepositoryCandidate(ByAggregateRootAnnotationRepository.class), is(true));
}
@Test // DATACOUCH-330
public void couchbaseRepositoryIsIdentifyingAnnotation() {
CustomCouchbaseRepositoryConfigurationExtension extension = new CustomCouchbaseRepositoryConfigurationExtension();
assertThat(extension.isStrictRepositoryCandidate(ByRepository.class), is(true));
}
@Document
static class AggregateRoot {}
interface ByAggregateRootAnnotationRepository extends Repository<AggregateRoot, Serializable> {}
interface ByRepository extends CouchbaseRepository<Object, Serializable> {};
static class CustomCouchbaseRepositoryConfigurationExtension extends CouchbaseRepositoryConfigurationExtension {
/*
* (non-Javadoc)
* @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#isStrictRepositoryCandidate(java.lang.Class)
*/
@Override
protected boolean isStrictRepositoryCandidate(Class<?> repositoryInterface) {
return super.isStrictRepositoryCandidate(repositoryInterface);
}
}
}