All Downloads are FREE. Search and download functionalities are using the official Maven repository.

panda.tool.codegen.entity.EntityBean.ftl Maven / Gradle / Ivy

<#include "common.ftl"/>
package ${package};

<#list imports as i>
import ${i};


<#if entity.comment?has_content>
@${gen.annoComment(entity)}("${entity.comment}")

<#if entity.table?has_content>
@Table("${entity.table}")

<#if entity.foreignKeyMap?has_content>
@ForeignKeys({
<#list entity.foreignKeyMap?keys as k>
	@FK(${entity.getForeignKeyDefine(entity.foreignKeyMap[k])})<#if k_has_next>,

})

<#if entity.uniqueKeyMap?has_content>
@Indexes({
<#list entity.uniqueKeyMap?keys as k>
	@Index(name="${k}", fields={ <#list entity.uniqueKeyMap[k] as p>"${p.name}"<#if p_has_next>,  }, unique=true)<#if k_has_next>,

})

<#if entity.joinMap?has_content>
@Joins({
<#list entity.joinMap?keys as k>
	@Join(${entity.getJoinDefine(entity.joinMap[k])})<#if k_has_next>,

})

public class ${name} <#if entity.baseBeanClass?has_content>extends ${class_name(entity.baseBeanClass)} implements Serializable<#if entity.baseInterfaces?has_content><#list entity.baseInterfaces as i>, ${class_name(i)} {

	private static final long serialVersionUID = ${svuid?c}L;

	/**
	 * Constructor
	 */
	public ${name}() {
		super();
	}

	/*----------------------------------------------------------------------*
	 * Constants
	 *----------------------------------------------------------------------*/
<#list entity.propertyList as p>
	public static final String ${p.uname} = "${p.name}";


	public static final String[] _COLUMNS_ = new String[] {
<#list entity.columnList as p>
			${p.uname}<#if p_has_next>,

		};

<#if entity.joinList?has_content>
	public static final String[] _JOINS_ = new String[] {
<#list entity.joinList as p>
			${p.uname}<#if p_has_next>,

		};


<#if entity.joinMap?has_content>
<#list entity.joinMap?keys as k>
	public static final String _JOIN_${k?upper_case}_ = "${k}";



	/*----------------------------------------------------------------------*
	 * Properties
	 *----------------------------------------------------------------------*/
<#list entity.propertyList as p>
<#if entity.isIdentity(p.name)>
	@Id<#if entity.identityDefine?has_content>(${entity.identityDefine})
<#elseif p.dbColumn>
	<#if p.primaryKey>
	@PK
	
	@Column<#if p.columnDefine?has_content>(${p.columnDefine})
<#elseif p.joinColumn>
	@JoinColumn(name="${p.joinName}", field="${p.joinField}")

<#if p.comment?has_content>
	@${gen.annoComment(entity)}("${p.comment}")

	${p.modifier} ${p.simpleJavaType} ${p.name}<#if p.initValue?has_content> = ${p.initValue};



	/*----------------------------------------------------------------------*
	 * Getter & Setter
	 *----------------------------------------------------------------------*/
<#list entity.propertyList as p>
	/**
	 * @return the ${p.name}
	 */
<#-- validation -->
	<#assign stype = p.simpleJavaType/>
	<#assign type = stype/>
	<#if type?ends_with('[]')>
		<#assign type = type?substring(0, type?length - 2)/>
	<#elseif type?ends_with('>') && type?index_of('<') gt 0> 
		<#assign ilt = type?index_of('<')/>
		<#assign type = type?substring(ilt + 1, type?length - 1)/>
	
	<#if p.validatorList?has_content || (p.dbColumn && type != "String" && stype != "byte[]")>
	@Validates({
	<#list p.validatorList as v>
		@Validate(value=${gen.validatorType(v.type)}, <#if v.refer?has_content>refer="${v.refer?j_string}", <#if v.hasParams>params="${v.params}", <#if v.message?has_content>message="${v.message?j_string}"<#else>msgId=${gen.validatorMsgId(v.msgId)})<#if v_has_next || type != "String">, 
	
	<#if type != "String">
		@Validate(value=${gen.validatorType('cast')}, msgId=${gen.validatorMsgId('cast-' + type)})
	
	})
	
<#-- validation -->
	public ${p.simpleJavaType} <#if p.simpleJavaType == 'boolean'>is<#else>get${p.name?cap_first}() {
	<#assign getterTrim = "" />
	<#if p.getterTrim??>
		<#if p.getterTrim?has_content>
			<#assign getterTrim = p.getterTrim/>
		
	
	<#if p.getterCode?has_content>
		${p.getterCode}
	<#elseif getterTrim?has_content>
		return ${getterTrim}(${p.name});
	<#else>
		return ${p.name};
	
	}

	/**
	 * @param ${p.name} the ${p.name} to set
	 */
	public void set${p.name?cap_first}(${p.simpleJavaType} ${p.name}) {
	<#assign setterTrim = "" />
	<#if p.setterTrim??>
		<#if p.setterTrim?has_content>
			<#assign setterTrim = p.setterTrim/>
		
	<#elseif entity.trimString?has_content && p.simpleJavaType == "String">
		<#assign setterTrim = entity.trimString />
	<#elseif entity.trimList?has_content && (p.simpleJavaType?matches("List<.*>") || p.simpleJavaType?matches("Set<.*>"))>
		<#assign setterTrim = entity.trimList />
	
	<#if p.setterCode?has_content>
		${p.setterCode}
	<#elseif setterTrim?has_content>
		this.${p.name} = ${setterTrim}(${p.name});
	<#else>
		this.${p.name} = ${p.name};
	
	}



	/**
	 * copy properties from the specified object.
	 * @param src the source object to copy
	 */
	public void copy(${name} src) {
<#list entity.propertyList as p>
		this.${p.name} = src.${p.name};

<#if entity.baseBeanClass?has_content>
		super.copy(src);

	}

	/*----------------------------------------------------------------------*
	 * Overrides
	 *----------------------------------------------------------------------*/
	/**
	 * Creates and returns a copy of this object.
	 * @return the copy object
	 */
	@Override
	public ${name} clone() {
		${name} copy = new ${name}();
		
		copy.copy(this);

		return copy;
	}

	/**
	 * @return  a hash code value for this object.
	 */
	@Override
	public int hashCode() {
		return Objects.hashCodes(<#list entity.primaryKeyList as p>${p.name}<#if p_has_next>,);
	}

	/**
	 * @return  true if this object is the same as the obj argument; 
	 * 			false otherwise.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}

		${name} rhs = (${name})obj;
<#if 'false' == props['entity.equals.pkey']!'true'>
	<#assign pl = entity.propertyList/>
		return Objects.equalsBuilder()
<#list pl as p>
				.append(${p.name}, rhs.${p.name})

<#if entity.baseBeanClass?has_content>
				.appendSuper(super.equals(rhs))

<#else>
	<#assign pl = entity.primaryKeyList/>
		return Objects.equalsBuilder()
<#list pl as p>
				.append(${p.name}, rhs.${p.name})

		
				.isEquals();
	}

	/**
	 * @return  a string representation of the object.
	 */
	@Override
	public String toString() {
		return Objects.toStringBuilder()
<#list entity.propertyList as p>
				.append(${p.uname}, ${p.name})

<#if entity.baseBeanClass?has_content>
				.appendSuper(super.toString())

				.toString();
	}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy