${database.allClassCopyright}package ${glPackageBaseCommon};

/**
 * The auto set-upper of common column.
 * @author ${database.classAuthor}
 */
public class ${glCommonColumnAutoSetupper} {

    // =====================================================================================
    //                                                                                Set up
    //                                                                                ======
    /**
     * Handle common columns of insert if it needs.
     * @param targetEntity Target entity that the type is entity interface. (NotNull)
     */
    public void handleCommonColumnOfInsertIfNeeds(${glEntity} targetEntity) {
#if ($database.isExistCommonColumnSetupElement())
        if (!(targetEntity instanceof ${glEntityDefinedCommonColumn})) {
            return;
        }
        final ${glEntityDefinedCommonColumn} entity = (${glEntityDefinedCommonColumn})targetEntity;
        if (!entity.canCommonColumnAutoSetup()) {
            return;
        }
#foreach ($columnName in ${database.commonColumnNameList})
#set ($filteredColumnName = ${database.filterCommonColumn(${columnName})})
#set ($entityCommonColumnMap = ${database.commonColumnMap})
#set ($columnType = ${entityCommonColumnMap.get(${columnName})})
#set ($javaNative = ${database.convertJavaNativeByJdbcType(${columnType})})
#set ($javaName = ${database.convertJavaNameByJdbcNameAsColumn(${filteredColumnName})})
#set ($uncapitalisedJavaName = ${database.convertUncapitalisedJavaNameByJdbcNameAsColumn(${filteredColumnName})})
#if (${database.containsValidColumnNameKeyCommonColumnSetupBeforeInsertInterceptorLogicMap(${columnName})})
#set ($logic = ${database.getCommonColumnSetupBeforeInsertInterceptorLogicByColumnName(${columnName})})
#if ($database.isCommonColumnSetupInvokingLogic($logic))
#set ($filteredLogic = $database.removeCommonColumnSetupInvokingMark($logic))

        ${filteredLogic}
#else

        final ${javaNative} ${uncapitalisedJavaName} = ${logic};
        entity.set${javaName}(${uncapitalisedJavaName});
#end
#end
#end
#end
    }

    /**
     * Handle common columns of update if it needs.
     * @param targetEntity Target entity that the type is entity interface. (NotNull)
     */
    public void handleCommonColumnOfUpdateIfNeeds(${glEntity} targetEntity) {
#if ($database.isExistCommonColumnSetupElement())
        if (!(targetEntity instanceof ${glEntityDefinedCommonColumn})) {
            return;
        }
        final ${glEntityDefinedCommonColumn} entity = (${glEntityDefinedCommonColumn})targetEntity;
        if (!entity.canCommonColumnAutoSetup()) {
            return;
        }
#foreach ($columnName in ${database.commonColumnNameList})
#set ($filteredColumnName = ${database.filterCommonColumn(${columnName})})
#set ($entityCommonColumnMap = ${database.CommonColumnMap})
#set ($columnType = ${entityCommonColumnMap.get(${columnName})})
#set ($javaNative = ${database.convertJavaNativeByJdbcType(${columnType})})
#set ($javaName = ${database.convertJavaNameByJdbcNameAsColumn(${filteredColumnName})})
#set ($uncapitalisedJavaName = ${database.convertUncapitalisedJavaNameByJdbcNameAsColumn(${filteredColumnName})})
#if (${database.containsValidColumnNameKeyCommonColumnSetupBeforeUpdateInterceptorLogicMap(${columnName})})
#set ($logic = ${database.getCommonColumnSetupBeforeUpdateInterceptorLogicByColumnName(${columnName})})
#if ($database.isCommonColumnSetupInvokingLogic($logic))
#set ($filteredLogic = $database.removeCommonColumnSetupInvokingMark($logic))

        ${filteredLogic}
#else

        final ${javaNative} ${uncapitalisedJavaName} = ${logic};
        entity.set${javaName}(${uncapitalisedJavaName});
#end
#end
#end
#end
    }
}
