Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2011, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file 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;
 
 import java.util.Map;
 
 
 import  org.jboss.invocation.Interceptor;
 import  org.jboss.invocation.InterceptorContext;

Author(s):
Stuart Douglas
 
 public class EntityBeanComponentInstance extends EjbComponentInstance {

    
The primary key of this instance, is it is associated with an object identity
 
     private volatile Object primaryKey;
     private volatile EntityContextImpl entityContext;
     private volatile boolean removed = false;
     private volatile boolean synchronizeRegistered;
 
     private final Interceptor ejbStore;
     private final Interceptor ejbActivate;
     private final Interceptor ejbLoad;
     private final Interceptor ejbPassivate;
     private final Interceptor unsetEntityContext;
 
     protected EntityBeanComponentInstance(final BasicComponent componentfinal AtomicReference<ManagedReferenceinstanceReferencefinal Interceptor preDestroyInterceptorfinal Map<Method, Interceptor> methodInterceptors) {
         super(componentinstanceReferencepreDestroyInterceptormethodInterceptors);
         final EntityBeanComponent ejbComponent = (EntityBeanComponentcomponent;
         this. = ejbComponent.createInterceptor(ejbComponent.getEjbStore());
         this. = ejbComponent.createInterceptor(ejbComponent.getEjbActivate());
         this. = ejbComponent.createInterceptor(ejbComponent.getEjbLoad());
         this. = ejbComponent.createInterceptor(ejbComponent.getEjbPassivate());
         this. = ejbComponent.createInterceptor(ejbComponent.getUnsetEntityContext());
     }
 
     @Override
     public EntityBeanComponent getComponent() {
         return (EntityBeanComponentsuper.getComponent();
     }
 
     @Override
     public EntityBean getInstance() {
         return (EntityBeansuper.getInstance();
     }
 
     public Object getPrimaryKey() {
         return ;
     }
 
 
     public void discard() {
         if (!isDiscarded()) {
             getComponent().getCache().discard(this);
             this. = null;
         }
         super.discard();
     }
 
     @Override
     protected void preDestroy() {
         try {
             invokeUnsetEntityContext();
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    protected void invokeUnsetEntityContext() throws Exception {
        final InterceptorContext context = prepareInterceptorContext();
        final EntityBeanComponent component = getComponent();
        context.setMethod(component.getUnsetEntityContextMethod());
        context.putPrivateData(InvocationType.class.);
        .processInvocation(context);
    }

    
Associates this entity with a primary key. This method is called when an entity bean is moved from the pool to the entity cache

Parameters:
primaryKey The primary key to associate the entity with
    public synchronized void associate(Object primaryKey) {
        this. = primaryKey;
        try {
            final InterceptorContext context = prepareInterceptorContext();
            final EntityBeanComponent component = getComponent();
            final Method ejbActivateMethod = component.getEjbActivateMethod();
            context.setMethod(ejbActivateMethod);
            context.putPrivateData(InvocationType.class.);
            .processInvocation(context);
            final InterceptorContext loadContext = prepareInterceptorContext();
            context.putPrivateData(InvocationType.class.);
            loadContext.setMethod(component.getEjbLoadMethod());
            .processInvocation(loadContext);
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    
Invokes the ejbStore method
    public synchronized void store() {
        try {
            if (!) {
                invokeEjbStore();
            }
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    protected void invokeEjbStore() throws Exception {
        final InterceptorContext context = prepareInterceptorContext();
        final EntityBeanComponent component = getComponent();
        context.setMethod(component.getEjbStoreMethod());
        .processInvocation(context);
    }

    
Prepares the instance for release by calling the ejbPassivate method.

This method does not actually release this instance into the pool

    public synchronized void passivate() {
        try {
            if (!) {
                final InterceptorContext context = prepareInterceptorContext();
                final EntityBeanComponent component = getComponent();
                context.setMethod(component.getEjbPassivateMethod());
                context.putPrivateData(InvocationType.class.);
                .processInvocation(context);
            }
             = null;
             = false;
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public void setupContext(final InterceptorContext interceptorContext) {
        final InvocationType invocationType = interceptorContext.getPrivateData(InvocationType.class);
        try {
            interceptorContext.putPrivateData(InvocationType.class.);
            final EntityContextImpl entityContext = new EntityContextImpl(this);
            setEjbContext(entityContext);
            getInstance().setEntityContext(entityContext);
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            interceptorContext.putPrivateData(InvocationType.classinvocationType);
        }
    }
    public EntityContextImpl getEjbContext() {
        return ;
    }
    protected void setEjbContext(EntityContextImpl entityContext) {
        this. = entityContext;
    }
    public EJBObject getEjbObject() {
        final Object pk = getPrimaryKey();
        if (pk == null) {
        }
        return getComponent().getEJBObject(pk);
    }
    public EJBLocalObject getEjbLocalObject() {
        final Object pk = getPrimaryKey();
        if (pk == null) {
        }
        return getComponent().getEJBLocalObject(pk);
    }
    public boolean isRemoved() {
        return ;
    }
    public void setRemoved(final boolean removed) {
        this. = removed;
    }
    public synchronized void setSynchronizationRegistered(final boolean synchronizeRegistered) {
        this. = synchronizeRegistered;
    }
    public synchronized boolean isSynchronizeRegistered() {
        return ;
    }
    protected void clearPrimaryKey() {
        this. = null;
    }

    
Remove all timers for this entity bean. This method is transactional, so if the current TX is rolled back the timers will not be removed
    public void removeAllTimers() {
        //cancel all timers for this entity
        for (final Timer timer : getComponent().getTimerService().getTimers()) {
            if (timer instanceof TimerImpl) {
                TimerImpl timerImpl = (TimerImpltimer;
                if (timerImpl.getPrimaryKey() != null && timerImpl.getPrimaryKey().equals(getPrimaryKey())) {
                    timer.cancel();
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X