activitybean.java

来自「这是一个工作流管理的后端EJB实现」· Java 代码 · 共 165 行

JAVA
165
字号
/*
 * Created on 2005-5-9
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package com.coshare.joyteam.projectMgr.entitybean.activity;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;

import com.coshare.joyteam.projectMgr.dao.DAOException;
import com.coshare.joyteam.projectMgr.dao.DAOFactory;
import com.coshare.joyteam.projectMgr.dto.ActivityDTO;

/**
 * @ejb.bean name="Activity"
 *	jndi-name="ActivityBean"
 *	type="BMP" 
 **/

public class ActivityBean extends ActivityDTO implements EntityBean
{
	private EntityContext context;
	
	//
	//EntityBean接口中的方法
	//
	public void ejbActivate()
	{
		System.out.println("ejbActivate()");
	}
	public void ejbPassivate()
	{
		System.out.println("ejbPassivate ()");
	}
	public void setEntityContext(EntityContext context)
	{
		System.out.println("setEntityContext()");
		this.context = context;
	}
	public void unsetEntityContext()
	{
		System.out.println("unsetEntityContext()");
		this.context = null;
	}
	public void ejbLoad()
	{
		System.out.println("ejbLoad()");
		
		ActivityPK key = (ActivityPK) context.getPrimaryKey();
		
		try
		{
			ActivityDTO dto = DAOFactory.newInstance().getActivityDAO().getActivity(key.templateId, key.activityName, key.activityType);
			
			super.setActivityId(dto.getActivityId());
			super.setActivityName(dto.getActivityName());
			super.setActivityType(dto.getActivityType());
			super.setTemplateId(dto.getTemplateId());
			super.setTheDescription(dto.getTheDescription());
		}
		catch (DAOException e)
		{
			e.printStackTrace();
			throw new EJBException(e);
		}
	}
	public void ejbStore()
	{
		System.out.println("ejbStore()");
		
		ActivityDTO dto = new ActivityDTO();
		
		dto.setActivityId(super.getActivityId());
		dto.setActivityName(super.getActivityName());
		dto.setActivityType(super.getActivityType());
		dto.setTemplateId(super.getTemplateId());
		dto.setTheDescription(super.getTheDescription());
		
		try
		{
			DAOFactory.newInstance().getActivityDAO().Update(dto);
		}
		catch (DAOException e)
		{
			e.printStackTrace();
			throw new EJBException(e);
		}
	}
	public void ejbRemove() throws RemoveException
	{
		System.out.println("ejbRemove()");
		
		ActivityDTO dto = new ActivityDTO();
		
		dto.setActivityId(super.getActivityId());
		dto.setActivityName(super.getActivityName());
		dto.setActivityType(super.getActivityType());
		dto.setTemplateId(super.getTemplateId());
		dto.setTheDescription(super.getTheDescription());
		
		try
		{
			DAOFactory.newInstance().getActivityDAO().Delete(dto);
		}
		catch (DAOException e)
		{
			e.printStackTrace();
			throw new RemoveException(e.toString());
		}
	}
	
	
	//
	//Create方法
	//
	public void ejbPostCreate(ActivityDTO dto)
	{
		System.out.println("ejbPostCreate()");
	}
	
	public ActivityPK ejbCreate(ActivityDTO dto) throws CreateException
	{
		System.out.println("ejbCreate()");
		
		ActivityPK key = new ActivityPK(dto.getTemplateId(), dto.getActivityName(), dto.getActivityType());
		
		try
		{
			DAOFactory.newInstance().getActivityDAO().AddNew(dto);
		}
		catch (DAOException e)
		{
			e.printStackTrace();
			throw new CreateException(e.toString());
		}
		
		return key;
	}

	//
	//ejbFind方法
	//
	public ActivityPK ejbFindByPrimaryKey(ActivityPK key) throws FinderException
	{
		System.out.println("ejbFindByPrimaryKey()");
		
		try
		{
			ActivityDTO dto = DAOFactory.newInstance().getActivityDAO().getActivity(key.templateId, key.activityName, key.activityType);
			return key;
		}
		catch (DAOException e)
		{
			e.printStackTrace();
			throw new FinderException(e.toString());
		}
	} 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?