分享

ejb3.0实体bean例子

 sonny--李永胜 2007-03-30
 
package org.sonny.human.entity;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.AccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.hibernate.annotations.GenericGenerator;
import cn.bizos.util.PinYin;
@XmlAccessorType(AccessType.FIELD)
@XmlRootElement(name = "person")
@XmlType(name = "", propOrder = {"details"})
@Entity
@Table(name = "t_person", uniqueConstraints = { @UniqueConstraint(columnNames = { "id" }) })
public class Person {
 
 @XmlAttribute
 private String account;
 
 @XmlAttribute
 private String domainId;
 @XmlAttribute
 private String ownerId;
 @XmlAttribute
 private boolean share;
 @XmlAttribute
 private int type;
 @XmlAttribute
 private boolean valid;
 @XmlAttribute
 private String id;
 
 @XmlAttribute
 private String chineseName;
 
 @XmlAttribute
 private String engName;
 
 @XmlAttribute
 private String companyName;
 
 @XmlAttribute
 private String department;
 
 @XmlAttribute
 private String extension;
 
 @XmlAttribute
 private String phone;
 
 @XmlAttribute
 private String email;
 
 @XmlAttribute
 private String position;
 
 @XmlAttribute
 private String shortcompany;
 
 @XmlAttribute
 private String companykind;
 
 @XmlAttribute
 private String sortIndex1;
 
 @XmlAttribute
 private String sortIndex2;
 
 @XmlAttribute
 private String image;
 
 @XmlAttribute
 private String sex; 
 
 private Set<PersonDetail> details = new HashSet<PersonDetail>();
 /**
  * @roseuid 442205E00223
  */
 public Person() {
 }
 
 @Transient
 public String getChineseName() {
  return this.chineseName;
 }
 public void setChineseName(String chineseName) {
  this.chineseName = chineseName;
 }
 @Transient
 public String getExtension() {
  return this.extension;
 }
 public void setExtension(String extension) {
  this.extension = extension;
 }
 @Transient
 public String getPhone() {
  return this.phone;
 }
 public void setPhone(String phone) {
  this.phone = phone;
 }
 @Transient
 public String getEmail() {
  return this.email;
 }
 public void setEmail(String email) {
  this.email = email;
 }
 @Transient
 public String getPosition() {
  return this.position;
 }
 public void setPosition(String position) {
  this.position = position;
 }
 
 @Transient
 public String getEngName() {
  return this.engName;
 }
 
 public void setEngName(String engName) {
  this.engName = engName;
 }
 @Transient
 public String getCompanyName() {
  return this.companyName;
 }
 
 public void setCompanyName(String companyName) {
  this.companyName = companyName;
 }
 @Transient
 public String getDepartment() {
  return this.department;
 }
 
 public void setDepartment(String department) {
  this.department = department;
 }
 
