${database.allClassCopyright}package ${glPackageBaseParameterBean};
#set ($myClassName = "${myBaseParameterBeanClassName}")

#if ($database.isPmbMetaDataForProcedure($pmbClassName))
import org.seasar.dbflute.outsidesql.ProcedurePmb;
#else
import org.seasar.dbflute.cbean.FetchBean;
import org.seasar.dbflute.twowaysql.pmbean.ParameterBean;
#end
import org.seasar.dbflute.jdbc.ParameterUtil;
import org.seasar.dbflute.jdbc.ParameterUtil.ShortCharHandlingMode;
#if ($database.hasPmbMetaDataPropertyOptionAnyLikeSearch($pmbClassName))
import org.seasar.dbflute.cbean.coption.LikeSearchOption;
#end
#if ($database.hasPmbMetaDataPropertyOptionAnyFromTo($pmbClassName))
import org.seasar.dbflute.cbean.coption.FromToOption;
#end
import org.seasar.dbflute.util.DfTypeUtil;

/**
 * The parameter-bean of ${pmbClassName}.
 * @author ${database.classAuthor}
 */
#if ($database.isPmbMetaDataForProcedure($pmbClassName))
public class ${myClassName} implements ProcedurePmb {
#else
public class ${myClassName}${database.getPmbMetaDataSuperClassDefinition($pmbClassName)} implements ParameterBean, FetchBean {
#end
#if ($database.isPmbMetaDataForProcedure($pmbClassName))

    // ===================================================================================
    //                                                                          Definition
    //                                                                          ==========
    // -----------------------------------------------------
    //                                   Procedure Parameter
    //                                   -------------------
#set ($procedureParameterIndex = 0)
#foreach ($propertyName in $database.getPmbMetaDataPropertySet($pmbClassName))
#set ($propertyType = $database.getPmbMetaDataPropertyType($pmbClassName, $propertyName))
#if ($database.isPmbMetaDataPropertyOptionProcedureParameterIn($pmbClassName, $propertyName))
    public static final String ${propertyName}_PROCEDURE_PARAMETER = "in, ${procedureParameterIndex}";
#set ($procedureParameterIndex = $procedureParameterIndex + 1)
#elseif ($database.isPmbMetaDataPropertyOptionProcedureParameterOut($pmbClassName, $propertyName))
    public static final String ${propertyName}_PROCEDURE_PARAMETER = "out, ${procedureParameterIndex}";
#set ($procedureParameterIndex = $procedureParameterIndex + 1)
#elseif ($database.isPmbMetaDataPropertyOptionProcedureParameterInOut($pmbClassName, $propertyName))
    public static final String ${propertyName}_PROCEDURE_PARAMETER = "inout, ${procedureParameterIndex}";
#set ($procedureParameterIndex = $procedureParameterIndex + 1)
#elseif ($database.isPmbMetaDataPropertyOptionProcedureParameterReturn($pmbClassName, $propertyName))
    public static final String ${propertyName}_PROCEDURE_PARAMETER = "return";
#end
#end
#end

    // ===================================================================================
    //                                                                           Attribute
    //                                                                           =========
#foreach ($propertyName in $database.getPmbMetaDataPropertySet($pmbClassName))
#set ($propertyType = $database.getPmbMetaDataPropertyType($pmbClassName, $propertyName))
    /** ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} */
    protected ${propertyType} _${propertyName};

#if ($database.hasPmbMetaDataPropertyOptionAnyLikeSearch($pmbClassName, $propertyName))
    /** The value of likeSearchOption for ${propertyName}. */
    protected LikeSearchOption _${propertyName}InternalLikeSearchOption;

#end
#end
#if ($database.hasPmbMetaDataSafetyResultDefitinion($pmbClassName))
    /** The max size of safety result. */
    protected int _safetyMaxResultSize;

#end
    // ===================================================================================
    //                                                                         Constructor
    //                                                                         ===========
    public ${myClassName}() {
    }

#if ($database.isPmbMetaDataForProcedure($pmbClassName))
    // ===================================================================================
    //                                                                           Procedure
    //                                                                           =========
    /**
     * {@inheritDoc}
     */
    public String getProcedureName() {
        return "${database.getPmbMetaDataProcedureName($pmbClassName)}";
    }

#end
#if ($database.hasPmbMetaDataSafetyResultDefitinion($pmbClassName))
    // ===================================================================================
    //                                                                       Safety Result
    //                                                                       =============
    /**
     * {@inheritDoc}
     */
    public void checkSafetyResult(int safetyMaxResultSize) {
        _safetyMaxResultSize = safetyMaxResultSize;
    }

