DATAJPA-710 - Adapt to changes in Spring Data Commons.
Tweaked method signatures in JpaRepositoryFactory after some signature changes in Spring Data Commons. Use newly introduced getTragetRepositoryViaReflection(…) to obtain the repository instance via the super class. Added repositoryBaseClass() attribute to @EnableJpaRepositories. Related tickets: DATACMNS-542.
This commit is contained in:
@@ -24,6 +24,7 @@ import javax.persistence.EntityManager;
|
||||
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
||||
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
|
||||
/**
|
||||
@@ -47,10 +48,10 @@ public class CustomGenericJpaRepositoryFactory extends JpaRepositoryFactory {
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected SimpleJpaRepository<?, ?> getTargetRepository(RepositoryMetadata metadata, EntityManager em) {
|
||||
protected SimpleJpaRepository<?, ?> getTargetRepository(RepositoryInformation information, EntityManager em) {
|
||||
|
||||
JpaEntityInformation<Object, Serializable> entityMetadata = mock(JpaEntityInformation.class);
|
||||
when(entityMetadata.getJavaType()).thenReturn((Class<Object>) metadata.getDomainType());
|
||||
when(entityMetadata.getJavaType()).thenReturn((Class<Object>) information.getDomainType());
|
||||
return new CustomGenericJpaRepository<Object, Serializable>(entityMetadata, em);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2014 the original author or authors.
|
||||
* Copyright 2008-2015 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.
|
||||
@@ -152,6 +152,18 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-710, DATACMNS-542
|
||||
*/
|
||||
@Test
|
||||
public void usesConfiguredRepositoryBaseClass() {
|
||||
|
||||
factory.setRepositoryBaseClass(CustomJpaRepository.class);
|
||||
|
||||
SampleRepository repository = factory.getRepository(SampleRepository.class);
|
||||
assertEquals(CustomJpaRepository.class, ((Advised) repository).getTargetClass());
|
||||
}
|
||||
|
||||
private interface SimpleSampleRepository extends JpaRepository<User, Integer> {
|
||||
|
||||
@Transactional
|
||||
@@ -195,4 +207,11 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
private interface QueryDslSampleRepository extends SimpleSampleRepository, QueryDslPredicateExecutor<User> {
|
||||
|
||||
}
|
||||
|
||||
static class CustomJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> {
|
||||
|
||||
public CustomJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
|
||||
super(entityInformation, entityManager);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user