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

org.sagacity.quickvo.abstract-entity.ftl Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
/**
 *@Generated by sagacity-quickvo 5.0
 */
package ${quickVO.entityPackage}.${quickVO.abstractPath};

import java.io.Serializable;
<#if (quickVO.selectFields==true||quickVO.exportTables?exists)>
<#if (quickVO.hasListType==false)>
import java.util.List;

import java.util.ArrayList;

import org.sagacity.sqltoy.config.annotation.Entity;
<#if (quickVO.selectFields==true)>
import org.sagacity.sqltoy.callback.SelectFields;

<#if (quickVO.type=="TABLE")>
import org.sagacity.sqltoy.config.annotation.Id;

import org.sagacity.sqltoy.config.annotation.Column;
<#if (quickVO.indexModels?exists && quickVO.indexModels?size>0)>
import org.sagacity.sqltoy.config.annotation.Indexes;
import org.sagacity.sqltoy.config.annotation.Index;

<#if (quickVO.hasVoEntity==false)>
<#if (quickVO.apiDoc=="swagger-v2")>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

<#if (quickVO.apiDoc=="swagger-v3")>
import io.swagger.v3.oas.annotations.media.Schema;

<#if (quickVO.apiDocImports?exists && quickVO.apiDocImports?size>0)>
<#list quickVO.apiDocImports as import>
import ${import};



<#if (quickVO.hasBusinessId==true)>
import org.sagacity.sqltoy.config.annotation.BusinessId;

<#if (quickVO.imports?exists && quickVO.imports?size>0)>
<#list quickVO.imports as import>
import ${import};


<#if (quickVO.exportTables?exists)>
import org.sagacity.sqltoy.config.annotation.OneToMany;
<#list quickVO.exportTables as exportTable>
import ${quickVO.entityPackage}.${exportTable.pkRefTableJavaName?cap_first};


<#if (quickVO.entityExtends?exists)>
import ${quickVO.entityExtends};


/**
<#if (quickVO.projectName?exists)> * @project ${quickVO.projectName}
<#if (quickVO.author?exists)> * @author ${quickVO.author}
<#if (quickVO.version?exists)> * @version ${quickVO.version}
 */