    /**
     * {@inheritDoc}
     */
    public int getSafetyMaxResultSize() {
        return _safetyMaxResultSize;
    }

#end
    // ===================================================================================
    //                                                                       Assist Helper
    //                                                                       =============
    protected String convertEmptyToNull(String value) {
        return ParameterUtil.convertEmptyToNull(value);
    }

    protected String handleShortChar(String propertyName, String value, Integer size) {
        ShortCharHandlingMode mode = getShortCharHandlingMode(propertyName, value, size);
        return ParameterUtil.handleShortChar(propertyName, value, size, mode);
    }

    protected ShortCharHandlingMode getShortCharHandlingMode(String propertyName, String value, Integer size) {
        return ShortCharHandlingMode.${database.shortCharHandlingMode};
    }

    protected java.util.Date convertToUtilDate(java.util.Date date) {
        return DfTypeUtil.toDate(date); // if sub class, re-create as pure date
    }

    protected String formatUtilDate(java.util.Date date) {
#if ($database.isDatabaseOracle())
        String pattern = "yyyy-MM-dd HH:mm:ss"; // for Oracle
#else
        String pattern = "yyyy-MM-dd";
#end
        return date != null ? new java.text.SimpleDateFormat(pattern).format(date) : null;
    }

    protected String formatByteArray(byte[] bytes) {
        return "byte[" + (bytes != null ? String.valueOf(bytes.length) : "null") + "]";
    }

    // ===================================================================================
    //                                                                      Basic Override
    //                                                                      ==============
    /**
     * @return The display string of all parameters. (NotNull)
     */
    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName()).append(":");
        sb.append(xbuildColumnString());
        return sb.toString();
    }
    private String xbuildColumnString() {
        final String c = ", ";
        final StringBuilder sb = new StringBuilder();
#foreach ($propertyName in $database.getPmbMetaDataPropertySet($pmbClassName))
#set ($propertyType = $database.getPmbMetaDataPropertyType($pmbClassName, $propertyName))
#if ($propertyType.equals("java.util.Date"))
        sb.append(c).append(formatUtilDate(_${propertyName}));
#elseif ($propertyType.equals("byte[]"))
        sb.append(c).append(formatByteArray(_${propertyName}));
#else
        sb.append(c).append(_${propertyName});
#end
#end
        if (sb.length() > 0) { sb.delete(0, c.length()); }
        sb.insert(0, "{").append("}");
        return sb.toString();
    }

    // ===================================================================================
    //                                                                            Accessor
    //                                                                            ========
#foreach ($propertyName in $database.getPmbMetaDataPropertySet($pmbClassName))
#set ($propertyType = $database.getPmbMetaDataPropertyType($pmbClassName, $propertyName))
    /**
     * [get] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @return The value of ${propertyName}. (Nullable & NotEmptyString: if the value is empty string, returns null)
     */
    public ${propertyType} get${database.initCap($propertyName)}() {
#if ($propertyType.endsWith("String"))
#if ($database.isShortCharHandlingValid() && $database.isPmbMetaDataPropertyRefColumnChar($pmbClassName, $propertyName))
        String filtered = convertEmptyToNull(_${propertyName});
        filtered = handleShortChar("${propertyName}", filtered, ${database.getPmbMetaDataPropertyRefSize($pmbClassName, $propertyName)});
        return filtered;
#else
        return convertEmptyToNull(_${propertyName});
#end
#else
#if ($propertyType.equals("java.util.Date"))
        return convertToUtilDate(_${propertyName});
#else
        return _${propertyName};
#end
#end
    }
