Skip to content

Commit

Permalink
try fix code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbai00 committed Dec 16, 2024
1 parent dbf6417 commit 15a2c5d
Showing 1 changed file with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,49 @@ import org.yaml.snakeyaml.Yaml

import java.io.InputStream
import java.nio.file.{Files, Path}
import java.util.{Map => JMap}
import scala.jdk.CollectionConverters._

object JooqCodeGenerator {
@throws[Exception]
def main(args: Array[String]): Unit = {
// Path to jOOQ configuration XML
// Load jOOQ configuration XML
val jooqXmlPath: Path =
Path.of("dao").resolve("src").resolve("main").resolve("resources").resolve("jooq-conf.xml")
val jooqConfig: Configuration = GenerationTool.load(Files.newInputStream(jooqXmlPath))
// Path to the YAML configuration file

// Load YAML configuration
val yamlConfPath: Path = Path
.of("workflow-core")
.resolve("src")
.resolve("main")
.resolve("resources")
.resolve("storage-config.yaml")
// Load YAML configuration
val yaml: Yaml = new Yaml
try {
val inputStream: InputStream = Files.newInputStream(yamlConfPath)
try {
val config: Map[String, AnyRef] = yaml.load(inputStream)
val jdbcConfigMap: Map[String, AnyRef] = (config
.get("storage")
.asInstanceOf[Map[String, AnyRef]])
.get("jdbc")
.asInstanceOf[Map[String, AnyRef]]
// Set JDBC configuration for jOOQ
val jooqJdbcConfig: Jdbc = new Jdbc
jooqJdbcConfig.setDriver("com.mysql.cj.jdbc.Driver")
jooqJdbcConfig.setUrl(jdbcConfigMap.get("url").toString)
jooqJdbcConfig.setUsername(jdbcConfigMap.get("username").toString)
jooqJdbcConfig.setPassword(jdbcConfigMap.get("password").toString)
jooqConfig.setJdbc(jooqJdbcConfig)
// Generate the code
GenerationTool.generate(jooqConfig)
} finally {
if (inputStream != null) inputStream.close()
}
}
val yaml = new Yaml
val inputStream: InputStream = Files.newInputStream(yamlConfPath)

val conf: Map[String, Any] =
yaml.load(inputStream).asInstanceOf[JMap[String, Any]].asScala.toMap

val jdbcConfig = conf("storage")
.asInstanceOf[JMap[String, Any]]
.asScala("jdbc")
.asInstanceOf[JMap[String, Any]]
.asScala

// Set JDBC configuration for jOOQ
val jooqJdbcConfig = new Jdbc
jooqJdbcConfig.setDriver("com.mysql.cj.jdbc.Driver")
jooqJdbcConfig.setUrl(jdbcConfig("url").toString)
jooqJdbcConfig.setUsername(jdbcConfig("username").toString)
jooqJdbcConfig.setPassword(jdbcConfig("password").toString)

jooqConfig.setJdbc(jooqJdbcConfig)

// Generate the code
GenerationTool.generate(jooqConfig)

// Close input stream
inputStream.close()
}
}

0 comments on commit 15a2c5d

Please sign in to comment.