/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.jfox.ejb;

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

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

public abstract class SessionBulk extends BulkSupport implements SessionOperation {

  public SessionBulk(BulkMetaData 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 ObjectId createBean(Invocation invocation) throws Exception;
}