#
# @since DBFlute-0.9.0
#
#set ($database = $schemaData.database)
$database.enableGenerateOutputDirectory()

## - - - - - - - - - - - -
## Initialize properties.
## - - - - - - - - - - - -
$database.initializeVersion(90)
$database.initializeAdditionalPrimaryKey()
$database.initializeAdditionalUniqueKey()
$database.initializeAdditionalForeignKey()
$database.initializeClassificationDeployment()
$database.initializeIncludeQuery()
$database.checkProperties()

## *****************************************************************************************************************
##                                                                                                   Global Paramter
##                                                                                                   ***************
## ===================================================================================
##                                                                            Language
##                                                                            ========
#set ($glTargetLanguage = ${database.targetLanguage})

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

## ===================================================================================
##                                                                           Extension
##                                                                           =========
#set ($glTemplateFileExtension = ${database.templateFileExtension})
#set ($glClassFileExtension = ${database.classFileExtension})

## ===================================================================================
##                                                                              Prefix
##                                                                              ======
#set ($glProjectPrefix = ${database.projectPrefix})
#set ($glBasePrefix = ${database.basePrefix})
#set ($glBaseSuffixForEntity = ${database.baseSuffixForEntity})

## ===================================================================================
##                                                                           Container
##                                                                           =========
#set ($glDBFluteDiconNamespace = "${database.DBFluteDiconNamespace}")
#set ($glDBFluteDiconFileName = "${database.DBFluteDiconFileName}")
#set ($glCreatorDiconFileName = "${database.DBFluteCreatorDiconFileName}")
#set ($glCustomizerDiconFileName = "${database.DBFluteCustomizerDiconFileName}")
#set ($glJ2eeDiconResourceName = "${database.j2eeDiconResourceName}")
#set ($glDBFluteBeansFileName = "${database.DBFluteBeansFileName}")
#set ($glDBFluteModule = "${glProjectPrefix}DBFluteModule")

## ===================================================================================
##                                                                          Class Name
##                                                                          ==========
## -----------------------------------------------------
##                                               Regular
##                                               -------
## [AllCommon]
#set ($glAccessContext = "${glProjectPrefix}AccessContext")
#set ($glCDef = "${glProjectPrefix}CDef")
#set ($glDBCurrent = "${glProjectPrefix}DBCurrent")
#set ($glDBFluteConfig = "${glProjectPrefix}DBFluteConfig")
#set ($glDBFluteInitializer = "${glProjectPrefix}DBFluteInitializer")
#set ($glEntityDefinedCommonColumn = "${glProjectPrefix}EntityDefinedCommonColumn")
#set ($glImplementedBehaviorSelector = "${glProjectPrefix}ImplementedBehaviorSelector")
#set ($glImplementedCommonColumnAutoSetupper = "${glProjectPrefix}ImplementedCommonColumnAutoSetupper")
#set ($glImplementedInvokerAssistant = "${glProjectPrefix}ImplementedInvokerAssistant")
#set ($glImplementedSqlClauseCreator = "${glProjectPrefix}ImplementedSqlClauseCreator")
#set ($glDBMetaInstanceHandler = "${glProjectPrefix}DBMetaInstanceHandler")

## -----------------------------------------------------
##                                               Plug-in
##                                               -------
## [Buri]
#set ($glBasicParticipantProvider = "${glProjectPrefix}BasicParticipantProvider")
#set ($glBasicBuriUserDataProvider = "${glProjectPrefix}BasicBuriUserDataProvider")
#set ($glBehaviorToDataAccessRule = "${glProjectPrefix}BehaviorToDataAccessRule")
#set ($glBuriDef = "${glProjectPrefix}BuriDef")
#set ($glFixedBuriDataAccessScriptFactoryImpl = "${glProjectPrefix}FixedBuriDataAccessScriptFactoryImpl")
#set ($glFixedScriptDataAccessUtilKeyImpl = "${glProjectPrefix}FixedScriptDataAccessUtilKeyImpl")

## ===================================================================================
##                                                                            Variable
##                                                                            ========
#set ($glConditionBeanInitialName = "CB")
#set ($glConditionQueryInitialName = "CQ")
#set ($glAttachedCBArgsVariableName = "cb")

