com.dp2345.entity.ShopCategory.java Source code

Java tutorial

Introduction

Here is the source code for com.dp2345.entity.ShopCategory.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_shop_category")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_shop_category_sequence")
public class ShopCategory extends OrderEntity {

    private static final long serialVersionUID = -5132652107151648662L;

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

    /** ? */
    private static final String PATH_PREFIX = "/store/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 ShopCategory parent;

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

    /**  */
    private Set<Shop> shops = new HashSet<Shop>();

    /**
     * ???
     * 
     * @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 ShopCategory getParent() {
        return parent;
    }

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

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

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

    /**
     * ?
     * 
     * @return 
     */
    @OneToMany(mappedBy = "shopCategory", fetch = FetchType.LAZY)
    public Set<Shop> getShops() {
        return shops;
    }

    /**
     * 
     * 
     * @param shops
     *            
     */
    public void setShops(Set<Shop> shops) {
        this.shops = shops;
    }

    /**
     * ?
     * 
     * @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;
    }

}