#
# @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 ($glDBFluteModuleAp = "${database.DBFluteModuleBhvApClassName}")
#set ($glDBFluteModuleLib = "${database.libraryProjectPrefix}DBFluteModule")

## ===================================================================================
##                                                                             Package
##                                                                             =======
## -----------------------------------------------------
##                                               Regular
##                                               -------
#set ($glPackageBaseCommonAp = "${database.applicationAllCommonPackage}")
#set ($glPackageBaseBhvAp = "${database.baseBehaviorPackage}")
#set ($glPackageExtendedBhvAp = "${database.extendedBehaviorPackage}")
#set ($glPackageBaseCommonLib = "${database.libraryAllCommonPackage}")
#set ($glPackageExtendedBhvLib = "${database.libraryBehaviorPackage}")

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

## *****************************************************************************************************************
##                                                                                                           Parsing
##                                                                                                           *******

## ===================================================================================
##                                                                     ContainerConfig
##                                                                     ===============
$database.info("public void parseContainerConfig() {")
#if ($database.isTargetContainerSeasar())
  #foreach ($dbfluteDiconPackageName in $database.DBFluteDiconPackageNameList)
    #set ($path = "${dbfluteDiconPackageName}" )
    $database.makeDirectory($path)

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

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

    #set ($path = "${dbfluteBeansPackageName}/${glDBFluteBeansFileName}" )
    #set ($path = $database.filterDBFluteBeansBhvAp($path) )
    $database.info("    ${path}")
    $generator.parse("om/${glResourceDirectory}/plugin/bhvap/container/lucy/BhvApLucyDBFluteBeans.${glTemplateFileExtension}", $path, "", "")
  #end
#end
#if ($database.isTargetContainerGuice())
  #set ($path = $database.getPackageAsPath(${glPackageBaseCommonAp}))
  $database.makeDirectory($path)

  #set ($path = "${database.getPackageAsPath(${glPackageBaseCommonAp})}${glDBFluteModuleAp}.${glClassFileExtension}" )
  $database.info("    ${path}")
  $generator.parse("om/${glResourceDirectory}/plugin/bhvap/container/guice/BhvApGuiceDBFluteModule.${glTemplateFileExtension}", $path, "", "")
#end
$database.info("}")

## ===================================================================================
##                                                                        Table Object
##                                                                        ============
#set ($path = $database.getPackageAsPath(${glPackageBaseBhvAp}))
$database.makeDirectory($path)

#set ($path = $database.getPackageAsPath(${glPackageExtendedBhvAp}))
$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}');")

    #set ($myBaseBhvApClassName = "${table.baseBehaviorApClassName}")
    #set ($myExtendedBhvApClassName = "${table.extendedBehaviorApClassName}")
    #set ($myExtendedBhvLibClassName = "${table.extendedBehaviorLibClassName}")

    #set ( $path = "${database.getPackageAsPath(${glPackageBaseBhvAp})}${myBaseBhvApClassName}.${glClassFileExtension}" )
    $generator.parse("om/${glResourceDirectory}/plugin/bhvap/BhvApBaseBhv.${glTemplateFileExtension}", $path, "table", $table)

    #if (!$database.isStopGenerateExtendedBhv())
      #set ( $path = "${database.getPackageAsPath(${glPackageExtendedBhvAp})}${myExtendedBhvApClassName}.${glClassFileExtension}" )
      #if (!$files.file(${generator.outputPath},$path).exists())
        $generator.parse("om/${glResourceDirectory}/plugin/bhvap/BhvApExtendedBhv.${glTemplateFileExtension}", $path, "table", $table)
      #end
      $database.reflectAllExCopyright($path)
    #end
  #end
#end
$database.info("* * * * * * * * * */")
$database.info(" ")

