
#set ($database = $schemaData.database)

## ------------------------------------------------------------------
##                                                    Global-Paramter
##                                                    ---------------
## ===================================================================================
##                                                                            Language
##                                                                            ========
## [Language]
#set ($glTargetLanguage = ${database.TargetLanguage})

## ===================================================================================
##                                                                  Resource Directory
##                                                                  ==================
#set ($glResourceDirectory = ${database.resourceDirectory})

## [Extension]
#set ($glTemplateFileExtension = ${database.TemplateFileExtension})
#set ($glClassFileExtension = ${database.ClassFileExtension})

## [Prefix-and-Suffix]
#set ($glProjectPrefix = ${database.ProjectPrefix})
#set ($glBasePrefix = ${database.BasePrefix})
#set ($glBaseSuffixForEntity = ${database.BaseSuffixForEntity})

## [Package]
#set ($glPackageBaseCommon = "${database.baseCommonPackage}")
#set ($glPackageBaseCommonCBean = "${database.baseCommonPackage}.cbean")
#set ($glPackageBaseCommonCOption = "${database.baseCommonPackage}.cbean.coption")
#set ($glPackageBaseCommonDBMeta = "${database.baseCommonPackage}.dbmeta")
#set ($glPackageBaseCommonDBMetaInfo = "${database.baseCommonPackage}.dbmeta.info")
#set ($glPackageBaseCommonHelper = "${database.baseCommonPackage}.helper")
#set ($glPackageBaseCommonJavaLike = "${database.baseCommonPackage}.javalike")
#set ($glPackageBaseCommonJdbc = "${database.baseCommonPackage}.jdbc")
#set ($glPackageBaseDao = "${database.baseDaoPackage}" )
#set ($glPackageBaseDaoCursor = "${database.baseDaoPackage}.cursor" )
#set ($glPackageBaseEntity = "${database.baseEntityPackage}")
#set ($glPackageExtendedDao = "${database.extendedDaoPackage}")
#set ($glPackageExtendedDaoCursor = "${database.extendedDaoPackage}.cursor")
#set ($glPackageExtendedEntity = "${database.extendedEntityPackage}")
#if ($database.isTargetLanguageCSharp())
  #set ($glPackageBaseCommon = "${database.baseCommonPackage}")
  #set ($glPackageBaseCommonCBean = "${database.baseCommonPackage}.CBean")
  #set ($glPackageBaseCommonCOption = "${database.baseCommonPackage}.CBean.COption")
  #set ($glPackageBaseCommonDBMeta = "${database.baseCommonPackage}.Dbm")
  #set ($glPackageBaseCommonDBMetaInfo = "${database.baseCommonPackage}.Dbm.Info")
  #set ($glPackageBaseCommonHelper = "${database.baseCommonPackage}.Helper")
  #set ($glPackageBaseCommonJavaLike = "${database.baseCommonPackage}.JavaLike")
  #set ($glPackageBaseCommonJdbc = "${database.baseCommonPackage}.Ado")
  #set ($glPackageBaseDao = "${database.baseDaoPackage}" )
  #set ($glPackageBaseDaoCursor = "${database.baseDaoPackage}.Cursor" )
  #set ($glPackageBaseEntity = "${database.baseEntityPackage}")
  #set ($glPackageExtendedDao = "${database.extendedDaoPackage}")
  #set ($glPackageExtendedDaoCursor = "${database.extendedDaoPackage}.Cursor")
  #set ($glPackageExtendedEntity = "${database.extendedEntityPackage}")
#end

## -----------------------------------------------------------------------------------------------------
##                                                                                Parse customize entity
##                                                                                ----------------------
## Setup output directory.
$database.enableSql2EntityOutputDirectory()

## for Sql2Entity
#set ($isSql2Entity = true)

#set ($glPackageBaseCustomizeEntity = "${database.s2jdbcBaseEntityPackage}.customize" )
#set ($glPackageExtendedCustomizeEntity = "${database.s2jdbcExtendedEntityPackage}.customize" )

#set ($path = $strings.getPackageAsPath(${glPackageBaseCustomizeEntity}))
$database.makeDirectory($path)

