## -------------------------------------------------- ## BASE 엔티티 (@MappedSuperclass) — DB에서 매번 재생성 (덮어씀) ## + concrete( @Entity )는 "없을 때만" 1회 생성 (있으면 보존) ## 경로는 telosys-tools.cfg 의 ENTITY_BASE_PKG / ENTITY_CONCRETE_PKG 로 결정 ## ## CSV 들 (converters.csv, type-mapping.csv) 의 FQN 은 자동으로 짧은 이름 ## 으로 치환되고, 필요한 import 가 자동 추가됨 (auto_imports.vm 참고). ## ## Lombok : ## @Getter @Setter @SuperBuilder @NoArgsConstructor @AllArgsConstructor ## (@Builder 가 아닌 @SuperBuilder — Base/Concrete 상속에서 builder() 가 ## Concrete 타입으로 동작하도록) ## ## Swagger : @Schema(description = "DB 컬럼 코멘트") 자동 부착 ## -------------------------------------------------- #if ( $entity.isJoinEntity() ) #cancel("No JPA class for join entity") #end #checkId($entity) #parse("include/init_var_entity.vm") #parse("include/java_header.vm") #parse("include/converters_mapping.vm") #parse("include/type_mapping.vm") #parse("include/auto_imports.vm") ##--------------------------------------------------------------------------------------- #set( $entityClass = "${entity.name}JpaEntity" ) #set( $entityBaseClass = "${entity.name}JpaEntityBase" ) #set( $basePath = $ENTITY_BASE_PKG.replace(".", "/") ) #set( $concretePath = $ENTITY_CONCRETE_PKG.replace(".", "/") ) #set( $concreteFolder = "${SRC}/${concretePath}" ) #set( $concreteFile = "${concreteFolder}/${entityClass}.java" ) #if( ! $fn.file($concreteFile).exists() ) $generator.generate($entity.name, "${entityClass}.java", $concreteFolder, "main-java/XxxConcrete_java.vm") #end ##--------------------------------------------------------------------------------------- package ${ENTITY_BASE_PKG}; import java.io.Serializable; #foreach( $import in $java.imports($entity) ) import $import; #end #foreach( $imp in $extraImports ) import $imp; #end import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.SuperBuilder; /** * BASE class for "${entityClass}" — generated from DB, DO NOT EDIT (regenerated). * 비즈니스 로직은 ${ENTITY_CONCRETE_PKG}.${entityClass} 에 작성하세요. #if( $entity.databaseComment && $entity.databaseComment != "" ) * * Table comment: ${entity.databaseComment} #end */ #if( $entity.databaseComment && $entity.databaseComment != "" ) @Schema(description = "${entity.databaseComment}") #end @MappedSuperclass @Getter @Setter @SuperBuilder @NoArgsConstructor @AllArgsConstructor public abstract class ${entityBaseClass} implements Serializable { private static final long serialVersionUID = 1L; //--- ENTITY PRIMARY KEY #foreach( $attribute in $entity.keyAttributes ) #if( $attribute.databaseComment && $attribute.databaseComment != "" ) @Schema(description = "${attribute.databaseComment}") #end $jpa.fieldAnnotations(4, $attribute) private $attribute.formattedType(10) $attribute.name #if($attribute.hasInitialValue())= ${attribute.ini} #end; #end //--- ENTITY DATA FIELDS #foreach( $attribute in $entity.nonKeyAttributes ) ## ---- 1) type-mapping.csv 우선 매칭 #set( $mapType = false ) #set( $mapAnno = false ) #foreach( $row in $typeMapRows ) #if( $row.size() >= 2 && $row.get(0).trim().equals($attribute.databaseName) ) #set( $mapType = $row.get(1).trim() ) #if( $row.size() >= 3 ) #set( $mapAnno = $row.get(2).trim() ) #end #end #end ## ---- 2) converters.csv 매칭 (type-mapping 매칭 없을 때만) #set( $convType = false ) #set( $convClass = false ) #if( !$mapType ) #if( $attribute.hasTag("converter") ) #set( $convType = $attribute.tagValue("javaType") ) #set( $convClass = $attribute.tagValue("converter") ) #else #foreach( $row in $convRows ) #if( $row.size() >= 3 && $row.get(0).trim().equals($attribute.databaseName) ) #set( $convType = $row.get(1).trim() ) #set( $convClass = $row.get(2).trim() ) #end #end #end #end ## ---- 3) FQN → 짧은 이름 치환 #set( $dispType = false ) #set( $dispAnno = false ) #set( $dispConv = false ) #if( $mapType )#set( $dispType = $mapType )#end #if( $mapAnno )#set( $dispAnno = $mapAnno )#end #if( $convType )#set( $dispType = $convType )#end #if( $convClass )#set( $dispConv = $convClass )#end #foreach( $imp in $extraImports ) #set( $tail = $imp.substring($imp.lastIndexOf(".")) ) #set( $sn = $tail.substring(1) ) #if( $dispType )#set( $dispType = $dispType.replace($imp, $sn) )#end #if( $dispAnno )#set( $dispAnno = $dispAnno.replace($imp, $sn) )#end #if( $dispConv )#set( $dispConv = $dispConv.replace($imp, $sn) )#end #end ## ---- 4) 필드 출력 #if( $attribute.databaseComment && $attribute.databaseComment != "" ) @Schema(description = "${attribute.databaseComment}") #end #if( $dispAnno && $dispAnno != "" ) ${dispAnno} #end #if( $dispConv ) @Convert(converter = ${dispConv}.class) #end $jpa.fieldAnnotations(4, $attribute) #if( $dispType ) private ${dispType} $attribute.name ; #else private $attribute.formattedType(10) $attribute.name #if($attribute.hasInitialValue())= ${attribute.ini} #end; #end #end }