DATAJPA-1230 - Make JpaRepositoryFactory agnostic of JpaRepository implementation

This commit is contained in:
Stefan Fussenegger
2017-11-29 14:07:44 +01:00
committed by Oliver Gierke
parent 5de6fe0fa7
commit 31ddaa979e
3 changed files with 40 additions and 5 deletions

View File

@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Christoph Strobl
* @author Jens Schauder
* @author Stefan Fussenegger
*/
public class JpaRepositoryFactory extends RepositoryFactorySupport {
@@ -87,8 +88,11 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
@Override
protected Object getTargetRepository(RepositoryInformation information) {
SimpleJpaRepository<?, ?> repository = getTargetRepository(information, entityManager);
repository.setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata());
Object repository = getTargetRepository(information, entityManager);
if (repository instanceof RepositoryMethodMetadataAware) {
((RepositoryMethodMetadataAware) repository)
.setRepositoryMethodMetadata(crudMethodMetadataPostProcessor.getCrudMethodMetadata());
}
return repository;
}
@@ -101,8 +105,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
* @param entityManager
* @return
*/
protected <T, ID extends Serializable> SimpleJpaRepository<?, ?> getTargetRepository(
RepositoryInformation information, EntityManager entityManager) {
protected Object getTargetRepository(RepositoryInformation information, EntityManager entityManager) {
JpaEntityInformation<?, Serializable> entityInformation = getEntityInformation(information.getDomainType());

View File

@@ -0,0 +1,30 @@
/*
* 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.jpa.repository.support;
import org.springframework.data.jpa.repository.support.CrudMethodMetadata;
/**
* implemented by {@link org.springframework.data.jpa.repository.JpaRepository} implementations requiring
* {@link CrudMethodMetadata}
*
* @author Stefan Fussenegger
*/
public interface RepositoryMethodMetadataAware {
void setRepositoryMethodMetadata(CrudMethodMetadata crudMethodMetadata);
}

View File

@@ -67,12 +67,14 @@ import org.springframework.util.Assert;
* @author Thomas Darimont
* @author Mark Paluch
* @author Christoph Strobl
* @author Stefan Fussenegger
* @param <T> the type of the entity to handle
* @param <ID> the type of the entity's identifier
*/
@Repository
@Transactional(readOnly = true)
public class SimpleJpaRepository<T, ID> implements JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
public class SimpleJpaRepository<T, ID>
implements JpaRepository<T, ID>, JpaSpecificationExecutor<T>, RepositoryMethodMetadataAware {
private static final String ID_MUST_NOT_BE_NULL = "The given id must not be null!";