#set ($path = $strings.getPackageAsPath(${glPackageExtendedCustomizeEntity}))
$database.makeDirectory($path)

$database.debug("public void parseCustomizeEntity() {")
$database.debug("    final List<String> tableNameList = getTableList();")
$database.debug("    for (String tableName : tableNameList) {")
#foreach ($table in $database.tableList)
  #set ($myBaseObjectClassName = "${database.s2jdbcBaseEntityPrefix}${table.javaName}")
  #set ($myBaseEntityPackageName = "${glPackageBaseCustomizeEntity}")
  #set ($myExtendedObjectClassName = "${table.javaName}")
  #set ($myExtendedEntityPackageName = "${glPackageExtendedCustomizeEntity}")

  #set ($myEntityVariableName = "${table.uncapitalisedJavaName}")
  #set ($myEntityListVariableName = "${table.uncapitalisedJavaName}List")

  $database.debug("        parseBaseCustomizeEntity(tableName);     // ${myBaseObjectClassName}")
  #set ( $path = "${strings.getPackageAsPath(${myBaseEntityPackageName})}${myBaseObjectClassName}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/other/s2jdbc/entity/S2jdbcBaseEntity.${glTemplateFileExtension}",$path ,"" ,"")

  #set ( $path = "${strings.getPackageAsPath(${myExtendedEntityPackageName})}${myExtendedObjectClassName}.${glClassFileExtension}" )
  #if (!$files.file(${generator.OutputPath},$path).exists())
    $database.debug("        parseExtendedCustomizeEntity(tableName); // ${myExtendedObjectClassName}")
    $generator.parse("om/${glResourceDirectory}/other/s2jdbc/entity/S2jdbcExtendedEntity.${glTemplateFileExtension}",$path ,"" ,"")
  #end
#end
$database.debug("    }")
$database.debug("}")

## -----------------------------------------------------------------------------------------------------
##                                                                                  Parse parameter bean
##                                                                                  --------------------
#if ($database.isExistPmbMetaData())
$database.debug("public void parseParameterBean() {")
$database.debug("    final List<DfParameterBeanMetaData> parameterBeanList = getParameterBeanList();")
$database.debug("    for (DfParameterBeanMetaData parameterBean : parameterBeanList) {")

  #set ($glPackageBaseParameterBean = "${database.s2jdbcBaseEntityPackage}.pmbean" )
  #set ($glPackageExtendedParameterBean = "${database.s2jdbcExtendedEntityPackage}.pmbean" )

  #set ($path = $strings.getPackageAsPath(${glPackageBaseParameterBean}))
  $database.makeDirectory($path)
  #set ($path = $strings.getPackageAsPath(${glPackageExtendedParameterBean}))
  $database.makeDirectory($path)

  #foreach ($pmbMetaData in $database.pmbMetaDataList)
    #set ($pmbClassName = "$pmbMetaData.className")
    #set ($pmbSuperClassName = "$pmbMetaData.superClassName")
    #set ($myBaseParameterBeanClassName = "${database.s2jdbcBaseEntityPrefix}${pmbClassName}")
    #set ($myExtendedParameterBeanClassName = "${pmbClassName}")

    $database.debug("        parseBaseParameterBean(parameterBean);     // ${myBaseParameterBeanClassName}")
    #set ( $path = "${strings.getPackageAsPath(${glPackageBaseParameterBean})}${myBaseParameterBeanClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/other/s2jdbc/pmbean/S2jdbcBaseParameterBean.${glTemplateFileExtension}",$path ,"" ,"")

    #set ( $path = "${strings.getPackageAsPath(${glPackageExtendedParameterBean})}${myExtendedParameterBeanClassName}.${glClassFileExtension}" )
    #if (!$files.file(${generator.OutputPath},$path).exists())
      $database.debug("        parseExtendedParameterBean(parameterBean); // ${myExtendedParameterBeanClassName}")
      $generator.parse("om/${glResourceDirectory}/other/s2jdbc/pmbean/S2jdbcExtendedParameterBean.${glTemplateFileExtension}",$path ,"" ,"")
    #end
  #end
$database.debug("    }")
$database.debug("}")
#end