## ===================================================================================
##                                                                             Package
##                                                                             =======
## -----------------------------------------------------
##                                               Regular
##                                               -------
#set ($glPackageBaseCommon = "${database.baseCommonPackage}")
#set ($glPackageBaseBhv = "${database.baseBehaviorPackage}")
#set ($glPackageBaseDao = "${database.baseDaoPackage}" )
#set ($glPackageBaseCustomizeDao = "${database.baseDaoPackage}.customize" )
#set ($glPackageBaseEntity = "${database.baseEntityPackage}")
#set ($glPackageBaseCustomizeEntity = "${database.baseEntityPackage}.customize" )
#set ($glPackageExtendedBhv = "${database.extendedBehaviorPackage}")
#set ($glPackageExtendedDao = "${database.extendedDaoPackage}")
#set ($glPackageExtendedCustomizeDao = "${database.extendedDaoPackage}.customize" )
#set ($glPackageExtendedEntity = "${database.extendedEntityPackage}")
#set ($glPackageExtendedCustomizeEntity = "${database.extendedEntityPackage}.customize" )
#set ($glPackageBaseCB = "${database.conditionBeanPackage}.bs")
#set ($glPackageCB = "${database.extendedConditionBeanPackage}")
#set ($glPackageBaseCQ = "${database.conditionBeanPackage}.cq.bs")
#set ($glPackageCQ = "${database.extendedConditionBeanPackage}.cq")
#set ($glPackageCIQ = "${database.conditionBeanPackage}.cq.ciq")
#set ($glPackageNss = "${database.conditionBeanPackage}.nss")
#set ($glPackageBaseDBMeta = "${glPackageBaseEntity}.dbmeta")
#set ($glPackageBaseCustomizeDBMeta = "${glPackageBaseCustomizeEntity}.dbmeta")

## -----------------------------------------------------
##                                               Plug-in
##                                               -------
## [Buri]
#set ($glPackagePluginBuri = "${database.baseCommonPackage}.plugin.buri")

## *****************************************************************************************************************
##                                                                                                           Parsing
##                                                                                                           *******
## ===================================================================================
##                                                                           AllCommon
##                                                                           =========
$database.info("public void parseAllCommon() {")

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

#if ($database.hasClassificationDefinitionMap())
  $database.info("    parse('CDef');")
  #set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glCDef}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/allcommon/CDef.${glTemplateFileExtension}",$path ,"" ,"")
#end

$database.info("    parse('DBCurrent');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glDBCurrent}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/DBCurrent.${glTemplateFileExtension}",$path ,"" ,"")

$database.info("    parse('DBFluteConfig');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glDBFluteConfig}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/DBFluteConfig.${glTemplateFileExtension}",$path ,"" ,"")

$database.info("    parse('DBFluteInitializer');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glDBFluteInitializer}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/DBFluteInitializer.${glTemplateFileExtension}",$path,"", "")

$database.info("    parse('DBMetaInstanceHandler');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glDBMetaInstanceHandler}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/DBMetaInstanceHandler.${glTemplateFileExtension}",$path,"", "")

$database.info("    parse('EntityDefinedCommonColumn');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glEntityDefinedCommonColumn}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/EntityDefinedCommonColumn.${glTemplateFileExtension}",$path ,"", "")

$database.info("    parse('ImplementedBehaviorSelector');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glImplementedBehaviorSelector}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/ImplementedBehaviorSelector.${glTemplateFileExtension}",$path ,"", "")

$database.info("    parse('ImplementedCommonColumnAutoSetupper');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glImplementedCommonColumnAutoSetupper}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/ImplementedCommonColumnAutoSetupper.${glTemplateFileExtension}",$path ,"", "")

$database.info("    parse('ImplementedInvokerAssistant');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glImplementedInvokerAssistant}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/ImplementedInvokerAssistant.${glTemplateFileExtension}",$path,"", "")

$database.info("    parse('ImplementedSqlClauseCreator');")
#set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glImplementedSqlClauseCreator}.${glClassFileExtension}" )
$generator.parse("om/${glResourceDirectory}/allcommon/ImplementedSqlClauseCreator.${glTemplateFileExtension}",$path ,"" ,"")