#if (!$database.hasPmbMetaDataPropertyOptionOriginalOnlyOneSetter($pmbClassName, $propertyName))

    /**
     * [set] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}(${propertyType} ${propertyName}) {
        _${propertyName} = ${propertyName};
    }
#end
#if ($database.isPmbMetaDataPropertyOptionLikeSearch($pmbClassName, $propertyName))

    /**
     * [set as likeSearch] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     * @param ${propertyName}Option The option of likeSearch for ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}(${propertyType} ${propertyName}, LikeSearchOption ${propertyName}Option) {
        _${propertyName} = ${propertyName};
        _${propertyName}InternalLikeSearchOption = ${propertyName}Option;
    }
#end
#if ($database.isPmbMetaDataPropertyOptionPrefixSearch($pmbClassName, $propertyName))

    /**
     * [set as prefixSearch] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}_PrefixSearch(${propertyType} ${propertyName}) {
        _${propertyName} = ${propertyName};
        _${propertyName}InternalLikeSearchOption = new LikeSearchOption().likePrefix();
    }
#end
#if ($database.isPmbMetaDataPropertyOptionContainSearch($pmbClassName, $propertyName))

    /**
     * [set as containSearch] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}_ContainSearch(${propertyType} ${propertyName}) {
        _${propertyName} = ${propertyName};
        _${propertyName}InternalLikeSearchOption = new LikeSearchOption().likeContain();
    }
#end
#if ($database.isPmbMetaDataPropertyOptionSuffixSearch($pmbClassName, $propertyName))

    /**
     * [set as suffixSearch] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}_SuffixSearch(${propertyType} ${propertyName}) {
        _${propertyName} = ${propertyName};
        _${propertyName}InternalLikeSearchOption = new LikeSearchOption().likeSuffix();
    }
#end
#if ($database.hasPmbMetaDataPropertyOptionAnyLikeSearch($pmbClassName, $propertyName))

    /**
     * Get the internal option of likeSearch for ${propertyName}. {Internal Method: Don't Invoke This!}
     * @return The internal option of likeSearch for ${propertyName}. (Nullable)
     */
    public LikeSearchOption get${database.initCap($propertyName)}InternalLikeSearchOption() {
        return _${propertyName}InternalLikeSearchOption;
    }
#end
#if ($database.isPmbMetaDataPropertyOptionFromDate($pmbClassName, $propertyName))

    /**
     * [set as fromDate] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}_FromDate(${propertyType} ${propertyName}) {
        _${propertyName} = new FromToOption().compareAsDate().filterFromDate(${propertyName});
    }
#end
#if ($database.isPmbMetaDataPropertyOptionToDate($pmbClassName, $propertyName))

    /**
     * [set as toDate] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * @param ${propertyName} The value of ${propertyName}. (Nullable)
     */
    public void set${database.initCap($propertyName)}_ToDate(${propertyType} ${propertyName}) {
        _${propertyName} = new FromToOption().compareAsDate().filterToDate(${propertyName});
    }
#end
#if ($database.isPmbMetaDataPropertyOptionClassification($pmbClassName, $propertyName))
#set ($classificationName = $database.getPmbMetaDataPropertyOptionClassificationName($pmbClassName, $propertyName))
#foreach ($classificationMap in $database.getPmbMetaDataPropertyOptionClassificationMapList($pmbClassName, $propertyName))

    /**
     * [set as ${classificationMap.get('name')}] ${propertyName}${database.getPmbMetaDataPropertyRefColumnInfo($pmbClassName, $propertyName)} <br />
     * ${database.getMapValue($classificationMap, 'comment')}
     */
    public void set${database.initCap($propertyName)}_${classificationMap.get('name')}() {
        _${propertyName} = ${glPackageBaseCommon}.${glCDef}.${classificationName}.${classificationMap.get('name')}.code();
    }
#end
#end

#end
}
