Java tutorial
/* Copyright c 2005-2012. * Licensed under GNU LESSER General Public License, Version 3. * http://www.gnu.org/licenses */ package org.beangle.ems.dictionary.model; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Date; import javax.persistence.Cacheable; import javax.persistence.Column; import javax.persistence.MappedSuperclass; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.apache.commons.lang.builder.ToStringBuilder; import org.beangle.model.pojo.LongIdTimeObject; import org.beangle.model.pojo.TemporalActiveEntity; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; /** * ? * </p> * ???????? ????? * ???.??????. ??. * * @author chaostone * @version $Id: BaseCode.java May 4, 2011 7:28:27 PM chaostone $ */ @SuppressWarnings("rawtypes") @MappedSuperclass @Cacheable @Cache(region = "ems.dictionary", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public abstract class BaseCode<T extends BaseCode> extends LongIdTimeObject implements Comparable<T>, TemporalActiveEntity { private static final long serialVersionUID = 5728157880502841506L; /** * ?? */ @Column(unique = true) @NotNull @Size(max = 32) protected String code; /** * ??? */ @NotNull @Size(max = 100) protected String name; /** * ??? */ @Size(max = 100) protected String engName; /** * */ @NotNull protected Date effectiveAt; /** * */ protected Date invalidAt; public BaseCode() { } public BaseCode(Long id) { this.id = id; } public void genIdFromCode() { setId(Long.valueOf(getCode())); } /** * ??? * * @return */ public boolean hasExtPros() { Field[] fields = getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (!(Modifier.isFinal(fields[i].getModifiers()) || Modifier.isStatic(fields[i].getModifiers()))) { return true; } } return false; } /** * ? * * @return ? */ public String getCode() { return code; } /** * ? * * @param code * ? */ public void setCode(String code) { this.code = code; } /** * ?? * * @return ?? */ public String getName() { return name; } /** * ?? * * @param name * ?? */ public void setName(String name) { this.name = name; } /** * ?? * * @return ?? */ public String getEngName() { return engName; } /** * ?? * * @param engName * ?? */ public void setEngName(String engName) { this.engName = engName; } /** * * * @return */ public Date getEffectiveAt() { return effectiveAt; } /** * * * @param effectiveAt * */ public void setEffectiveAt(Date effectiveAt) { this.effectiveAt = effectiveAt; } /** * * * @return */ public Date getInvalidAt() { return invalidAt; } /** * * * @param invalidAt * */ public void setInvalidAt(Date invalidAt) { this.invalidAt = invalidAt; } public int compareTo(T arg0) { T other = (T) arg0; return this.getCode().compareTo(other.getCode()); } public String toString() { return new ToStringBuilder(this).append("name", this.name).append("id", this.id).append("code", this.code) .append("engName", this.engName).toString(); } }