[jboss-user] [EJB 3.0] - Re: SOS

zhuhuapeng@gmail.com do-not-reply at jboss.com
Tue Aug 26 09:54:35 EDT 2008


please see the following code : 
OrganizationEO 
  | package jpa.entity.cattle;
  | 
  | import java.io.Serializable;
  | import java.lang.reflect.InvocationTargetException;
  | import java.util.List;
  | 
  | import javax.persistence.CascadeType;
  | import javax.persistence.Column;
  | import javax.persistence.Entity;
  | import javax.persistence.FetchType;
  | import javax.persistence.GeneratedValue;
  | import javax.persistence.GenerationType;
  | import javax.persistence.Id;
  | import javax.persistence.JoinColumn;
  | import javax.persistence.ManyToOne;
  | import javax.persistence.OneToMany;
  | import javax.persistence.Table;
  | import javax.persistence.Transient;
  | 
  | import org.apache.commons.beanutils.BeanUtils;
  | 
  | 
  | /**
  |  * 标准组织结构表.
  |  * 
  |  * @author howard.zhu
  |  * 
  |  */
  | @Entity
  | @Table(name="BAS_ORGANIZATION")
  | public class OrganizationEO  extends SmallToad implements Serializable {
  | 
  | 	private static final long serialVersionUID = 8137282822392486399L;
  | 
  | 
  | 	private int id;
  | 	/**
  | 	 * 对应的上级机构的ID.
  | 	 * 当本身就属于最高级时,å
¶parentId 值为null.
  | 	 */
  | 	private OrganizationEO parentObj; 
  | //	private Integer parentId;
  | 	/**
  | 	 * 本级机构名.
  | 	 */
  | 	private String unitName; 
  | 	/**
  | 	 * 本级机构的区域编码.
  | 	 * 诸如'宁夏自治区'的区域编码就是'N'.
  | 	 * 所有属于'宁夏自治区'的市,县均得以'N'开头,å
¶åŽè·Ÿè‡ªèº«çš„编码号.
  | 	 * 该值唯一.
  | 	 * 
  | 	 */
  | 	private String code;
  | 	/**
  | 	 * 序号.
  | 	 */
  | 	private String serialNum; 
  | 	/**
  | 	 * 联系人.
  | 	 */
  | 	private String contact;
  | 	/**
  | 	 * 联系电话.
  | 	 */
  | 	private String tel;
  | 	/**
  | 	 * 邮政编码.
  | 	 */
  | 	private String postalCode;
  | 	/**
  | 	 * 联系地址.
  | 	 */
  | 	private String address;
  | 	/**
  | 	 * 传真.
  | 	 */
  | 	private String fax;
  | 	/**
  | 	 * 电子邮箱.
  | 	 */
  | 	private String email;
  | 	/**
  | 	 * 备注
  | 	 */
  | 	private String memo;
  | 	
  | 	/**
  | 	 * 该组织的直接下属机构.
  | 	 */
  | 	private List<OrganizationEO>  sonOrgs;
  | 	
  | 	/**
  | 	 * å
¶ä¸‹æŒ‚载的所有的牛的信息.
  | 	 */
  | 	private List<CattleUnityEO> cattleUnities; 
  | 	
  | 
  | 	/**
  | 	 * @return the id
  | 	 */
  | 	@Id
  |     @GeneratedValue(strategy=GenerationType.AUTO)
  | 	public int getId() {
  | 		return id;
  | 	}
  | 
  | 	/**
  | 	 * @return the parentId
  | 	 */
  | //	public int getParentId() {
  | //		return parentId;
  | //	}
  | 	
  | 
  | 	/**
  | 	 * @return the code
  | 	 */
  | 	@Column(nullable=false,unique=true)
  | 	public String getCode() {
  | 		return code;
  | 	}
  | 
  | 	/**
  | 	 * @return the contact
  | 	 */
  | 	public String getContact() {
  | 		return contact;
  | 	}
  | 
  | 	/**
  | 	 * @return the tel
  | 	 */
  | 	public String getTel() {
  | 		return tel;
  | 	}
  | 
  | 	/**
  | 	 * @return the postalCode
  | 	 */
  | 	public String getPostalCode() {
  | 		return postalCode;
  | 	}
  | 
  | 	/**
  | 	 * @return the address
  | 	 */
  | 	public String getAddress() {
  | 		return address;
  | 	}
  | 
  | 	/**
  | 	 * @return the fax
  | 	 */
  | 	public String getFax() {
  | 		return fax;
  | 	}
  | 
  | 	/**
  | 	 * @return the email
  | 	 */
  | 	public String getEmail() {
  | 		return email;
  | 	}
  | 
  | 	/**
  | 	 * @return the memo
  | 	 */
  | 	public String getMemo() {
  | 		return memo;
  | 	}
  | 
  | 	
  | 	
  | 	
  | 	/**
  | 	 * @return the unitName
  | 	 */
  | 	@Column(nullable=false,length=32)
  | 	public String getUnitName() {
  | 		return unitName;
  | 	}
  | 	
  | 	
  | 
  | 	/**
  | 	 * @return the sonOrgs
  | 	 */
  | 	@OneToMany(cascade={CascadeType.ALL},mappedBy="parentObj",fetch=FetchType.EAGER)
  | 	public List<OrganizationEO> getSonOrgs() {
  | 		return sonOrgs;
  | 	}
  | 
  | 	
  | 	
  | 	
  | 	/**
  | 	 * @return the parentObj
  | 	 */
  | 	@ManyToOne
  | 	@JoinColumn(name = "parent_id")
  | 	public OrganizationEO getParentObj() {
  | 		return parentObj;
  | 	}
  | 	
  | 	
  | 
  | 	/**
  | 	 * @return the cattleUnities
  | 	 */
  | 	@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY,mappedBy="organization")
  | 	public List<CattleUnityEO> getCattleUnities() {
  | 		return cattleUnities;
  | 	}
  | 
  | 	
  | 	@Column(nullable=false)
  | 	public String getSerialNum() {
  | 		return serialNum;
  | 	}
  | 
  | 	public void setSerialNum(String serialNum) {
  | 		this.serialNum = serialNum;
  | 	}
  | 
  | 	/**
  | 	 * @param cattleUnities the cattleUnities to set
  | 	 */
  | 	public void setCattleUnities(List<CattleUnityEO> cattleUnities) {
  | 		this.cattleUnities = cattleUnities;
  | 	}
  | 
  | 	/**
  | 	 * @param parentObj the parentObj to set
  | 	 */
  | 	public void setParentObj(OrganizationEO parentObj) {
  | 		this.parentObj = parentObj;
  | 	}
  | 
  | 	/**
  | 	 * @param sonOrgs the sonOrgs to set
  | 	 */
  | 	public void setSonOrgs(List<OrganizationEO> sonOrgs) {
  | 		this.sonOrgs = sonOrgs;
  | 	}
  | 
  | 	/**
  | 	 * @param unitName the unitName to set
  | 	 */
  | 	public void setUnitName(String unitName) {
  | 		this.unitName = unitName;
  | 	}
  | 
  | 	/**
  | 	 * @param id
  | 	 *            the id to set
  | 	 */
  | 	public void setId(int id) {
  | 		this.id = id;
  | 	}
  | 
  | 	/**
  | 	 * @param parentId
  | 	 *            the parentId to set
  | 	 */
  | //	public void setParentId(int parentId) {
  | //		this.parentId = parentId;
  | //	}
  | 
  | 	/**
  | 	 * @param code
  | 	 *            the code to set
  | 	 */
  | 	public void setCode(String code) {
  | 		this.code = code;
  | 	}
  | 
  | 	/**
  | 	 * @param contact
  | 	 *            the contact to set
  | 	 */
  | 	public void setContact(String contact) {
  | 		this.contact = contact;
  | 	}
  | 
  | 	/**
  | 	 * @param tel
  | 	 *            the tel to set
  | 	 */
  | 	public void setTel(String tel) {
  | 		this.tel = tel;
  | 	}
  | 
  | 	/**
  | 	 * @param postalCode
  | 	 *            the postalCode to set
  | 	 */
  | 	public void setPostalCode(String postalCode) {
  | 		this.postalCode = postalCode;
  | 	}
  | 
  | 	/**
  | 	 * @param address
  | 	 *            the address to set
  | 	 */
  | 	public void setAddress(String address) {
  | 		this.address = address;
  | 	}
  | 
  | 	/**
  | 	 * @param fax
  | 	 *            the fax to set
  | 	 */
  | 	public void setFax(String fax) {
  | 		this.fax = fax;
  | 	}
  | 
  | 	/**
  | 	 * @param email
  | 	 *            the email to set
  | 	 */
  | 	public void setEmail(String email) {
  | 		this.email = email;
  | 	}
  | 
  | 	/**
  | 	 * @param memo
  | 	 *            the memo to set
  | 	 */
  | 	public void setMemo(String memo) {
  | 		this.memo = memo;
  | 	}
  | 
  | 	/**
  | 	 * @param parentId the parentId to set
  | 	 */
  | //	public void setParentId(Integer parentId) {
  | //		this.parentId = parentId;
  | //	}
  | 
  | 	
  | 	
  | 	
  | 	
  | 	/* (non-Javadoc)
  | 	 * @see java.lang.Object#hashCode()
  | 	 */
  | 	@Override
  | 	public int hashCode() {
  | 		final int prime = 31;
  | 		int result = 1;
  | 		result = prime * result + ((code == null) ? 0 : code.hashCode());
  | 		result = prime * result + ((address == null) ? 0 : address.hashCode());
  | 		result = prime * result + ((contact == null) ? 0 : contact.hashCode());
  | 		result = prime * result + ((email == null) ? 0 : email.hashCode());
  | 		result = prime * result + ((fax == null) ? 0 : fax.hashCode());
  | 		result = prime * result + id;
  | 		result = prime * result + ((memo == null) ? 0 : memo.hashCode());
  | //		result = prime * result
  | //				+ ((parentId == null) ? 0 : parentId.hashCode());
  | 		result = prime * result
  | 				+ ((postalCode == null) ? 0 : postalCode.hashCode());
  | 		result = prime * result + ((tel == null) ? 0 : tel.hashCode());
  | 		result = prime * result
  | 				+ ((unitName == null) ? 0 : unitName.hashCode());
  | 		return result;
  | 	}
  | 
  | 	/* (non-Javadoc)
  | 	 * @see java.lang.Object#equals(java.lang.Object)
  | 	 */
  | 	@Override
  | 	public boolean equals(Object obj) {
  | 		if (this == obj)
  | 			return true;
  | 		if (obj == null)
  | 			return false;
  | 		if (!(obj instanceof OrganizationEO))
  | 			return false;
  | 		OrganizationEO other = (OrganizationEO) obj;
  | 		if (code == null) {
  | 			if (other.code != null)
  | 				return false;
  | 		} else if (!code.equals(other.code))
  | 			return false;
  | 		if (address == null) {
  | 			if (other.address != null)
  | 				return false;
  | 		} else if (!address.equals(other.address))
  | 			return false;
  | 		if (contact == null) {
  | 			if (other.contact != null)
  | 				return false;
  | 		} else if (!contact.equals(other.contact))
  | 			return false;
  | 		if (email == null) {
  | 			if (other.email != null)
  | 				return false;
  | 		} else if (!email.equals(other.email))
  | 			return false;
  | 		if (fax == null) {
  | 			if (other.fax != null)
  | 				return false;
  | 		} else if (!fax.equals(other.fax))
  | 			return false;
  | 		if (id != other.id)
  | 			return false;
  | 		if (memo == null) {
  | 			if (other.memo != null)
  | 				return false;
  | 		} else if (!memo.equals(other.memo))
  | 			return false;
  | //		if (parentId == null) {
  | //			if (other.parentId != null)
  | //				return false;
  | //		} else if (!parentId.equals(other.parentId))
  | //			return false;
  | 		if (postalCode == null) {
  | 			if (other.postalCode != null)
  | 				return false;
  | 		} else if (!postalCode.equals(other.postalCode))
  | 			return false;
  | 		if (tel == null) {
  | 			if (other.tel != null)
  | 				return false;
  | 		} else if (!tel.equals(other.tel))
  | 			return false;
  | 		if (unitName == null) {
  | 			if (other.unitName != null)
  | 				return false;
  | 		} else if (!unitName.equals(other.unitName))
  | 			return false;
  | 		return true;
  | 	}
  | 
  | 	@Transient
  | 	@Override
  | 	public boolean checkInsertable() {
  | 		if(null == this.getUnitName() ||("".equals(this.getUnitName().trim())))
  | 		{
  | 			return false; 
  | 		}
  | 		if(null == this.getCode() ||("".equals(this.getCode().trim())))
  | 		{
  | 			return false; 
  | 		}
  | 		if(null == this.getSerialNum() ||("".equals(this.getSerialNum().trim())))
  | 		{
  | 			return false; 
  | 		}
  | 
  | 		return true;
  | 	}
  | 	
  | 	@Transient
  | 	@Override
  | 	public   boolean checkupdateble()
  | 	{
  | 		if(this.getId() < 0)
  | 		{
  | 			return false; 
  | 		}
  | 		if(null == this.getUnitName() ||("".equals(this.getUnitName().trim())))
  | 		{
  | 			return false; 
  | 		}
  | 		if(null == this.getCode() ||("".equals(this.getCode().trim())))
  | 		{
  | 			return false; 
  | 		}
  | 		if(null == this.getSerialNum() ||("".equals(this.getSerialNum().trim())))
  | 		{
  | 			return false; 
  | 		}
  | 
  | 		return true;
  | 	}
  | 
  | 	@Transient
  | 	@Override
  | 	public   boolean checkdeleted(){
  | 		if((id <= 0))
  | 		{
  | 			return false; 
  | 		}
  | 		return true;
  | 	}
  | 	
  | 	
  | 	@Transient
  | 	@Override
  | 	public   int getIdAfterInsert()
  | 	{
  | 		return this.getId();
  | 	}
  | 	
  | 	@Transient
  | 	@Override
  | 	public  <T extends SmallToad> void copy(T t)
  | 	{
  | 		if(t instanceof OrganizationEO)
  | 		{
  | 			OrganizationEO oo = (OrganizationEO)t;
  | 			try {
  | 				BeanUtils.copyProperties(this,oo);
  | 			} catch (IllegalAccessException e) {
  | 				e.printStackTrace();
  | 			} catch (InvocationTargetException e) {
  | 				e.printStackTrace();
  | 			}
  | 		}
  | 	}
  | 
  | }
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172583#4172583

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172583




More information about the jboss-user mailing list