com.aistor.modules.cms.entity.Article.java Source code

Java tutorial

Introduction

Here is the source code for com.aistor.modules.cms.entity.Article.java

Source

/**
 * Copyright &copy; 2012-2013 <a href="https://github.com/Dopas/dopas">Dopas</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.aistor.modules.cms.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Resolution;
import org.hibernate.search.annotations.Store;
import org.hibernate.validator.constraints.Length;
import org.wltea.analyzer.lucene.IKAnalyzer;

import com.google.common.collect.Lists;
import com.aistor.common.persistence.BaseEntity;
import com.aistor.modules.sys.entity.User;

/**
 * Entity
 * @author Zaric
 * @version 2013-01-15
 */
@Entity
@Table(name = "cms_article")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Indexed
@Analyzer(impl = IKAnalyzer.class)
public class Article extends BaseEntity {

    private static final long serialVersionUID = 1L;
    private Long id; // ?
    private Category category;// ?
    private User user; // ?
    private String title; // 
    private String color; // redgreenblue?yelloworange
    private String thumb; // 
    private String keywords;// 
    private String desciption;// ????
    private String status; // ??0?12
    private Integer weight; // ????
    private Integer hits; // 
    private String posid; // ???12???
    private Date inputDate; // 
    private Date updateDate;// 

    private ArticleData articleData; //

    public Article() {
        this.status = STATUS_RELEASE;
        this.weight = 0;
        this.hits = 0;
        this.posid = "";
        this.inputDate = new Date();
        this.updateDate = new Date();
    }

    public Article(Long id) {
        this();
        this.id = id;
    }

    public Article(Category category) {
        this();
        this.category = category;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    //   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_cms_article")
    //   @SequenceGenerator(name = "seq_cms_article", sequenceName = "seq_cms_article")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne
    @JoinColumn(name = "category_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @NotNull
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @ManyToOne
    @JoinColumn(name = "user_id")
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Length(min = 1, max = 255)
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Length(min = 0, max = 50)
    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Length(min = 0, max = 255)
    public String getThumb() {
        return thumb;
    }

    public void setThumb(String thumb) {
        this.thumb = thumb;
    }

    @Length(min = 0, max = 255)
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
    public String getKeywords() {
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    @Length(min = 0, max = 255)
    @Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
    public String getDesciption() {
        return desciption;
    }

    public void setDesciption(String desciption) {
        this.desciption = desciption;
    }

    @Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES)
    public String getStatus() {
        return status;
    }

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

    @NotNull
    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public Integer getHits() {
        return hits;
    }

    public void setHits(Integer hits) {
        this.hits = hits;
    }

    @Length(min = 0, max = 10)
    public String getPosid() {
        return posid;
    }

    public void setPosid(String posid) {
        this.posid = posid;
    }

    @NotNull
    public Date getInputDate() {
        return inputDate;
    }

    public void setInputDate(Date inputDate) {
        this.inputDate = inputDate;
    }

    @Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES)
    @DateBridge(resolution = Resolution.DAY)
    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @OneToOne(mappedBy = "article", cascade = CascadeType.ALL, optional = false)
    @IndexedEmbedded
    @Valid
    public ArticleData getArticleData() {
        return articleData;
    }

    public void setArticleData(ArticleData articleData) {
        this.articleData = articleData;
    }

    @Transient
    public List<String> getPosidList() {
        List<String> list = Lists.newArrayList();
        if (posid != null) {
            for (String s : StringUtils.split(posid, ",")) {
                list.add(s);
            }
        }
        return list;
    }

    @Transient
    public void setPosidList(List<Long> list) {
        posid = "," + StringUtils.join(list, ",") + ",";
    }

}