$database.info("}")

## ===================================================================================
##                                                                             Plug-in
##                                                                             =======
## -----------------------------------------------------
##                                                  Buri
##                                                  ----
#if ($database.isUseBuri())
  $database.info("public void parsePluginBuri() {")

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

  $database.info("    parse('BasicBuriUserDataProvider');")
  #set ( $path = "${database.getPackageAsPath(${glPackagePluginBuri})}${glBasicBuriUserDataProvider}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/plugin/buri/BasicBuriUserDataProvider.${glTemplateFileExtension}",$path ,"" ,"")

  $database.info("    parse('BasicParticipantProvider');")
  #set ( $path = "${database.getPackageAsPath(${glPackagePluginBuri})}${glBasicParticipantProvider}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/plugin/buri/BasicParticipantProvider.${glTemplateFileExtension}",$path ,"" ,"")

  $database.info("    parse('BehaviorToDataAccessRule');")
  #set ( $path = "${database.getPackageAsPath(${glPackagePluginBuri})}${glBehaviorToDataAccessRule}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/plugin/buri/BehaviorToDataAccessRule.${glTemplateFileExtension}",$path ,"" ,"")

  $database.info("    parse('BuriDef');")
  #set ( $path = "${database.getPackageAsPath(${glPackagePluginBuri})}${glBuriDef}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/plugin/buri/BuriDef.${glTemplateFileExtension}",$path ,"" ,"")

  $database.info("    parse('FixedBuriDataAccessScriptFactoryImpl');")
  #set ( $path = "${database.getPackageAsPath(${glPackagePluginBuri})}${glFixedBuriDataAccessScriptFactoryImpl}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/plugin/buri/FixedBuriDataAccessScriptFactoryImpl.${glTemplateFileExtension}",$path ,"" ,"")

  $database.info("    parse('FixedScriptDataAccessUtilKeyImpl');")
  #set ( $path = "${database.getPackageAsPath(${glPackagePluginBuri})}${glFixedScriptDataAccessUtilKeyImpl}.${glClassFileExtension}" )
  $generator.parse("om/${glResourceDirectory}/plugin/buri/FixedScriptDataAccessUtilKeyImpl.${glTemplateFileExtension}",$path ,"" ,"")

  $database.info("}")
#end

## ===================================================================================
##                                                                     ContainerConfig
##                                                                     ===============
$database.info("public void parseContainerConfig() {")
#if ($database.isTargetContainerSeasar())
  #if ($database.isAvailableHotDeploy())
    #set ($glBehaviorCreator = "${glProjectPrefix}BehaviorCreator")
    #set ($glPackageBaseCommonS2Container = "${database.baseCommonPackage}.s2container")
    #set ($path = $database.getPackageAsPath(${glPackageBaseCommonS2Container}))
    $database.makeDirectory($path)

    $database.info("    parse('BehaviorCreator');")
    #set ( $path = "${database.getPackageAsPath(${glPackageBaseCommonS2Container})}${glBehaviorCreator}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/allcommon/container/seasar/hotdeploy/BehaviorCreator.${glTemplateFileExtension}",$path ,"" ,"")

    #foreach ($dbfluteDiconPackageName in $database.DBFluteDiconPackageNameList)
      #set ($path = "${dbfluteDiconPackageName}" )
      $database.makeDirectory($path)

      #set ($path = "${dbfluteDiconPackageName}/${glDBFluteDiconFileName}" )
      $database.info("    ${path}")
      $generator.parse("om/${glResourceDirectory}/allcommon/container/seasar/hotdeploy/HotDeployDicon.${glTemplateFileExtension}", $path, "", "")

      #set ($path = "${dbfluteDiconPackageName}/${glCreatorDiconFileName}" )
      $database.info("    ${path}")
      $generator.parse("om/${glResourceDirectory}/allcommon/container/seasar/hotdeploy/CreatorDicon.${glTemplateFileExtension}", $path, "", "")

      #set ($path = "${dbfluteDiconPackageName}/${glCustomizerDiconFileName}" )
      $database.info("    ${path}")
      $generator.parse("om/${glResourceDirectory}/allcommon/container/seasar/hotdeploy/CustomizerDicon.${glTemplateFileExtension}", $path, "", "")
    #end
  #else
    #foreach ($dbfluteDiconPackageName in $database.DBFluteDiconPackageNameList)
      #set ($path = "${dbfluteDiconPackageName}" )
      $database.makeDirectory($path)

      #set ($path = "${dbfluteDiconPackageName}/${glDBFluteDiconFileName}" )
      $database.info("    ${path}")
      $generator.parse("om/${glResourceDirectory}/allcommon/container/seasar/DBFluteDicon.${glTemplateFileExtension}", $path, "", "")
    #end
  #end