<#if (quickVO.hasVoEntity==false)>
<#if (quickVO.apiDoc=="swagger-v2")>
@ApiModel(value="${quickVO.entityName}"<#if (quickVO.tableRemark?exists && quickVO.tableRemark!='')>,description="${quickVO.tableRemark}")

<#if (quickVO.apiDoc=="swagger-v3")>
@Schema(name="${quickVO.entityName}"<#if (quickVO.tableRemark?exists && quickVO.tableRemark!='')>,description="${quickVO.tableRemark}")

<#if (quickVO.apiDocContent?exists)>
${quickVO.apiDocContent}


@Entity(tableName="${quickVO.tableName}",comment="${quickVO.tableRemark!""}"<#if (quickVO.pkConstraint?exists)>,pk_constraint="${quickVO.pkConstraint}"<#if (quickVO.schema?exists && quickVO.schema!='')>,schema="${quickVO.schema}")
<#if (quickVO.indexModels?exists && quickVO.indexModels?size>0)>
<#assign paramCnt=0/>
@Indexes(indexes={<#list quickVO.indexModels as indexModel><#if (paramCnt>0)>,@Index(name="${indexModel.indexName}",columns={${indexModel.columnsAry}},sortTypes={${indexModel.sortTypesAry}}<#if (indexModel.isUnique)>,isUnique=true)
<#assign paramCnt=paramCnt+1/>
})

<#if (quickVO.entityExtends?exists)>
public abstract class Abstract${quickVO.entityName} extends ${quickVO.entityExtends?substring(quickVO.entityExtends?last_index_of(".")+1)} implements Serializable {
<#else>
public abstract class Abstract${quickVO.entityName} implements Serializable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = ${quickVO.abstractEntitySerialUID}L;
	
<#list quickVO.columns as column>
<#if (column.skipEntity==false)>

	<#if (quickVO.hasVoEntity==false)>
	<#if (quickVO.apiDoc=="swagger-v2")>
	@ApiModelProperty(name="${column.colJavaName?uncap_first}",value="${column.colRemark!""}"<#if (column.nullable=='0')>,allowEmptyValue=false<#else>,allowEmptyValue=true)
	
	<#if (quickVO.apiDoc=="swagger-v3")>
	@Schema(name="${column.colJavaName?uncap_first}",description="${column.colRemark!""}"<#if (column.nullable=='0')>,nullable=false<#else>,nullable=true)
	
	<#if (column.apiDocContent?exists)>
	${column.apiDocContent}
	
	
	<#if (column.pkFlag?exists && column.pkFlag=='1')>
	@Id<#if (column.businessIdConfig?exists)><#else><#if (quickVO.singlePk=='1')>(strategy="${column.strategy}"<#if (column.sequence?exists && column.sequence!='')>,sequence="${column.sequence}"<#if (column.generator?exists && column.generator!='')>,generator="${column.generator}")
	
	<#if (column.businessIdConfig?exists)>
	<#assign businessId=column.businessIdConfig/>
	@BusinessId(generator="${businessId.generator}"<#if (businessId.signature?exists)>,signature="${businessId.signature}"<#if (businessId.relatedColumns?exists)>,relatedColumns={<#list businessId.relatedColumns as relatedCol><#if (relatedCol_index>0)>,"${relatedCol}"}<#if (businessId.length?exists)>,length=${businessId.length}<#if (businessId.sequenceSize?exists)>,sequenceSize=${businessId.sequenceSize})
	
	<#if (column.partitionKey==true)>
	@PartitionKey
	
	<#if (column.fkRefTableName?exists)>
	@Foreign(table="${column.fkRefTableName}",field="${column.fkRefTableColName}",deleteRestict=${column.deleteRestict},updateRestict=${column.updateRestict}<#if (column.fkName?exists)>,constraintName="${column.fkName}")
	
	@Column(name="${column.colName}",comment="${column.colRemark!""}"<#if (column.precision?exists)>,length=${column.precision?c}L<#if (column.scale?exists && column.scale>0)>,scale=${column.scale?c}<#if (column.defaultValue?exists)>,defaultValue="${column.defaultValue}",type=<#if (column.dataType?matches("\\d+"))==false>java.sql.Types.<#if (column.dataType?upper_case=='INT')>INTEGER<#else>${column.dataType?upper_case},nativeType="${column.colType!""}",nullable=<#if (column.nullable=='0')>false<#else>true<#if column.autoIncrement=='true'>,autoIncrement=true)
	protected ${column.resultType} ${column.colJavaName?uncap_first};


<#if (quickVO.columnSize==0)>
   // 未能获得表字段信息,请检查quickvo.xml 中dataSource的schema 和 catalog配置,可尝试先去除schema\catalog
   // 内部原理: conn.getMetaData().getColumns(catalog, schema, tableName, null);

<#if (quickVO.exportTables?exists)>
<#list quickVO.exportTables as exportTable>
	/**
	 * 主键关联子表信息
	 */
	@OneToMany(fields={${exportTable.pkColJavaName}},mappedFields={${exportTable.pkRefColJavaName}}<#if (exportTable.load?exists)>,load="${exportTable.load}"<#if (exportTable.updateSql?exists)>,update="${exportTable.updateSql}"<#if (exportTable.deleteRule==1)>,delete=true<#if (exportTable.orderBy?exists)>,orderBy="${exportTable.orderBy}")
	protected List<${exportTable.pkRefTableJavaName?cap_first}> ${exportTable.pkRefTableJavaName?uncap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es=new ArrayList<${exportTable.pkRefTableJavaName?cap_first}>();



<#if (quickVO.type=='TABLE')>
	/** default constructor */
	public Abstract${quickVO.entityName}() {
	}
	
<#if (quickVO.singlePk=='1'||quickVO.singlePk=='0')>
<#assign paramCnt="0"/> 
	/** pk constructor */
	public Abstract${quickVO.entityName}(<#list quickVO.columns as column><#if (column.pkFlag=='1')><#if (paramCnt=='1')>,<#assign paramCnt='1'/>${column.resultType} ${column.colJavaName?uncap_first})
	{
		<#list quickVO.columns as column>
		<#if (column.pkFlag=='1')>
		this.${column.colJavaName?uncap_first}=${column.colJavaName?uncap_first};
		
		
	}


<#list quickVO.columns as column>
<#if (column.skipEntity==false)>
	
	/**
	 *@param ${column.colJavaName?uncap_first} the ${column.colJavaName?uncap_first} to set
	 */
	<#if (quickVO.returnSelf==true)>
	public Abstract${quickVO.entityName} set${column.colJavaName?cap_first}(${column.resultType} ${column.colJavaName?uncap_first}) {
		this.${column.colJavaName?uncap_first}=${column.colJavaName?uncap_first};
		return this;
	}
	<#else>
	public void set${column.colJavaName?cap_first}(${column.resultType} ${column.colJavaName?uncap_first}) {
		this.${column.colJavaName?uncap_first}=${column.colJavaName?uncap_first};
	}
	
		
	/**
	 *@return the ${column.colJavaName}
	 */
	public ${column.resultType} get${column.colJavaName?cap_first}() {
	    return this.${column.colJavaName?uncap_first};
	}



<#if (quickVO.exportTables?exists)>
<#list quickVO.exportTables as exportTable>
	/**
	 * @return the ${exportTable.pkRefTableJavaName?uncap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es
	 */
	public List<${exportTable.pkRefTableJavaName?cap_first}> get${exportTable.pkRefTableJavaName?cap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es() {
		return this.${exportTable.pkRefTableJavaName?uncap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es;
	}
	
	public void set${exportTable.pkRefTableJavaName?cap_first}s(List<${exportTable.pkRefTableJavaName?cap_first}> ${exportTable.pkRefTableJavaName?uncap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es)	{
		this.${exportTable.pkRefTableJavaName?uncap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es=${exportTable.pkRefTableJavaName?uncap_first}<#if exportTable.pkRefTableJavaName?ends_with("s")>es;
	}



	/**
     * @todo vo columns to String
     */
    @Override
	public String toString() {
		StringBuilder columnsBuffer=new StringBuilder();
		<#list quickVO.columns as column>
		columnsBuffer.append("${column.colJavaName?uncap_first}=").append(get${column.colJavaName?cap_first}()).append("\n");
		
		return columnsBuffer.toString();
	}
	
<#if (quickVO.selectFields==true)>
	/**
	 * @TODO create entityQuery fields
	 */
	public static SelectFieldsImpl select() {
		return new SelectFieldsImpl();
	}
	
	public static class SelectFieldsImpl extends SelectFields {
		private List fields = new ArrayList();

		@Override
		public String[] getSelectFields() {
			String[] result = new String[fields.size()];
			fields.toArray(result);
			return result;
		}
		
<#list quickVO.columns as column>
	    public SelectFieldsImpl ${column.colJavaName?uncap_first}<#if (column.colJavaName?uncap_first=='notify')>_<#if (column.colJavaName?uncap_first=='finalize')>_<#if (column.colJavaName?uncap_first=='wait')>_<#if (column.colJavaName?uncap_first=='notifyAll')>_() {
	    	if (!fields.contains("${column.colJavaName?uncap_first}")) {
				fields.add("${column.colJavaName?uncap_first}");
			}
	    	return this;
	    }
    

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy