tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1139723 - in /openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/ container/openejb-core/src/main/java/org/apache/openejb/cdi/ container/openejb-core/src/test/java/org/apache/openejb/cdi/ tck/cdi-embedded/src/t...
Date Sun, 26 Jun 2011 07:35:20 GMT
Author: dblevins
Date: Sun Jun 26 07:35:20 2011
New Revision: 1139723

URL: http://svn.apache.org/viewvc?rev=1139723&view=rev
Log:
OPENEJB-1586: @Dependent instances of an EJB removed when EJB is removed

Added:
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/DependentScopedTest.java
      - copied, changed from r1139700, openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java
Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java?rev=1139723&r1=1139722&r2=1139723&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
Sun Jun 26 07:35:20 2011
@@ -38,7 +38,10 @@ import javax.ejb.LockType;
 import javax.ejb.MessageDrivenBean;
 import javax.ejb.TimedObject;
 import javax.ejb.Timer;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.spi.Contextual;
 import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
 import javax.naming.Context;
 import javax.persistence.EntityManagerFactory;
 
@@ -65,7 +68,12 @@ import org.apache.openejb.util.Index;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.component.AbstractInjectionTargetBean;
+import org.apache.webbeans.component.EnterpriseBeanMarker;
+import org.apache.webbeans.component.InjectionTargetBean;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.inject.AbstractInjectable;
+import org.apache.webbeans.proxy.JavassistProxyFactory;
 import org.apache.xbean.recipe.ConstructionException;
 
 
@@ -1217,10 +1225,7 @@ public class BeanContext extends Deploym
 
             final Object beanInstance = injectionProcessor.createInstance();
 
-            beanDefinition.injectSuperFields(beanInstance, creationalContext);
-            beanDefinition.injectSuperMethods(beanInstance, creationalContext);
-            beanDefinition.injectFields(beanInstance, creationalContext);
-            beanDefinition.injectMethods(beanInstance, creationalContext);
+            inject(beanInstance, creationalContext);
 
             // Create interceptors
             final HashMap<String, Object> interceptorInstances = new HashMap<String,
Object>();
@@ -1299,6 +1304,68 @@ public class BeanContext extends Deploym
         }                        
     }
 
