Author: pete.muir(a)jboss.org
Date: 2009-07-25 18:28:54 -0400 (Sat, 25 Jul 2009)
New Revision: 3236
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/persistence/PersistenceApiAbstraction.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/JpaServices.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/helpers/ForwardingJpaServices.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockJpaServices.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockJpaServices.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ResourceProducer.java
Log:
Add support for injecting PUs
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-07-25
21:59:42 UTC (rev 3235)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -35,7 +35,6 @@
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.injection.ConstructorInjectionPoint;
import org.jboss.webbeans.injection.FieldInjectionPoint;
-import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.injection.ParameterInjectionPoint;
import org.jboss.webbeans.injection.WBInjectionPoint;
import org.jboss.webbeans.introspector.WBClass;
@@ -50,7 +49,6 @@
import org.jboss.webbeans.persistence.spi.JpaServices;
import org.jboss.webbeans.resources.spi.ResourceServices;
import org.jboss.webbeans.util.Names;
-import org.jboss.webbeans.util.Reflections;
/**
* Represents a simple bean
@@ -72,11 +70,14 @@
private WBMethod<?> preDestroy;
private Set<WBInjectionPoint<?, ?>> ejbInjectionPoints;
- private Set<WBInjectionPoint<?, ?>> persistenceUnitInjectionPoints;
+ private Set<WBInjectionPoint<?, ?>> persistenceContextInjectionPoints;
+ private HashSet<WBInjectionPoint<?, ?>> persistenceUnitInjectionPoints;
private Set<WBInjectionPoint<?, ?>> resourceInjectionPoints;
private SimpleBean<?> specializedBean;
+
+
/**
* Creates a simple, annotation defined Web Bean
*
@@ -191,35 +192,23 @@
{
this.ejbInjectionPoints.add(FieldInjectionPoint.of(this, field));
}
-
- for (WBMethod<?> method :
annotatedItem.getAnnotatedMethods(ejbAnnotationType))
- {
- this.ejbInjectionPoints.add(MethodInjectionPoint.of(this, method));
- }
}
- protected void initPersistenceUnitInjectionPoints()
+ protected void initJpaInjectionPoints()
{
+ this.persistenceContextInjectionPoints = new HashSet<WBInjectionPoint<?,
?>>();
this.persistenceUnitInjectionPoints = new HashSet<WBInjectionPoint<?,
?>>();
- Class<? extends Annotation> persistenceContextAnnotationType =
manager.getServices().get(PersistenceApiAbstraction.class).PERSISTENCE_CONTEXT_ANNOTATION_CLASS;
- Object extendedPersistenceContextEnum =
manager.getServices().get(PersistenceApiAbstraction.class).EXTENDED_PERSISTENCE_CONTEXT_ENUM_VALUE;
+ Class<? extends Annotation> persistenceContextAnnotationType =
manager.getServices().get(PersistenceApiAbstraction.class).PERSISTENCE_CONTEXT_ANNOTATION_CLASS;
for (WBField<?> field :
annotatedItem.getAnnotatedFields(persistenceContextAnnotationType))
{
- if
(extendedPersistenceContextEnum.equals(Reflections.invokeAndWrap("type",
field.getAnnotation(persistenceContextAnnotationType))))
- {
- throw new DefinitionException("Cannot inject an extended persistence
context into " + field);
- }
- this.persistenceUnitInjectionPoints.add(FieldInjectionPoint.of(this, field));
+ this.persistenceContextInjectionPoints.add(FieldInjectionPoint.of(this,
field));
}
-
- for (WBMethod<?> method :
annotatedItem.getAnnotatedMethods(persistenceContextAnnotationType))
+
+ Class<? extends Annotation> persistenceUnitAnnotationType =
manager.getServices().get(PersistenceApiAbstraction.class).PERSISTENCE_UNIT_ANNOTATION_CLASS;
+ for (WBField<?> field :
annotatedItem.getAnnotatedFields(persistenceUnitAnnotationType))
{
- if
(extendedPersistenceContextEnum.equals(Reflections.invokeAndWrap("type",
method.getAnnotation(persistenceContextAnnotationType))))
- {
- throw new DefinitionException("Cannot inject an extended persistence
context into " + method);
- }
- this.persistenceUnitInjectionPoints.add(MethodInjectionPoint.of(this, method));
+ this.persistenceUnitInjectionPoints.add(FieldInjectionPoint.of(this, field));
}
}
@@ -253,9 +242,14 @@
if (jpaServices != null)
{
+ for (WBInjectionPoint<?, ?> injectionPoint :
persistenceContextInjectionPoints)
+ {
+ Object pcInstance = jpaServices.resolvePersistenceContext(injectionPoint);
+ injectionPoint.inject(beanInstance, pcInstance);
+ }
for (WBInjectionPoint<?, ?> injectionPoint :
persistenceUnitInjectionPoints)
{
- Object puInstance = jpaServices.resolvePersistenceContext(injectionPoint);
+ Object puInstance = jpaServices.resolvePersistenceUnit(injectionPoint);
injectionPoint.inject(beanInstance, puInstance);
}
}
@@ -289,7 +283,7 @@
}
if (getManager().getServices().contains(JpaServices.class))
{
- initPersistenceUnitInjectionPoints();
+ initJpaInjectionPoints();
}
if (getManager().getServices().contains(ResourceServices.class))
{
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/persistence/PersistenceApiAbstraction.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/persistence/PersistenceApiAbstraction.java 2009-07-25
21:59:42 UTC (rev 3235)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/persistence/PersistenceApiAbstraction.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -26,6 +26,7 @@
{
public final Class<? extends Annotation> PERSISTENCE_CONTEXT_ANNOTATION_CLASS;
+ public final Class<? extends Annotation> PERSISTENCE_UNIT_ANNOTATION_CLASS;
public final Object EXTENDED_PERSISTENCE_CONTEXT_ENUM_VALUE;
public final Class<?> PERSISTENCE_CONTEXT_TYPE_CLASS;
public final Class<? extends Annotation> ENTITY_CLASS;
@@ -39,6 +40,7 @@
{
super(resourceLoader);
PERSISTENCE_CONTEXT_ANNOTATION_CLASS =
annotationTypeForName("javax.persistence.PersistenceContext");
+ PERSISTENCE_UNIT_ANNOTATION_CLASS =
annotationTypeForName("javax.persistence.PersistenceUnit");
PERSISTENCE_CONTEXT_TYPE_CLASS =
classForName("javax.persistence.PersistenceContextType");
if (PERSISTENCE_CONTEXT_TYPE_CLASS.getClass().equals( Dummy.class))
{
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/JpaServices.java
===================================================================
---
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/JpaServices.java 2009-07-25
21:59:42 UTC (rev 3235)
+++
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/JpaServices.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -48,25 +48,18 @@
public EntityManager resolvePersistenceContext(InjectionPoint injectionPoint);
/**
- * Resolve a persistence context for a given persistence unit name
+ * Resolve the value for the given @PersistenceUnit injection point
*
- * @param unitName the unit name
+ * @param injectionPoint
+ * the injection point metadata
* @return an instance of the entity manager
+ * @throws IllegalArgumentException
+ * if the injection point is not annotated with
+ * @PersistenceUnit, or, if the injection point is a method
+ * that doesn't follow JavaBean conventions
* @throws IllegalStateException
* if no suitable persistence units can be resolved for injection
*/
- public EntityManager resolvePersistenceContext(String unitName);
-
- /**
- * Resolve a persistence unit for a given persistence unit name
- *
- * @param unitName the unit name
- * @return an instance of the entity manager factory
- * @throws IllegalStateException
- * if no suitable persistence units can be resolved for injection
- * @throws IllegalArgumentException
- * if unitName is null
- */
- public EntityManagerFactory resolvePersistenceUnit(String unitName);
+ public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint);
}
Modified:
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/helpers/ForwardingJpaServices.java
===================================================================
---
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/helpers/ForwardingJpaServices.java 2009-07-25
21:59:42 UTC (rev 3235)
+++
ri/trunk/spi/src/main/java/org/jboss/webbeans/persistence/spi/helpers/ForwardingJpaServices.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -42,16 +42,11 @@
return delegate().resolvePersistenceContext(injectionPoint);
}
- public EntityManager resolvePersistenceContext(String unitName)
+ public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint)
{
- return delegate().resolvePersistenceContext(unitName);
+ return delegate().resolvePersistenceUnit(injectionPoint);
}
- public EntityManagerFactory resolvePersistenceUnit(String unitName)
- {
- return delegate().resolvePersistenceUnit(unitName);
- }
-
@Override
public String toString()
{
Modified:
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockJpaServices.java
===================================================================
---
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockJpaServices.java 2009-07-25
21:59:42 UTC (rev 3235)
+++
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockJpaServices.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -21,14 +21,9 @@
return null;
}
- public EntityManager resolvePersistenceContext(String unitName)
+ public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint)
{
return null;
}
- public EntityManagerFactory resolvePersistenceUnit(String unitName)
- {
- return null;
- }
-
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockJpaServices.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockJpaServices.java 2009-07-25
21:59:42 UTC (rev 3235)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockJpaServices.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -31,16 +31,11 @@
return null;
}
- public EntityManager resolvePersistenceContext(String unitName)
+ public EntityManagerFactory resolvePersistenceUnit(InjectionPoint injectionPoint)
{
return null;
}
- public EntityManagerFactory resolvePersistenceUnit(String unitName)
- {
- return null;
- }
-
public Collection<Class<?>> discoverEntities()
{
Set<Class<?>> classes = new HashSet<Class<?>>();
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java 2009-07-25
21:59:42 UTC (rev 3235)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/PersistenceContextInjectionTest.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -42,7 +42,7 @@
assert managedBean.getPersistenceContext().isOpen() : "Persistence context not
open injected into bean";
}
- @Test(groups = { "ri-broken", "beanLifecycle",
"commonAnnotations", "integration" })
+ @Test(groups = { "beanLifecycle", "commonAnnotations",
"integration" })
@SpecAssertions( {
@SpecAssertion(section = "3.5.1", id = "dd")
})
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ResourceProducer.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ResourceProducer.java 2009-07-25
21:59:42 UTC (rev 3235)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/resource/persistenceContext/ResourceProducer.java 2009-07-25
22:28:54 UTC (rev 3236)
@@ -11,4 +11,20 @@
private @Produces @Default @PersistenceUnit EntityManagerFactory persistenceUnit;
private @Produces @Default @PersistenceContext EntityManager persistenceContext;
+
+ /**
+ * @return the persistenceContext
+ */
+ public EntityManager getPersistenceContext()
+ {
+ return persistenceContext;
+ }
+
+ /**
+ * @return the persistenceUnit
+ */
+ public EntityManagerFactory getPersistenceUnit()
+ {
+ return persistenceUnit;
+ }
}