From 15a2c5d8214ed2dfa45695852030f06a9e4623f4 Mon Sep 17 00:00:00 2001 From: Jiadong Bai Date: Mon, 16 Dec 2024 14:02:00 -0800 Subject: [PATCH] try fix code gen --- .../ics/texera/dao/JooqCodeGenerator.scala | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/core/dao/src/main/scala/edu/uci/ics/texera/dao/JooqCodeGenerator.scala b/core/dao/src/main/scala/edu/uci/ics/texera/dao/JooqCodeGenerator.scala index 921d0a0fec4..f0297781434 100644 --- a/core/dao/src/main/scala/edu/uci/ics/texera/dao/JooqCodeGenerator.scala +++ b/core/dao/src/main/scala/edu/uci/ics/texera/dao/JooqCodeGenerator.scala @@ -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() } }