net.kamhon.ieagle.function.user.vo.UserAccessCat.java Source code

Java tutorial

Introduction

Here is the source code for net.kamhon.ieagle.function.user.vo.UserAccessCat.java

Source

/*
 * 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.ArrayList;
import java.util.List;
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.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import net.kamhon.ieagle.FrameworkConst;
import net.kamhon.ieagle.vo.annotation.ToTrim;
import net.kamhon.ieagle.vo.annotation.ToUpperCase;

import org.apache.commons.lang.builder.HashCodeBuilder;

@Entity
@Table(name = "app_user_access_cat")
@Access(AccessType.FIELD)
public class UserAccessCat extends net.kamhon.ieagle.vo.VoBase {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "cat_id")
    private Long catId;

    @Column(name = "parent_id")
    private Long parentId;

    @ManyToOne
    @JoinColumn(name = "parent_id", insertable = false, updatable = false, nullable = true)
    private UserAccessCat parentCat;

    @ToTrim
    @Column(name = "cat_name", length = 200)
    private String catName;

    @ToTrim
    @Column(name = "cat_short_name", length = 100)
    private String catShortName;

    @ToTrim
    @ToUpperCase
    @Column(name = "cat_desc", length = 255)
    private String catDesc;

    @Column(name = "sort_seq")
    private Long sortSeq;

    @ToTrim
    @ToUpperCase
    @Column(name = "status", length = 1)
    private String status;

    @Transient
    private List<UserAccess> userAccessList = new ArrayList<UserAccess>();

    @OneToMany(mappedBy = "parentCat", fetch = FetchType.LAZY)
    @OrderBy(value = "catId")
    private Set<UserAccessCat> childCats;

    public UserAccessCat() {
    }

    public UserAccessCat(Long catId) {
        this.catId = catId;
    }

    public UserAccessCat(boolean defaultValue) {
        if (defaultValue) {
            status = FrameworkConst.STATUS_APPROVED;
        }
    }

    public UserAccessCat(Long catId, String catName, String catShortName) {
        this(true);
        this.catId = catId;
        this.catName = catName;
        this.catShortName = catShortName;
        this.sortSeq = catId;
    }

    public UserAccessCat(Long catId, Long parentId, String catName, String catShortName) {
        this(true);
        this.catId = catId;
        this.parentId = parentId;
        this.catName = catName;
        this.catShortName = catShortName;
        this.sortSeq = catId;
    }

    public UserAccessCat(Long catId, String catName, String catShortName, String catDesc, Long sortSeq) {
        this(true);
        this.catId = catId;
        this.catName = catName;
        this.catShortName = catShortName;
        this.catDesc = catDesc;
        this.sortSeq = sortSeq;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Long getCatId() {
        return catId;
    }

    public String getCatName() {
        return catName;
    }

    public String getCatShortName() {
        return catShortName;
    }

    public String getCatDesc() {
        return catDesc;
    }

    public Long getSortSeq() {
        return sortSeq;
    }

    public String getStatus() {
        return status;
    }

    public void setCatId(Long catId) {
        this.catId = catId;
    }

    public void setCatName(String catName) {
        this.catName = catName;
    }

    public void setCatShortName(String catShortName) {
        this.catShortName = catShortName;
    }

    public void setCatDesc(String catDesc) {
        this.catDesc = catDesc;
    }

    public void setSortSeq(Long sortSeq) {
        this.sortSeq = sortSeq;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<UserAccess> getUserAccessList() {
        return userAccessList;
    }

    public void setUserAccessList(List<UserAccess> userAccessList) {
        this.userAccessList = userAccessList;
    }

    public UserAccessCat getParentCat() {
        return parentCat;
    }

    public void setParentCat(UserAccessCat parentCat) {
        this.parentCat = parentCat;
    }

    public Set<UserAccessCat> getChildCats() {
        return childCats;
    }

    public void setChildCats(Set<UserAccessCat> childCats) {
        this.childCats = childCats;
    }

    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        final UserAccessCat other = (UserAccessCat) obj;
        if (this.catId == null) {
            if (other.catId != null)
                return false;
        } else if (!this.catId.equals(other.catId))
            return false;
        return true;
    }

    public int hashCode() {
        HashCodeBuilder hashCode = new HashCodeBuilder();
        if (catId != null)
            hashCode.append(catId);
        return hashCode.toHashCode();
    }
}