/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.ejb;

import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.EnterpriseBean;
import javax.ejb.Handle;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

/**
 * 实现对于 SessionBean 统一的方法
 *
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public abstract class SessionBucket extends BucketSupport implements SessionOperation {

    public SessionBucket(BucketMetaData meta) {
        super(meta);
    }

    public Object getPrimaryKey(EnterpriseBean obj) throws RemoteException {
        throw new RemoteException("getPrimaryKey(EJBObject obj) can not be called on an session bean");
    }

    public Handle getHandle(EnterpriseBean obj) throws RemoteException {
        // 因为在客户端实现，所以这里不用实现，见　JRMPContainerInvoker
        return null;
    }

    public void ejbActivate(SessionBean bean) throws EJBException, RemoteException {
        logger.debug(bean + " activate");
        bean.ejbActivate();
    }

    public void ejbPassivate(SessionBean bean) throws EJBException, RemoteException {
        logger.debug(bean + " passivate");
        bean.ejbPassivate();
    }

    public void ejbRemove(SessionBean bean) throws EJBException, RemoteException {
        logger.debug(bean + " remove");
        bean.ejbRemove();
    }

    public void setSessionContext(SessionBean bean, SessionContext ctx) throws EJBException, RemoteException {
        logger.debug(bean + " setSessionContext");
        bean.setSessionContext(ctx);
    }

    // removeByPrimaryKey 这个方法因为已经在 JRMPContainerInvoker 客户端执行，所以从不会调用
    public void remove(Object parimaryKey) throws RemoteException, RemoveException {
        throw new RemoteException("remove(java.lang.Object primaryKey) can not be used for a session bean");
    }

    public abstract EJBPoolableObject retrieveBean(Object key) throws Exception;

    public abstract void restoreBean(Object key, EJBPoolableObject pobj);

    public abstract EJBObjectId createBean(Invocation invocation) throws Exception;
}