DATAJPA-319 - Use default CDI repository scope (application).
Don't inherit the scope of the repository from the EntityManager but let it be the default (application scope singleton).
This commit is contained in:
@@ -32,7 +32,6 @@ import org.springframework.util.Assert;
|
|||||||
*
|
*
|
||||||
* @author Dirk Mahler
|
* @author Dirk Mahler
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
*
|
|
||||||
* @param <T> The type of the repository.
|
* @param <T> The type of the repository.
|
||||||
*/
|
*/
|
||||||
class JpaRepositoryBean<T> extends CdiRepositoryBean<T> {
|
class JpaRepositoryBean<T> extends CdiRepositoryBean<T> {
|
||||||
@@ -69,14 +68,4 @@ class JpaRepositoryBean<T> extends CdiRepositoryBean<T> {
|
|||||||
JpaRepositoryFactory factory = new JpaRepositoryFactory(entityManager);
|
JpaRepositoryFactory factory = new JpaRepositoryFactory(entityManager);
|
||||||
return factory.getRepository(repositoryType);
|
return factory.getRepository(repositoryType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see javax.enterprise.inject.spi.Bean#getScope()
|
|
||||||
*/
|
|
||||||
public Class<? extends Annotation> getScope() {
|
|
||||||
|
|
||||||
// The repository uses the same scope as the associated EntityManager.
|
|
||||||
return entityManagerBean.getScope();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 the original author or authors.
|
* Copyright 2011-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.jpa.repository.cdi;
|
package org.springframework.data.jpa.repository.cdi;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
|
import javax.enterprise.inject.spi.Bean;
|
||||||
|
|
||||||
import org.apache.webbeans.cditest.CdiTestContainer;
|
import org.apache.webbeans.cditest.CdiTestContainer;
|
||||||
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@@ -36,6 +44,19 @@ public class CdiExtensionintegrationTests {
|
|||||||
container.bootContainer();
|
container.bootContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAJPA-319
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public void foo() {
|
||||||
|
|
||||||
|
Set<Bean<?>> beans = container.getBeanManager().getBeans(PersonRepository.class);
|
||||||
|
|
||||||
|
assertThat(beans, hasSize(1));
|
||||||
|
assertThat(beans.iterator().next().getScope(), is(equalTo((Class) ApplicationScoped.class)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void saveAndFindAll() {
|
public void saveAndFindAll() {
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 the original author or authors.
|
* Copyright 2011-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,7 +17,7 @@ package org.springframework.data.jpa.repository.cdi;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
interface PersonRepository {
|
public interface PersonRepository {
|
||||||
|
|
||||||
List<Person> findAll();
|
List<Person> findAll();
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ package org.springframework.data.jpa.repository.cdi;
|
|||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
@PersonDB
|
@PersonDB
|
||||||
interface QualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
|
public interface QualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 the original author or authors.
|
* Copyright 2011-2013 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,6 +17,6 @@ package org.springframework.data.jpa.repository.cdi;
|
|||||||
|
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
interface UnqualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
|
public interface UnqualifiedPersonRepository extends PersonRepository, Repository<Person, Long> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user