-
Notifications
You must be signed in to change notification settings - Fork 358
DATAJDBC-437 - In strict mode we only claim repositories for domain types with @Table
annotation.
#177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DATAJDBC-437 - In strict mode we only claim repositories for domain types with @Table
annotation.
#177
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.springframework.data.repository.core.support.RepositoryFactorySupport=org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2019 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 | ||
* | ||
* https://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.jdbc.repository.config; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.Collection; | ||
|
||
import org.junit.Test; | ||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
import org.springframework.beans.factory.support.DefaultListableBeanFactory; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.env.StandardEnvironment; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | ||
import org.springframework.core.type.StandardAnnotationMetadata; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
import org.springframework.data.repository.Repository; | ||
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; | ||
import org.springframework.data.repository.config.RepositoryConfiguration; | ||
import org.springframework.data.repository.config.RepositoryConfigurationSource; | ||
|
||
/** | ||
* Unit tests for {@link JdbcRepositoryConfigExtension}. | ||
* | ||
* @author Jens Schauder | ||
* @since 1.2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: No need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
*/ | ||
public class JdbcRepositoryConfigExtensionUnitTests { | ||
|
||
StandardAnnotationMetadata metadata = new StandardAnnotationMetadata(Config.class, true); | ||
ResourceLoader loader = new PathMatchingResourcePatternResolver(); | ||
Environment environment = new StandardEnvironment(); | ||
BeanDefinitionRegistry registry = new DefaultListableBeanFactory(); | ||
|
||
RepositoryConfigurationSource configurationSource = new AnnotationRepositoryConfigurationSource(metadata, | ||
EnableJdbcRepositories.class, loader, environment, registry); | ||
|
||
@Test // DATAJPA-437 | ||
public void isStrictMatchOnlyIfDomainTypeIsAnnotatedWithDocument() { | ||
|
||
JdbcRepositoryConfigExtension extension = new JdbcRepositoryConfigExtension(); | ||
|
||
Collection<RepositoryConfiguration<RepositoryConfigurationSource>> configs = extension.getRepositoryConfigurations(configurationSource, loader, true); | ||
|
||
assertThat(configs).extracting(config -> config.getRepositoryInterface()).containsExactly(SampleRepository.class.getName()); | ||
} | ||
|
||
@EnableJdbcRepositories(considerNestedRepositories = true) | ||
static class Config { | ||
|
||
} | ||
|
||
@Table | ||
static class Sample {} | ||
|
||
interface SampleRepository extends Repository<Sample, Long> {} | ||
|
||
interface UnannotatedRepository extends Repository<Object, Long> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we don't use |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should improve handling for non-existent entity types in
JdbcRepositoryFactory.getTargetRepository(…)
(e.g. callinggetRequiredPersistentEntity(…)
instead ofgetPersistentEntity(…)
).is hard to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✓