FileDocCategorySizeDatePackage
EntityContextImpl.javaAPI DocGlassfish v2 API8910Fri May 04 22:32:58 BST 2007com.sun.ejb.containers

EntityContextImpl

public class EntityContextImpl extends EJBContextImpl implements EntityContext
Implementation of EJBContext for EntityBeans

Fields Summary
private int
lastTxStatus
private boolean
newlyActivated
private int
nCallsInProgress
private boolean
dirty
private boolean
inUnsetEntityContext
private boolean
inEjbLoad
private boolean
inEjbStore
private boolean
cascadeDeleteBeforeEJBRemove
private boolean
cascadeDeleteAfterSuperEJBRemove
private Object
_primaryKey
private int
_pkHashCode
private EntityContextImpl
_next
Constructors Summary
EntityContextImpl(Object ejb, BaseContainer container)


        
        super(ejb, container);
    
Methods Summary
final com.sun.ejb.containers.EntityContextImpl_getNext()

	return _next;
    
final int_getPKHashCode()

	return this._pkHashCode;
    
final void_setNext(com.sun.ejb.containers.EntityContextImpl val)

	this._next = val;
    
final voidcachePrimaryKey()

	Object pk = getPrimaryKey();
	this._primaryKey = pk;
	this._pkHashCode = pk.hashCode();
    
protected voidcheckAccessToCallerSecurity()

        if( state == NOT_INITIALIZED || inUnsetEntityContext ) {
            throw new IllegalStateException("Operation not allowed");
        }
        checkActivatePassivate();
        
        if (inEjbLoad || inEjbStore) {
            // Security access is allowed from these two methods.  In the
            // case that they are invoked as part of an ejbTimeout call,
            // getCallerPrincipal will return null and isCallerInRole will
            // be false
            return;
        }
    
public voidcheckTimerServiceMethodAccess()

        
        // Prohibit access from constructor, setEntityContext, ejbCreate,
        // ejbActivate, ejbPassivate, unsetEntityContext, ejbFind
        if( (state == NOT_INITIALIZED) ||
        inUnsetEntityContext ||
        inFinder() ||
        inActivatePassivate() ||
        !hasIdentity() ) {
            throw new IllegalStateException("Operation not allowed");
        }
        
    
final voidclearCachedPrimaryKey()

	this._primaryKey = null;
    
synchronized voiddecrementCalls()

        nCallsInProgress--;
    
final booleandoesMatch(BaseContainer baseContainer, int pkHashCode, java.lang.Object pk)

	return (
	    (container == baseContainer)
	    && (_pkHashCode == pkHashCode)
	    && (_primaryKey.equals(pk))
	);
    
public EJBObjectgetEJBObject()
Implementation of EntityContext method, overrides EJBContextImpl method.

        if (! isRemoteInterfaceSupported) {
            throw new IllegalStateException("EJBObject not available");
        }

        if ( ejbStub == null ) {
            Object pkey = getPrimaryKey(); // throws IllegalStateException
            ejbStub = ((EntityContainer) container).getEJBObjectStub(pkey, null);
        }

        return ejbStub;
    
intgetLastTransactionStatus()

        return lastTxStatus;
    
public java.lang.ObjectgetPrimaryKey()
Implementation of EntityContext method.

        if ( ejbObjectImpl == null && ejbLocalObjectImpl == null ) {
            // There is no ejbObjectImpl/localObject in ejbCreate, ejbFind,
            // setEntityCtx etc
            throw new IllegalStateException("Primary key not available");
        }
        
        if ( ejbLocalObjectImpl != null )
            return ejbLocalObjectImpl.getKey();
        else
            return ejbObjectImpl.getKey();
    
public TimerServicegetTimerService()

        if( state == NOT_INITIALIZED || inUnsetEntityContext || inFinder() ) {
            throw new IllegalStateException("Operation not allowed");
        }
     
        ContainerFactoryImpl cf = (ContainerFactoryImpl)
            Switch.getSwitch().getContainerFactory();
        EJBTimerService timerService = cf.getEJBTimerService();
        if( timerService == null ) {
            throw new EJBException("EJB Timer service not available");
        }
        return new EJBTimerServiceWrapper(timerService,
                                          (EntityContextImpl) this);
    
booleanhasIdentity()

        return( (ejbObjectImpl != null) || (ejbLocalObjectImpl != null) );
    
booleanhasReentrantCall()

        return (nCallsInProgress > 1);
    
private booleaninFinder()

        boolean inFinder = false;
        ComponentInvocation i = 
            container.invocationManager.getCurrentInvocation();
        if ( i instanceof Invocation ) {
            Invocation inv = (Invocation) i;
            Method currentMethod = inv.method;
            inFinder = ( (currentMethod != null) && inv.isHome &&
                         currentMethod.getName().startsWith("find") );
        }
        return inFinder;
    
synchronized voidincrementCalls()

        nCallsInProgress++;
    
public final booleanisCascadeDeleteAfterSuperEJBRemove()

        return cascadeDeleteAfterSuperEJBRemove;
    
public final booleanisCascadeDeleteBeforeEJBRemove()

        return cascadeDeleteBeforeEJBRemove;
    
booleanisDirty()

        return dirty;
    
booleanisNewlyActivated()

        return newlyActivated;
    
public final voidsetCascadeDeleteAfterSuperEJBRemove(boolean value)

        this.cascadeDeleteAfterSuperEJBRemove = value;
    
public final voidsetCascadeDeleteBeforeEJBRemove(boolean value)

        this.cascadeDeleteBeforeEJBRemove = value;
    
voidsetDirty(boolean b)

        dirty = b;
    
voidsetInEjbLoad(boolean flag)

        inEjbLoad = flag;
    
voidsetInEjbStore(boolean flag)

        inEjbStore = flag;
    
voidsetInUnsetEntityContext(boolean flag)

        inUnsetEntityContext = flag;
    
voidsetLastTransactionStatus(int status)

        lastTxStatus = status;
    
voidsetNewlyActivated(boolean b)

        newlyActivated = b;
    
voidsetState(int s)

        state = s;
        if ( state == EntityContainer.POOLED || 
            state == EntityContainer.DESTROYED )
        {
            dirty = false;
        }