com.dp2345.entity.ArticleCategory.java Source code

Java tutorial

Introduction

Here is the source code for com.dp2345.entity.ArticleCategory.java

Source

/*
 * Copyright 2013-2015 cetvision.com. All rights reserved.
 * Support: http://www.cetvision.com
 * License: http://www.cetvision.com/license
 */
package com.dp2345.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * Entity - 
 * 
 * @author CETVISION CORP
 * @version 2.0.3
 */
@Entity
@Table(name = "xx_article_category")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_article_category_sequence")
public class ArticleCategory extends OrderEntity {

    private static final long serialVersionUID = -5132652107151648662L;

    /**  */
    public static final String TREE_PATH_SEPARATOR = ",";

    /** ? */
    private static final String PATH_PREFIX = "/article/list";

    /** ? */
    private static final String PATH_SUFFIX = ".jhtml";

    /** ?? */
    private String name;

    /** ? */
    private String seoTitle;

    /** ?? */
    private String seoKeywords;

    /** ??? */
    private String seoDescription;

    /**  */
    private String treePath;

    /**  */
    private Integer grade;

    /**  */
    private ArticleCategory parent;

    /**  */
    private Set<ArticleCategory> children = new HashSet<ArticleCategory>();

    /**  */
    private Set<Article> articles = new HashSet<Article>();

    /**
     * ???
     * 
     * @return ??
     */
    @NotEmpty
    @Length(max = 200)
    @Column(nullable = false)
    public String getName() {
        return name;
    }

    /**
     * ??
     * 
     * @param name
     *            ??
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @Length(max = 200)
    public String getSeoTitle() {
        return seoTitle;
    }

    /**
     * ?
     * 
     * @param seoTitle
     *            ?
     */
    public void setSeoTitle(String seoTitle) {
        this.seoTitle = seoTitle;
    }

    /**
     * ???
     * 
     * @return ??
     */
    @Length(max = 200)
    public String getSeoKeywords() {
        return seoKeywords;
    }

    /**
     * ??
     * 
     * @param seoKeywords
     *            ??
     */
    public void setSeoKeywords(String seoKeywords) {
        this.seoKeywords = seoKeywords;
    }

    /**
     * ????
     * 
     * @return ???
     */
    @Length(max = 200)
    public String getSeoDescription() {
        return seoDescription;
    }

    /**
     * ???
     * 
     * @param seoDescription
     *            ???
     */
    public void setSeoDescription(String seoDescription) {
        this.seoDescription = seoDescription;
    }

    /**
     * ?
     * 
     * @return 
     */
    @Column(nullable = false)
    public String getTreePath() {
        return treePath;
    }

    /**
     * 
     * 
     * @param treePath
     *            
     */
    public void setTreePath(String treePath) {
        this.treePath = treePath;
    }

    /**
     * ?
     * 
     * @return 
     */
    @Column(nullable = false)
    public Integer getGrade() {
        return grade;
    }

    /**
     * 
     * 
     * @param grade
     *            
     */
    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    /**
     * ?
     * 
     * @return 
     */
    @ManyToOne(fetch = FetchType.LAZY)
    public ArticleCategory getParent() {
        return parent;
    }

    /**
     * 
     * 
     * @param parent
     *            
     */
    public void setParent(ArticleCategory parent) {
        this.parent = parent;
    }

    /**
     * ?
     * 
     * @return 
     */
    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    @OrderBy("order asc")
    public Set<ArticleCategory> getChildren() {
        return children;
    }

    /**
     * 
     * 
     * @param children
     *            
     */
    public void setChildren(Set<ArticleCategory> children) {
        this.children = children;
    }

    /**
     * ?
     * 
     * @return 
     */
    @OneToMany(mappedBy = "articleCategory", fetch = FetchType.LAZY)
    public Set<Article> getArticles() {
        return articles;
    }

    /**
     * 
     * 
     * @param articles
     *            
     */
    public void setArticles(Set<Article> articles) {
        this.articles = articles;
    }

    /**
     * ?
     * 
     * @return 
     */
    @Transient
    public List<Long> getTreePaths() {
        List<Long> treePaths = new ArrayList<Long>();
        String[] ids = StringUtils.split(getTreePath(), TREE_PATH_SEPARATOR);
        if (ids != null) {
            for (String id : ids) {
                treePaths.add(Long.valueOf(id));
            }
        }
        return treePaths;
    }

    /**
     * ?
     * 
     * @return 
     */
    @Transient
    public String getPath() {
        if (getId() != null) {
            return PATH_PREFIX + "/" + getId() + PATH_SUFFIX;
        }
        return null;
    }

}