PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/component/entity/interceptors/EntityBeanIsIdenticalInterceptorFactory.java

#
Java | 84 lines | 45 code | 12 blank | 27 comment | 3 complexity | 344a93acca34b538b40ee4aaec390d88 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.ejb3.component.entity.interceptors;
  23. import javax.ejb.EJBLocalObject;
  24. import javax.ejb.EJBObject;
  25. import org.jboss.as.ee.component.ComponentInstance;
  26. import org.jboss.as.ee.component.ComponentView;
  27. import org.jboss.as.ejb3.component.entity.EntityBeanComponent;
  28. import org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance;
  29. import org.jboss.invocation.Interceptor;
  30. import org.jboss.invocation.InterceptorContext;
  31. import org.jboss.invocation.InterceptorFactory;
  32. import org.jboss.invocation.InterceptorFactoryContext;
  33. /**
  34. * Interceptor that handles the {@link javax.ejb.EJBLocalObject#isIdentical(javax.ejb.EJBLocalObject)}
  35. * && {@link javax.ejb.EJBObject#isIdentical(javax.ejb.EJBObject)} methods
  36. *
  37. * @author Stuart Douglas
  38. */
  39. public class EntityBeanIsIdenticalInterceptorFactory implements InterceptorFactory {
  40. public static final EntityBeanIsIdenticalInterceptorFactory INSTANCE = new EntityBeanIsIdenticalInterceptorFactory();
  41. private EntityBeanIsIdenticalInterceptorFactory() {
  42. }
  43. @Override
  44. public Interceptor create(final InterceptorFactoryContext context) {
  45. final ComponentView componentView = (ComponentView) context.getContextData().get(ComponentView.class);
  46. return new EntityIsIdenticalInterceptor(componentView);
  47. }
  48. private class EntityIsIdenticalInterceptor implements Interceptor {
  49. private final ComponentView componentView;
  50. public EntityIsIdenticalInterceptor(final ComponentView componentView) {
  51. this.componentView = componentView;
  52. }
  53. @Override
  54. public Object processInvocation(final InterceptorContext context) throws Exception {
  55. final EntityBeanComponentInstance instance = (EntityBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
  56. try {
  57. final Object primaryKey = context.getPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY);
  58. final Object other = context.getParameters()[0];
  59. if (!componentView.getViewClass().isAssignableFrom(other.getClass())) {
  60. return false;
  61. }
  62. if (context.getMethod().getParameterTypes()[0].equals(EJBLocalObject.class)) {
  63. return ((EJBLocalObject) other).getPrimaryKey().equals(primaryKey);
  64. } else {
  65. return ((EJBObject) other).getPrimaryKey().equals(primaryKey);
  66. }
  67. } finally {
  68. instance.getComponent().getCache().release(instance, true);
  69. }
  70. }
  71. }
  72. }