Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2010, Red Hat Inc., and individual contributors as indicated
   * by the @authors tag. See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.as.ejb3.component.entity.interceptors;
 
 
 
 import  org.jboss.invocation.ImmediateInterceptorFactory;
 import  org.jboss.invocation.InterceptorContext;
 import  org.jboss.invocation.InterceptorFactory;
 
 import static org.jboss.as.ejb3.EjbLogger.ROOT_LOGGER;
 import static org.jboss.as.ejb3.EjbMessages.MESSAGES;

Interceptor factory for entity beans that associates an invocation with a primary key

Author(s):
Stuart Douglas
 
 
     public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new EntityBeanAssociatingInterceptor());
 
     @Override
     public Object processInvocation(final InterceptorContext contextthrows Exception {
         final EntityBeanComponent component = getComponent(contextEntityBeanComponent.class);
 
         final Object primaryKey = context.getPrivateData(.);
         if (primaryKey == null) {
             throw .primaryKeyIsNull();
         }
         final EntityBeanComponentInstance instance;
         try {
             instance = component.getCache().get(primaryKey);
 
             if (instance.isRemoved()) {
                 component.getCache().release(instancetrue);
                 throw .instanceWasRemoved(component.getComponentName(), primaryKey);
             }
         } catch (javax.ejb.NoSuchEntityException e) {
             //if this is a timer service invocation we throw a special exception
             //that tells the invoker that this timer no longer exists, and can be removed
 
             if (context.getPrivateData(InvocationType.class) == .) {
                 throw new BeanRemovedException(e);
             }
             throw e;
         }
 
         try {
             context.putPrivateData(ComponentInstance.classinstance);
             return context.proceed();
         } catch (Exception ex) {
             // Detect app exception
             if (component.getApplicationException(ex.getClass(), context.getMethod()) != null) {
                 // it's an application exception, just throw it back.
                 throw ex;
             }
             if (ex instanceof ConcurrentAccessTimeoutException || ex instanceof ConcurrentAccessException) {
                 throw ex;
             }
             if (ex instanceof RuntimeException || ex instanceof RemoteException) {
                 if (.isTraceEnabled())
                     .trace("Discarding bean " + primaryKey + " because of exception"ex);
                 instance.discard();
             }
             throw ex;
         } catch (final Error e) {
             if (.isTraceEnabled())
                 .trace("Discarding bean " + primaryKey + " because of error"e);
             instance.discard();
             throw e;
        } catch (final Throwable t) {
            if (.isTraceEnabled())
                .trace("Discarding bean " + primaryKey + " because of Throwable"t);
            instance.discard();
            throw new RuntimeException(t);
        } finally {
            // the StatefulSessionSynchronizationInterceptor will take care of releasing
            context.putPrivateData(ComponentInstance.classnull);
        }
    }
New to GrepCode? Check out our FAQ X