Java tutorial
/* * Copyright 2012 Eng Kam Hon (kamhon@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.kamhon.ieagle.function.user.vo; import java.util.Set; import javax.persistence.Access; import javax.persistence.AccessType; 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.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; import net.kamhon.ieagle.vo.Manipulateable; import net.kamhon.ieagle.vo.annotation.ToTrim; import net.kamhon.ieagle.vo.annotation.ToUpperCase; import org.apache.commons.lang.builder.HashCodeBuilder; import org.hibernate.annotations.GenericGenerator; @Entity @Table(name = "app_user_loc") @Access(AccessType.FIELD) public class UserLoc extends net.kamhon.ieagle.vo.VoBase implements Manipulateable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") @Column(name = "loc_id", unique = true, nullable = false, length = 32) private String locId; @Column(name = "comp_id", nullable = false, length = 32) private String compId; @Column(name = "loc_type_id") private String locTypeId; @ManyToOne @JoinColumn(name = "loc_type_id", insertable = false, updatable = false, nullable = true) private UserLocType userLocType; @ToTrim @ToUpperCase @Column(name = "loc_code", length = 5) private String locCode; @ToTrim @ToUpperCase @Column(name = "loc_name", length = 50) private String locName; @ToTrim @ToUpperCase @Column(name = "loc_desc", length = 200) private String locDesc; @Column(name = "include_sub_loc") private Boolean includeSubLoc; @Column(name = "root_loc_id") private Long rootLocId; @Column(name = "parent_loc_id") private Long parentLocId; @ManyToOne @JoinColumn(name = "parent_loc_id", insertable = false, updatable = false, nullable = true) private UserLoc parentLoc; @ToTrim @ToUpperCase @Column(name = "status", length = 1) private String status; @OneToMany(mappedBy = "parentLoc", fetch = FetchType.LAZY) @OrderBy(value = "locCode") private Set<UserLoc> childLocs; public UserLoc() { } public UserLoc(String locId) { this.locId = locId; } public UserLoc(boolean defaultValue) { if (defaultValue) { includeSubLoc = false; } } public String getLocId() { return locId; } public String getCompId() { return compId; } public String getLocTypeId() { return locTypeId; } public String getLocCode() { return locCode; } public String getLocName() { return locName; } public String getLocDesc() { return locDesc; } public Boolean getIncludeSubLoc() { return includeSubLoc; } public Long getParentLocId() { return parentLocId; } public String getStatus() { return status; } public void setLocId(String locId) { this.locId = locId; } public void setCompId(String compId) { this.compId = compId; } public void setLocTypeId(String locTypeId) { this.locTypeId = locTypeId; } public void setLocCode(String locCode) { this.locCode = locCode; } public void setLocName(String locName) { this.locName = locName; } public void setLocDesc(String locDesc) { this.locDesc = locDesc; } public void setIncludeSubLoc(Boolean includeSubLoc) { this.includeSubLoc = includeSubLoc; } public void setParentLocId(Long parentLocId) { this.parentLocId = parentLocId; } public void setStatus(String status) { this.status = status; } public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final UserLoc other = (UserLoc) obj; if (this.locId == null) { if (other.locId != null) return false; } else if (!this.locId.equals(other.locId)) return false; return true; } public int hashCode() { HashCodeBuilder hashCode = new HashCodeBuilder(); if (locId != null) hashCode.append(locId); return hashCode.toHashCode(); } public UserLoc getParentLoc() { return parentLoc; } public void setParentLoc(UserLoc parentLoc) { this.parentLoc = parentLoc; } public Set<UserLoc> getChildLocs() { return childLocs; } public void setChildLocs(Set<UserLoc> childLocs) { this.childLocs = childLocs; } public UserLocType getUserLocType() { return userLocType; } public void setUserLocType(UserLocType userLocType) { this.userLocType = userLocType; } public Long getRootLocId() { return rootLocId; } public void setRootLocId(Long rootLocId) { this.rootLocId = rootLocId; } public boolean isApproveable() { return true; } public boolean isEditable() { return true; } public boolean isDeleteable() { return false; } }