#end
#if ($database.isTargetContainerSpring())
  #foreach ($dbfluteBeansPackageName in $database.DBFluteBeansPackageNameList)
    #set ($path = "${dbfluteBeansPackageName}" )
    $database.makeDirectory($path)

    #set ($path = "${dbfluteBeansPackageName}/${glDBFluteBeansFileName}" )
    $database.info("    ${path}")
    $generator.parse("om/${glResourceDirectory}/allcommon/container/spring/SpringDBFluteBeans.${glTemplateFileExtension}", $path, "", "")
  #end
#end
#if ($database.isTargetContainerLucy())
  #foreach ($dbfluteBeansPackageName in $database.DBFluteBeansPackageNameList)
    #set ($path = "${dbfluteBeansPackageName}" )
    $database.makeDirectory($path)

    #set ($path = "${dbfluteBeansPackageName}/${glDBFluteBeansFileName}" )
    $database.info("    ${path}")
    $generator.parse("om/${glResourceDirectory}/allcommon/container/lucy/LucyDBFluteBeans.${glTemplateFileExtension}", $path, "", "")
  #end
#end
#if ($database.isTargetContainerGuice())
  #set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glDBFluteModule}.${glClassFileExtension}" )
  $database.info("    ${path}")
  $generator.parse("om/${glResourceDirectory}/allcommon/container/guice/GuiceDBFluteModule.${glTemplateFileExtension}", $path, "", "")
#end
#if ($database.isTargetContainerSlim3())
  #set ( $path = "${database.getPackageAsPath(${glPackageBaseCommon})}${glDBFluteModule}.${glClassFileExtension}" )
  $database.info("    ${path}")
  $generator.parse("om/${glResourceDirectory}/allcommon/container/slim3/Slim3DBFluteModule.${glTemplateFileExtension}", $path, "", "")
#end
$database.info("}")

## ===================================================================================
##                                                                        Table Object
##                                                                        ============
## for Sql2Entity
#set ($isSql2Entity = false)

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

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

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

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

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

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

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

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

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

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

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

##
## Delete old table classes.
##
$database.deleteOldTableClass()

