net.shopxx.entity.ProductCategory.java Source code

Java tutorial

Introduction

Here is the source code for net.shopxx.entity.ProductCategory.java

Source

/*
 * Copyright 2005-2013 shopxx.net. All rights reserved.
 * Support: http://www.xmsoft.cn
 * License: http://www.xmsoft.cn/license
 */
package net.shopxx.entity;

import java.util.ArrayList;
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.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.PreRemove;
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 SHOP++ Team
 * @version 3.0
 */
@Entity
@Table(name = "xx_product_category")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_product_category_sequence")
public class ProductCategory extends OrderEntity {

    private static final long serialVersionUID = 5095521437302782717L;

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

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

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

    /** ? */
    private Set<Product> products = new HashSet<Product>();

    /** ? */
    private Set<Brand> brands = new HashSet<Brand>();

    /** ? */
    private Set<ParameterGroup> parameterGroups = new HashSet<ParameterGroup>();

    /**  */
    private Set<Attribute> attributes = new HashSet<Attribute>();

    /**  */
    private Set<Promotion> promotions = new HashSet<Promotion>();

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

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

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

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

    /**
     * ??
     * 
     * @return ?
     */
    @OneToMany(mappedBy = "productCategory", fetch = FetchType.LAZY)
    public Set<Product> getProducts() {
        return products;
    }

    /**
     * ?
     * 
     * @param products
     *            ?
     */
    public void setProducts(Set<Product> products) {
        this.products = products;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "xx_product_category_brand")
    @OrderBy("order asc")
    public Set<Brand> getBrands() {
        return brands;
    }

    /**
     * ?
     * 
     * @param brands
     *            ?
     */
    public void setBrands(Set<Brand> brands) {
        this.brands = brands;
    }

    /**
     * ??
     * 
     * @return ?
     */
    @OneToMany(mappedBy = "productCategory", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
    @OrderBy("order asc")
    public Set<ParameterGroup> getParameterGroups() {
        return parameterGroups;
    }

    /**
     * ?
     * 
     * @param parameterGroups
     *            ?
     */
    public void setParameterGroups(Set<ParameterGroup> parameterGroups) {
        this.parameterGroups = parameterGroups;
    }

    /**
     * ?
     * 
     * @return 
     */
    @OneToMany(mappedBy = "productCategory", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
    @OrderBy("order asc")
    public Set<Attribute> getAttributes() {
        return attributes;
    }

    /**
     * 
     * 
     * @param attributes
     *            
     */
    public void setAttributes(Set<Attribute> attributes) {
        this.attributes = attributes;
    }

    /**
     * ?
     * 
     * @return 
     */
    @ManyToMany(mappedBy = "productCategories", fetch = FetchType.LAZY)
    public Set<Promotion> getPromotions() {
        return promotions;
    }

    /**
     * 
     * 
     * @param promotions
     *            
     */
    public void setPromotions(Set<Promotion> promotions) {
        this.promotions = promotions;
    }

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

    /**
     * ??
     */
    @PreRemove
    public void preRemove() {
        Set<Promotion> promotions = getPromotions();
        if (promotions != null) {
            for (Promotion promotion : promotions) {
                promotion.getProductCategories().remove(this);
            }
        }
    }

    //??
    private Set<ProductMerchantCategory> productMerchantCategorys = new HashSet<ProductMerchantCategory>();

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productCategory", fetch = FetchType.LAZY)
    public Set<ProductMerchantCategory> getProductMerchantCategorys() {
        return productMerchantCategorys;
    }

    public void setProductMerchantCategorys(Set<ProductMerchantCategory> productMerchantCategorys) {
        this.productMerchantCategorys = productMerchantCategorys;
    }

}