+    protected <X> X getBean(Class<X> clazz, Bean<?> bean)
+    {
+        return clazz.cast(bean);
+    }
+
+    public <T> void inject(T instance, CreationalContext<T> ctx)
+    {
+
+        WebBeansContext webBeansContext = getModuleContext().getAppContext().getWebBeansContext();
+
+        AbstractInjectionTargetBean<Object> beanDefinition = get(CdiEjbBean.class);
+
+        final ConstructorInjectionBean<Object> beanConstructor = new ConstructorInjectionBean<Object>(webBeansContext,
beanClass);
+
+        if (beanDefinition == null) {
+            beanDefinition = beanConstructor;
+        }
+
+        if(!(ctx instanceof CreationalContextImpl))
+        {
+            ctx = webBeansContext.getCreationalContextFactory().wrappedCreationalContext(ctx,
beanDefinition);
+        }
+
+        Object oldInstanceUnderInjection = AbstractInjectable.instanceUnderInjection.get();
+        boolean isInjectionToAnotherBean = false;
+        try
+        {
+            Contextual<?> contextual = null;
+            if(ctx instanceof CreationalContextImpl)
+            {
+                contextual = ((CreationalContextImpl)ctx).getBean();
+                isInjectionToAnotherBean = contextual == getBean(InjectionTargetBean.class,
beanDefinition) ? false : true;
+            }
+
+            if(!isInjectionToAnotherBean)
+            {
+                AbstractInjectable.instanceUnderInjection.set(instance);
+            }
+
+            InjectionTargetBean<T> bean = getBean(InjectionTargetBean.class, beanDefinition);
+
+            bean.injectResources(instance, ctx);
+            bean.injectSuperFields(instance, ctx);
+            bean.injectSuperMethods(instance, ctx);
+            bean.injectFields(instance, ctx);
+            bean.injectMethods(instance, ctx);
+        }
+        finally
+        {
+            if(oldInstanceUnderInjection != null)
+            {
+                AbstractInjectable.instanceUnderInjection.set(oldInstanceUnderInjection);
+            }
+            else
+            {
+                AbstractInjectable.instanceUnderInjection.set(null);
+                AbstractInjectable.instanceUnderInjection.remove();
+            }
+        }
+
+    }
+
     public Set<Class<?>> getAsynchronousClasses() {
         return asynchronousClasses;
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java?rev=1139723&r1=1139722&r2=1139723&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiEjbBean.java
Sun Jun 26 07:35:20 2011
@@ -175,6 +175,13 @@ public class CdiEjbBean<T> extends BaseE
         return points;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.webbeans.component.AbstractBean#isPassivationCapable()
+     */
+    @Override
+    public boolean isPassivationCapable() {
+        return getWebBeansContext().getBeanManagerImpl().isPassivatingScope(getScope());
+    }
 
     @SuppressWarnings("unchecked")
     private List<Method> findRemove(Class beanClass, Class beanInterface) {

Copied: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/DependentScopedTest.java
(from r1139700, openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/DependentScopedTest.java?p2=openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/DependentScopedTest.java&p1=openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java&r1=1139700&r2=1139723&rev=1139723&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/ApplicationScopedTest.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/cdi/DependentScopedTest.java
Sun Jun 26 07:35:20 2011
@@ -25,233 +25,152 @@ import org.apache.openejb.junit.Module;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import javax.ejb.Local;
-import javax.ejb.Stateful;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.spi.Context;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @version $Rev$ $Date$
  */
 @RunWith(ApplicationComposer.class)
-public class ApplicationScopedTest extends TestCase {
+public class DependentScopedTest extends TestCase {
 
     @Inject
     private BeanManager beanManager;
 
     @Test
     public void test() throws Exception {
+        created.clear();
+        destroyed.clear();
 
-        final Context appContext = beanManager.getContext(ApplicationScoped.class);
+        final Bean<ColorWheelLocal> colorWheelBean = getBean(ColorWheelLocal.class);
 
+        final CreationalContext<ColorWheelLocal> creationalContext = beanManager.createCreationalContext(colorWheelBean);
 
+        final ColorWheelLocal colorWheel = colorWheelBean.create(creationalContext);
 
-        final Green green = createAndMutate(appContext, Green.class);
+        assertEquals(6, created.size());
 
-        final Blue blue = createAndMutate(appContext, Blue.class);
+        assertEquals(6, colorWheel.getColors().size());
 
-        assertEquals(green.getMessage(), blue.getGreen().getMessage());
+        colorWheelBean.destroy(colorWheel, creationalContext);
 
-        final BrownLocal brownLocal = createAndMutate(appContext, BrownLocal.class);
+        assertEquals(6, destroyed.size());
 
-        final Green green2 = brownLocal.getGreen();
-        green2.getMessage();
-
-        final Orange orange = createAndMutate(appContext, Orange.class);
-        assertNotNull(orange);
-        assertNotNull(orange.getBlue());
-        assertNotNull(orange.getBlue().getGreen());
-        assertNotNull(orange.getGreen());
-
-        final Green greenA = orange.getBlue().getGreen();
-        final Green greenB = orange.getGreen();
-
-        assertSame(greenA, greenB);
     }
 
-    private <T extends Message> T createAndMutate(Context context, Class<T> beanType)
{
-
-        final Bean<T> bean = (Bean<T>) beanManager.getBeans(beanType).iterator().next();
-
-        // We haven't created anything yet, so the instance should not exist in the context
-        assertNull(context.get(bean));
-
-
-        final CreationalContext<T> cc1 = beanManager.createCreationalContext(bean);
-
-        // This should create the instance and put it in the context
-        final T instance = context.get(bean, cc1);
-
-
-        // Assert the instance is now in the context and can be generically retrieved
-        assertNotNull(context.get(bean));
-
-
-        final String prefix = beanType.getSimpleName();
-
-        // Mutate the instance...
-        instance.setMessage(prefix + ": hello application");
-
-        // Now check the reference in the context
-        assertEquals(prefix + ": hello application", context.get(bean, cc1).getMessage());
-
-        // Attempt to create a second instance (should not work)
-        final CreationalContext<T> cc2 = beanManager.createCreationalContext(bean);
-
-        // We should still have the same mutated instance as before
-        assertEquals(prefix + ": hello application", context.get(bean, cc2).getMessage());
-
-        // Mutate the instance one more time
-        instance.setMessage(prefix + ": hello again application");
-
-        // And double check that we still just have the single instance in the context
-        assertEquals(prefix + ": hello again application", context.get(bean).getMessage());
-        assertEquals(prefix + ": hello again application", context.get(bean, null).getMessage());
-        assertEquals(prefix + ": hello again application", context.get(bean, cc1).getMessage());
-        assertEquals(prefix + ": hello again application", context.get(bean, cc2).getMessage());
-
-        return instance;
+    private <T> Bean<T> getBean(Class<T> beanType) {
+        return (Bean<T>) beanManager.getBeans(beanType).iterator().next();
     }
 
+
     @Module
     public SessionBean getEjbs() {
-        return new StatefulBean(Brown.class);
+        return new StatefulBean(ColorWheel.class);
     }
 
     @Module
     public Beans getBeans() {
         final Beans beans = new Beans();
+//        beans.addManagedClass(ColorWheel.class);
+        beans.addManagedClass(Red.class);
         beans.addManagedClass(Orange.class);
-        beans.addManagedClass(Blue.class);
+        beans.addManagedClass(Yellow.class);
         beans.addManagedClass(Green.class);
+        beans.addManagedClass(Blue.class);
+        beans.addManagedClass(Violet.class);
         return beans;
     }
 
-    @Local
-    public static interface BrownLocal extends Message {
+    public static final List<Class> destroyed = new ArrayList<Class>();
+    public static final List<Class> created = new ArrayList<Class>();
 
-        public Green getGreen();
+    public static interface ColorWheelLocal {
+        public List<Color> getColors();
     }
 
-    @Stateful
-    @ApplicationScoped
-    public static class Brown implements BrownLocal {
-        private String id;
-
-        @Inject
-        private Green green;
+    public static class ColorWheel implements ColorWheelLocal {
 
-        @Override
-        public String getMessage() {
-            return id;
-        }
+        private List<Color> colors = new ArrayList<Color>();
 
-        @Override
-        public void setMessage(String id) {
-            this.id = id;
-        }
-
-        @Override
-        public Green getGreen() {
-            return green;
+        @Inject
+        public void set(Red color) {
+            colors.add(color);
         }
-    }
-
-    @ApplicationScoped
-    public static class Orange implements Message {
 
-        private String id;
-        private Blue blue;
-
-        public Orange() {
-            System.out.println(this.getClass().getName());
+        @Inject
+        public void set(Orange color) {
+            colors.add(color);
         }
 
-        @Override
-        public String getMessage() {
-            return id;
+        @Inject
+        public void set(Yellow color) {
+            colors.add(color);
         }
 
-        @Override
-        public void setMessage(String id) {
-            this.id = id;
-        }
         @Inject
-        private Green green;
+        public void set(Green color) {
+            colors.add(color);
+        }
 
         @Inject
-        public void setBlue(Blue blue) {
-            this.blue = blue;
+        public void set(Blue color) {
+            colors.add(color);
         }
 
-        public Blue getBlue() {
-            return blue;
+        @Inject
+        public void set(Violet color) {
+            colors.add(color);
         }
 
-        public Green getGreen() {
-            return green;
+        public List<Color> getColors() {
+            return colors;
         }
     }
 
-    @ApplicationScoped
-    public static class Blue implements Message {
-
-        private String id;
-        private Green green;
-
-        public Blue() {
-            System.out.println(this.getClass().getName());
-        }
+    public static class Color {
 
-        @Override
-        public String getMessage() {
-            return id;
+        public Class get() {
+            return getClass();
         }
 
-        @Override
-        public void setMessage(String id) {
-            this.id = id;
+        @PostConstruct
+        public void create() {
+            created.add(getClass());
         }
 
-        public Green getGreen() {
-            return green;
+        @PreDestroy
+        public void destroy() {
+            destroyed.add(getClass());
         }
+    }
 
-        @Inject
-        public void setGreen(Green green) {
-            this.green = green;
-        }
+    public static class Red extends Color {
     }
 
-    @ApplicationScoped
-    public static class Green implements Message {
+    public static class Orange extends Color {
 
-        private String id;
+    }
 
-        public Green() {
-            "".length();
-            System.out.println(this.getClass().getName());
-        }
+    public static class Yellow extends Color {
 
-        @Override
-        public String getMessage() {
-            return id;
-        }
+    }
+
+    public static class Green extends Color {
 
-        @Override
-        public void setMessage(String id) {
-            this.id = id;
-        }
     }
 
-    public static interface Message {
+    public static class Blue extends Color {
 
-        void setMessage(String id);
+    }
+
+    public static class Violet extends Color {
 
-        String getMessage();
     }
+
 }

Modified: openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml?rev=1139723&r1=1139722&r2=1139723&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml (original)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/all-failing.xml Sun Jun 26
07:35:20 2011
@@ -11,9 +11,9 @@
       <class name="org.jboss.jsr299.tck.tests.context.conversation.LongRunningConversationPropagatedByFacesContextTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.conversation.ManualCidPropagationTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.dependent.DependentContextTest"/>
-      <class name="org.jboss.jsr299.tck.tests.context.dependent.ejb.DependentContextEjbTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.dependentScopedProducerFieldReturnsNonSerializableObjectForInjectionIntoStatefulSessionBean.EnterpriseBeanWithIllegalDependencyTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.dependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoStatefulSessionBean.EnterpriseBeanWithIllegalDependencyTest"/>
+      <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.enterpriseBeanWithNonPassivatingDecorator.EnterpriseBeanWithNonPassivatingDecoratorTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.request.RequestContextTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.request.ejb.EJBRequestContextTest"/>
       <class name="org.jboss.jsr299.tck.tests.context.session.SessionContextTest"/>

Modified: openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml?rev=1139723&r1=1139722&r2=1139723&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml (original)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml Sun Jun 26 07:35:20
2011
@@ -60,12 +60,6 @@
           <exclude name="testInstanceUsedForElEvaluationNotShared"/>
         </methods>
       </class>
-      <class name="org.jboss.jsr299.tck.tests.context.dependent.ejb.DependentContextEjbTest">
-        <methods>
-          <exclude name="testDestroyingEjbDestroysDependentSimples"/>
-          <exclude name="testDestroyingEjbDestroysDependents"/>
-        </methods>
-      </class>
       <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.dependentScopedProducerFieldReturnsNonSerializableObjectForInjectionIntoStatefulSessionBean.EnterpriseBeanWithIllegalDependencyTest">
         <methods>
           <exclude name="test"/>
@@ -76,6 +70,11 @@
           <exclude name="test"/>
         </methods>
       </class>
+      <class name="org.jboss.jsr299.tck.tests.context.passivating.broken.enterpriseBeanWithNonPassivatingDecorator.EnterpriseBeanWithNonPassivatingDecoratorTest">
+        <methods>
+          <exclude name="testEnterpriseBeanWithNonPassivatingDecoratorFails"/>
+        </methods>
+      </class>
       <class name="org.jboss.jsr299.tck.tests.context.request.RequestContextTest">
         <methods>
           <exclude name="testRequestScopeActiveDuringServiceMethod"/>
@@ -120,7 +119,6 @@
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle.EnterpriseBeanLifecycleTest">
         <methods>
           <exclude name="testCreateSFSB"/>
-          <exclude name="testDependentObjectsDestroyed"/>
           <exclude name="testSerializeSFSB"/>
         </methods>
       </class>
@@ -144,8 +142,8 @@
         <methods>
           <exclude name="testBeanTypesAndBindingTypesOfPersistenceContext"/>
           <exclude name="testInjectionOfPersistenceUnit"/>
-          <exclude name="testInjectionOfPersistenceContext"/>
           <exclude name="testPassivationOfPersistenceContext"/>
+          <exclude name="testInjectionOfPersistenceContext"/>
           <exclude name="testPassivationOfPersistenceUnit"/>
         </methods>
       </class>



Mime
View raw message