##
## Loop by tables.
##
$database.info("/* * * * * * * * * * * * * * {Table Class}")
#foreach ($table in $database.tables)
  #if (!$table.isForReferenceOnly())

    $database.info("parseTable('${table.Name}');")
    ##
    ## The name of objects
    ##
    #set ($myExtendedDaoClassName = "${table.extendedDaoClassName}")
    #set ($myExtendedDaoPackageName = "${glPackageExtendedDao}")

    #set ($myBaseDaoClassName = "${table.baseDaoClassName}")
    #set ($myBaseDaoPackageName = "${glPackageBaseDao}")

    #set ($myBaseBhvClassName = "${table.baseBehaviorClassName}")
    #set ($myBaseBhvPackageName = "${glPackageBaseBhv}")
    #set ($myExtendedBhvClassName = "${table.extendedBehaviorClassName}")
    #set ($myExtendedBhvPackageName = "${glPackageExtendedBhv}")

    #set ($myBaseObjectClassName = "${table.baseEntityClassName}")
    #set ($myBaseEntityPackageName = "${glPackageBaseEntity}")

    #set ($myExtendedObjectClassName = "${table.extendedEntityClassName}")
    #set ($myExtendedEntityPackageName = "${glPackageExtendedEntity}")

    #set ($myBaseConditionBeanClassName = "${table.baseConditionBeanClassName}")
    #set ($myConditionBeanClassName = "${table.extendedConditionBeanClassName}")
    #set ($myAbstractBaseConditionQueryClassName = "${table.abstractBaseConditionQueryClassName}")
    #set ($myBaseConditionQueryClassName = "${table.baseConditionQueryClassName}")
    #set ($myConditionQueryClassName = "${table.extendedConditionQueryClassName}")
    #set ($myConditionInlineQueryClassName = "${table.extendedConditionInlineQueryClassName}")
    #set ($myNestSelectSetupperClassName = "${table.nestSelectSetupperClassName}")
    #set ($myNestSelectSetupperTerminalClassName = "${table.nestSelectSetupperTerminalClassName}")

    #set ($myDBMetaClassName = "${table.DBMetaClassName}")
    #set ($myDBMetaPackageName = "${glPackageBaseDBMeta}")

    ##
    ## The variable name
    ##
    #set ($myAttachedCBArgsString = "${glPackageCB}.${myConditionBeanClassName} ${glAttachedCBArgsVariableName}")

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

    ##
    ## Determination
    ##
    #set ($isExistBehavior = false)
    #set ($isExistBehavior = true)
    #set ($isExistDao = true)
    #set ($isExistConditionBean = true)

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseBhv})}${myBaseBhvClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/bsbhv/BaseBhv.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseEntity})}${myBaseObjectClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/bsentity/BaseEntity.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseDBMeta})}${myDBMetaClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/bsentity/dbmeta/DBMetaImpl.${glTemplateFileExtension}",$path,"", "")

    #if (!$database.isStopGenerateExtendedBhv())
      #set ( $path = "${database.getPackageAsPath(${glPackageExtendedBhv})}${myExtendedBhvClassName}.${glClassFileExtension}" )
      #if (!$files.file(${generator.outputPath},$path).exists())
        $generator.parse("om/${glResourceDirectory}/exbhv/ExtendedBhv.${glTemplateFileExtension}", $path, "table", $table)
      #end
      $database.reflectAllExCopyright($path)
    #end

    #if (!$database.isStopGenerateExtendedEntity())
      #set ( $path = "${database.getPackageAsPath(${glPackageExtendedEntity})}${myExtendedObjectClassName}.${glClassFileExtension}" )
      #if (!$files.file(${generator.outputPath},$path).exists())
        $generator.parse("om/${glResourceDirectory}/exentity/ExtendedEntity.${glTemplateFileExtension}", $path, "table", $table)
      #end
      $database.reflectAllExCopyright($path)
    #end

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseCB})}${myBaseConditionBeanClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/cbean/BsConditionBean.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseCQ})}${myAbstractBaseConditionQueryClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/cbean/AbstractBsConditionQuery.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageCIQ})}${myConditionInlineQueryClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/cbean/BsConditionInlineQuery.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseCQ})}${myBaseConditionQueryClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/cbean/BsConditionQuery.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageNss})}${myNestSelectSetupperClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/cbean/NestSelectSetupper.${glTemplateFileExtension}", $path, "table", $table)

    #set ( $path = "${database.getPackageAsPath(${glPackageCB})}${myConditionBeanClassName}.${glClassFileExtension}" )
    #if (!$files.file(${generator.outputPath},$path).exists())
      $generator.parse("om/${glResourceDirectory}/cbean/ExConditionBean.${glTemplateFileExtension}", $path, "table", $table)
    #end
    $database.reflectAllExCopyright($path)

    #set ( $path = "${database.getPackageAsPath(${glPackageCQ})}${myConditionQueryClassName}.${glClassFileExtension}" )
    #if (!$files.file(${generator.outputPath},$path).exists())
      $generator.parse("om/${glResourceDirectory}/cbean/ExConditionQuery.${glTemplateFileExtension}", $path, "table", $table)
    #end
    $database.reflectAllExCopyright($path)
  #end
#end
$database.info("* * * * * * * * * */")
$database.info(" ")

## ===================================================================================
##                                                                          Simple Dto
##                                                                          ==========
#if ($database.hasSimpleDtoDefinition() && $database.isTargetLanguageJava())
  $database.info("parseSimpleDto() {// mapper=$database.isSimpleDtoUseDtoMapper()")
  #set ($myDomainEntityPackageName = "${glPackageExtendedEntity}")
  #set ($myBaseEntityPackageName = "${database.simpleDtoBaseDtoPackage}")
  #set ($myExtendedEntityPackageName = "${database.simpleDtoExtendedDtoPackage}")
  #set ($myDtoMapperPackageName = "${database.simpleDtoDtoMapperPackage}")

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

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

  #if ($database.isSimpleDtoUseDtoMapper())
    #set ($path = $database.getPackageAsPath(${myDtoMapperPackageName}))
    $database.makeDirectory($path)
  #end

  #foreach ($table in $database.tables)
    #set ($myBaseObjectClassName = "${database.simpleDtoBaseDtoPrefix}${table.javaName}${database.simpleDtoBaseDtoSuffix}")
    #set ($myExtendedObjectClassName = "${database.simpleDtoExtendedDtoPrefix}${table.javaName}${database.simpleDtoExtendedDtoSuffix}")
    #set ($myDtoMapperClassName = "${myExtendedObjectClassName}Mapper")

    $database.info("    parse('${myExtendedObjectClassName}');")

    #set ( $path = "${database.getPackageAsPath(${myBaseEntityPackageName})}${myBaseObjectClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/plugin/simpledto/SimpleDtoBaseEntity.${glTemplateFileExtension}", $path, "table", $table)

    #if (!$database.isStopGenerateExtendedEntity())
      #set ( $path = "${database.getPackageAsPath(${myExtendedEntityPackageName})}${myExtendedObjectClassName}.${glClassFileExtension}" )
      #if (!$files.file(${generator.outputPath},$path).exists())
        $generator.parse("om/${glResourceDirectory}/plugin/simpledto/SimpleDtoExtendedEntity.${glTemplateFileExtension}", $path, "table", $table)
      #end
      $database.reflectAllExCopyright($path)
    #end

    #if ($database.isSimpleDtoUseDtoMapper())
      #set ( $path = "${database.getPackageAsPath(${myDtoMapperPackageName})}${myDtoMapperClassName}.${glClassFileExtension}" )
      $generator.parse("om/${glResourceDirectory}/plugin/simpledto/mapper/SimpleDtoMapper.${glTemplateFileExtension}", $path, "table", $table)
    #end
  #end
  $database.info("}")
#end

## ===================================================================================
##                                                                            Flex Dto
##                                                                            ========
#if ($database.hasFlexDtoDefinition() && $database.isTargetLanguageJava())
  $database.enableFlexDtoOutputDirectory()
  $database.info("parseFlexDto() {")
  #set ($myBaseEntityPackageName = "${database.flexDtoBaseDtoPackage}")
  #set ($myExtendedEntityPackageName = "${database.flexDtoExtendedDtoPackage}")

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

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

  #foreach ($table in $database.tables)
    #set ($myBaseObjectClassName = "${database.flexDtoBaseDtoPrefix}${table.javaName}${database.flexDtoBaseDtoSuffix}")
    #set ($myExtendedObjectClassName = "${database.flexDtoExtendedDtoPrefix}${table.javaName}${database.flexDtoExtendedDtoSuffix}")
    #set ($myRemoteSimpleDtoClassName = "${database.simpleDtoExtendedDtoPackage}.${myExtendedObjectClassName}")

    $database.info("    parse('${myExtendedObjectClassName}');")

    #set ( $path = "${database.getPackageAsPath(${myBaseEntityPackageName})}${myBaseObjectClassName}.as" )
    $generator.parse("om/${glResourceDirectory}/plugin/flexdto/FlexDtoBaseEntity.${glTemplateFileExtension}", $path, "table", $table)

    #if (!$database.isStopGenerateExtendedEntity())
      #set ( $path = "${database.getPackageAsPath(${myExtendedEntityPackageName})}${myExtendedObjectClassName}.as" )
      #if ($database.isFlexDtoOverrideExtended() || !$files.file(${generator.outputPath},$path).exists())
        $generator.parse("om/${glResourceDirectory}/plugin/flexdto/FlexDtoExtendedEntity.${glTemplateFileExtension}", $path, "table", $table)
      #end
      $database.reflectAllExCopyright($path)
    #end
  #end
  $database.info("}")
  $database.enableGenerateOutputDirectory()
#end