 @Column(name = "account", unique = false, nullable = true, insertable = true, updatable = true, length = 61)
 public String getAccount() {
  return account;
 }
 public void setAccount(String account) {
  this.account = account;
 }
 @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
 @JoinColumn(name="person_id")
 @OrderBy("type")
 public Set<PersonDetail> getDetails() {
  return details;
 }
 public void setDetails(Set<PersonDetail> details) {  
  this.details = details;
 }
 @Column(name = "domain_id", unique = false, nullable = false, insertable = true, updatable = true, length = 36)
 public String getDomainId() {
  return domainId;
 }
 public void setDomainId(String domainId) {
  this.domainId = domainId;
 }
 @Id
 @GeneratedValue(generator="system-uuid")
 @GenericGenerator(name="system-uuid", strategy = "uuid")
 public String getId() {
  return id;
 }
 public void setId(String id) {
  this.id = id;
 }
 @Column(name = "owner_id", unique = false, nullable = true, insertable = true, updatable = true, length = 36)
 public String getOwnerId() {
  return ownerId;
 }
  public void setSex(String sex) {
   this.sex = sex;
  }
  @Column(name = "sex", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
  public String getSex() {
   return sex;
  }
 public void setOwnerId(String ownerId) {
  this.ownerId = ownerId;
 }
 @Column(name = "share", unique = false, nullable = true, insertable = true, updatable = true)
 public boolean isShare() {
  return share;
 }
 public void setShare(boolean share) {
  this.share = share;
 }
 @Column(name = "type", unique = false, nullable = false, insertable = true, updatable = true)
 public int getType() {
  return type;
 }
 public void setType(int type) {
  this.type = type;
 }
 @Column(name = "valid", unique = false, nullable = false, insertable = true, updatable = true)
 public boolean isValid() {
  return valid;
 }
 public void setValid(boolean valid) {
  this.valid = valid;
 }
 
 public PersonDetail detailFirstValueByType(int detailType) {
  PersonDetail result = new PersonDetail();
  for(PersonDetail detail : details) {
   if(detail.getType() == detailType){
    result = detail;
    break;
   }
  }
  return result;  
 }
 
 public Set<PersonDetail> detailValuesByType(int detailType) {
  Set<PersonDetail> pds = new HashSet<PersonDetail>();
  for(PersonDetail detail : details) {
   if(detail.getType() == detailType){
    pds.add(detail);
   }
  }
  return pds;
 }
 
 public void initFieldsFromPersonDetail() {
  this.chineseName = detailFirstValueByType(DetailType.chineseName).getValue();
  this.engName = detailFirstValueByType(DetailType.engName).getValue();
  this.companyName = detailFirstValueByType(DetailType.companyName).getValue();
  this.department = detailFirstValueByType(DetailType.department).getValue();
  this.position = detailFirstValueByType(DetailType.position).getValue();
  this.extension = detailFirstValueByType(DetailType.extension).getValue();
  this.shortcompany = detailFirstValueByType(DetailType.shortcompany).getValue();
  this.companykind = detailFirstValueByType(DetailType.companykind).getValue();
  this.sortIndex1 = getAccountsByName(companykind);
  this.sortIndex2 = getAccountsByName(shortcompany);
  int[] etypes = {20, 21, 22};
  PersonDetail detail = null;
  for(int j = 0; j < etypes.length; j++) {
   detail = detailFirstValueByType(etypes[j]);
   if(detail.getValue() != null) {
    break;
   }
  }
  this.email = detail.getValue();
  int[] types = {14, 15, 16, 17, 18, 19};
  for(int n = 0; n < types.length; n++) {
   detail = detailFirstValueByType(types[n]);
   if(detail.getValue() != null) {
    break;
   }
  }
  this.phone = detail.getValue();
 }
 @Override
 public boolean equals(Object obj) { 
  return hashCode() == obj.hashCode();
 }
 @Override
 public int hashCode() {
  int result = 17;       
        result = 37 * result + ( (id == null) ? 0 : id.hashCode() );       
        return result;
 }
 @Column(name = "image", unique = false, nullable = true, insertable = true, updatable = true, length = 500)
 public String getImage() {
  return image;
 }
 public void setImage(String image) {
  this.image = image;
 }
 
 @Transient
 public String getShortcompany() {
  return shortcompany;
 }
 public void setShortcompany(String shortcompany) {
  this.shortcompany = shortcompany;
 }
 @Transient
 public String getCompanykind() {
  return companykind;
 }
 public void setCompanykind(String companykind) {
  this.companykind = companykind;
 }
 @Transient
 public String getSortIndex1() {
  return sortIndex1;
 }
 public void setSortIndex1(String sortIndex1) {
  this.sortIndex1 = sortIndex1;
 }
 @Transient
 public String getSortIndex2() {
  return sortIndex2;
 }
 public void setSortIndex2(String sortIndex2) {
  this.sortIndex2 = sortIndex2;
 }
 
 private String getAccountsByName(String name) {
  if(name == null) return "";
  PinYin py = new PinYin();
  List<String> accounts =  py.translate(name);
  if(accounts != null) {
   if(accounts.size() > 0) {
    return accounts.get(0);
   }
  }
  return "";
 }
 
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多