DATAJPA-419 - Adapt to new non-lazy-instantiation model of repositories.
Mostly mayor cleanups the way test cases bootstrap the repositories as they're now instantiated eagerly.
This commit is contained in:
@@ -22,7 +22,6 @@ package org.springframework.data.jpa.domain.sample;
|
||||
*/
|
||||
public class Role {
|
||||
|
||||
private static final long serialVersionUID = -8832631113344035104L;
|
||||
private static final String PREFIX = "ROLE_";
|
||||
|
||||
private Integer id;
|
||||
|
||||
@@ -21,17 +21,15 @@ import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleDepartment;
|
||||
import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployee;
|
||||
import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployeePK;
|
||||
import org.springframework.data.jpa.domain.sample.IdClassExampleDepartment;
|
||||
import org.springframework.data.jpa.domain.sample.IdClassExampleEmployee;
|
||||
import org.springframework.data.jpa.domain.sample.IdClassExampleEmployeePK;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.jpa.repository.sample.EmployeeRepositoryWithEmbeddedId;
|
||||
import org.springframework.data.jpa.repository.sample.EmployeeRepositoryWithIdClass;
|
||||
import org.springframework.data.jpa.repository.sample.SampleConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -43,15 +41,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@ContextConfiguration(classes = SampleConfig.class)
|
||||
@Transactional
|
||||
public class DataJpa269RepositoryWithCompositeKeyTests {
|
||||
|
||||
@Configuration
|
||||
@ImportResource("classpath:infrastructure.xml")
|
||||
@EnableJpaRepositories
|
||||
static interface Config {}
|
||||
|
||||
@Autowired EmployeeRepositoryWithIdClass employeeRepositoryWithIdClass;
|
||||
@Autowired EmployeeRepositoryWithEmbeddedId employeeRepositoryWithEmbeddedId;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -53,10 +53,8 @@ public class JavaConfigUserRepositoryTests extends UserRepositoryTests {
|
||||
@ImportResource("classpath:infrastructure.xml")
|
||||
static class Config {
|
||||
|
||||
@PersistenceContext
|
||||
EntityManager entityManager;
|
||||
@Autowired
|
||||
BeanFactory beanFactory;
|
||||
@PersistenceContext EntityManager entityManager;
|
||||
@Autowired BeanFactory beanFactory;
|
||||
|
||||
@Bean
|
||||
public UserRepository userRepository() throws IOException {
|
||||
@@ -88,12 +86,13 @@ public class JavaConfigUserRepositoryTests extends UserRepositoryTests {
|
||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||
public void doesNotPickUpJpaRepository() {
|
||||
|
||||
ApplicationContext context = new AnnotationConfigApplicationContext(JpaRepositoryConfig.class);
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(JpaRepositoryConfig.class);
|
||||
context.getBean("jpaRepository");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableJpaRepositories
|
||||
@EnableJpaRepositories(basePackageClasses = UserRepository.class)
|
||||
@ImportResource("classpath:infrastructure.xml")
|
||||
static class JpaRepositoryConfig {
|
||||
|
||||
|
||||
@@ -23,14 +23,12 @@ import java.util.List;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.data.jpa.domain.sample.ConcreteType1;
|
||||
import org.springframework.data.jpa.domain.sample.ConcreteType2;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.jpa.repository.sample.ConcreteRepository1;
|
||||
import org.springframework.data.jpa.repository.sample.ConcreteRepository2;
|
||||
import org.springframework.data.jpa.repository.sample.MappedTypeRepository;
|
||||
import org.springframework.data.jpa.repository.sample.SampleConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -42,14 +40,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@Transactional
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@ContextConfiguration(classes = SampleConfig.class)
|
||||
public class MappedTypeRepositoryIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@ImportResource("classpath:infrastructure.xml")
|
||||
@EnableJpaRepositories
|
||||
static class Config {}
|
||||
|
||||
@Autowired ConcreteRepository1 concreteRepository1;
|
||||
@Autowired ConcreteRepository2 concreteRepository2;
|
||||
|
||||
|
||||
@@ -24,13 +24,11 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.sample.User;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.data.jpa.repository.sample.RedeclaringRepositoryMethodsRepository;
|
||||
import org.springframework.data.jpa.repository.sample.SampleConfig;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -39,15 +37,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@ContextConfiguration(classes = SampleConfig.class)
|
||||
@Transactional
|
||||
public class RedeclaringRepositoryMethodsTests {
|
||||
|
||||
@Configuration
|
||||
@ImportResource("classpath:infrastructure.xml")
|
||||
@EnableJpaRepositories
|
||||
static class Config {}
|
||||
|
||||
@Autowired RedeclaringRepositoryMethodsRepository repository;
|
||||
|
||||
User ollie, tom;
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.sample.ConcreteType1;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Lazy
|
||||
public interface ConcreteRepository1 extends MappedTypeRepository<ConcreteType1> {
|
||||
|
||||
}
|
||||
|
||||
@@ -15,11 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.sample.ConcreteType2;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Lazy
|
||||
public interface ConcreteRepository2 extends MappedTypeRepository<ConcreteType2> {
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployee;
|
||||
import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployeePK;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@@ -24,5 +25,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Lazy
|
||||
public interface EmployeeRepositoryWithEmbeddedId extends
|
||||
JpaRepository<EmbeddedIdExampleEmployee, EmbeddedIdExampleEmployeePK> {}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.sample.IdClassExampleEmployee;
|
||||
import org.springframework.data.jpa.domain.sample.IdClassExampleEmployeePK;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@@ -24,4 +25,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Lazy
|
||||
public interface EmployeeRepositoryWithIdClass extends JpaRepository<IdClassExampleEmployee, IdClassExampleEmployeePK> {}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.sample.AbstractMappedType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -24,6 +25,7 @@ import org.springframework.data.jpa.repository.Query;
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
@Lazy
|
||||
public interface MappedTypeRepository<T extends AbstractMappedType> extends JpaRepository<T, Long> {
|
||||
|
||||
@Query("from #{#entityName} t where t.attribute1=?1")
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.sample;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.jpa.domain.sample.Parent;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
public interface ParentRepository extends JpaRepository<Parent, Long>, JpaSpecificationExecutor<Parent> {
|
||||
}
|
||||
@Lazy
|
||||
public interface ParentRepository extends JpaRepository<Parent, Long>, JpaSpecificationExecutor<Parent> {}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2013 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.sample;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
@ImportResource("classpath:infrastructure.xml")
|
||||
@EnableJpaRepositories
|
||||
public class SampleConfig {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="default">
|
||||
<class>org.springframework.data.jpa.domain.sample.AbstractMappedType</class>
|
||||
<class>org.springframework.data.jpa.domain.AbstractPersistable</class>
|
||||
<class>org.springframework.data.jpa.domain.AbstractAuditable</class>
|
||||
<class>org.springframework.data.jpa.domain.sample.Account</class>
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
|
||||
xmlns:repository="http://www.springframework.org/schema/data/repository"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
|
||||
|
||||
<import resource="../infrastructure.xml" />
|
||||
|
||||
<jpa:repositories base-package="org.springframework.data.jpa.repository.sample" query-lookup-strategy="use-declared-query" />
|
||||
<jpa:repositories base-package="org.springframework.data.jpa.repository.sample" query-lookup-strategy="use-declared-query">
|
||||
<repository:include-filter type="assignable" expression="org.springframework.data.jpa.repository.sample.RoleRepository" />
|
||||
</jpa:repositories>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user