diff --git a/core/dao/build.sbt b/core/dao/build.sbt index 23ec6c6dcb3..526c37be92e 100644 --- a/core/dao/build.sbt +++ b/core/dao/build.sbt @@ -88,4 +88,5 @@ libraryDependencies ++= Seq( libraryDependencies ++= Seq( "mysql" % "mysql-connector-java" % "8.0.33", // MySQL connector + "org.yaml" % "snakeyaml" % "1.30", // for reading storage config yaml file ) \ No newline at end of file diff --git a/core/dao/src/main/resources/jooq-conf.xml b/core/dao/src/main/resources/jooq-conf.xml new file mode 100644 index 00000000000..2935bce5073 --- /dev/null +++ b/core/dao/src/main/resources/jooq-conf.xml @@ -0,0 +1,46 @@ + + + + + false + + true + true + + + org.jooq.codegen.JavaGenerator + + + + org.jooq.meta.mysql.MySQLDatabase + + + texera_db + + + .* + + + (test_.*)|(ignore_.*) + + + + + + edu.uci.ics.texera.dao.jooq.generated + + + dao/src/main/scala + + + 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 new file mode 100644 index 00000000000..f0297781434 --- /dev/null +++ b/core/dao/src/main/scala/edu/uci/ics/texera/dao/JooqCodeGenerator.scala @@ -0,0 +1,54 @@ +package edu.uci.ics.texera.dao + +import org.jooq.codegen.GenerationTool +import org.jooq.meta.jaxb.{Configuration, Jdbc} +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 = { + // 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)) + + // Load YAML configuration + val yamlConfPath: Path = Path + .of("workflow-core") + .resolve("src") + .resolve("main") + .resolve("resources") + .resolve("storage-config.yaml") + 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() + } +} diff --git a/core/util/build.sbt b/core/util/build.sbt deleted file mode 100644 index 58d56c4f89f..00000000000 --- a/core/util/build.sbt +++ /dev/null @@ -1,18 +0,0 @@ -name := "util" -organization := "edu.uci.ics" -version := "0.1-SNAPSHOT" - -scalaVersion := "2.13.12" - -lazy val util = project - .in(file(".")) - .settings( - // https://mvnrepository.com/artifact/mysql/mysql-connector-java - libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.23", - // https://mvnrepository.com/artifact/com.typesafe/config - libraryDependencies += "com.typesafe" % "config" % "1.4.1", - // https://mvnrepository.com/artifact/org.jooq/jooq - libraryDependencies += "org.jooq" % "jooq" % "3.14.4", - // https://mvnrepository.com/artifact/org.jooq/jooq-codegen - libraryDependencies += "org.jooq" % "jooq-codegen" % "3.12.4" - ) diff --git a/core/util/conf/jooq-conf.xml b/core/util/conf/jooq-conf.xml deleted file mode 100644 index b30e2abcce3..00000000000 --- a/core/util/conf/jooq-conf.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - false - - true - true - - - org.jooq.codegen.JavaGenerator - - - - org.jooq.meta.mysql.MySQLDatabase - - - texera_db - - - .* - - - (test_.*)|(ignore_.*) - - - - - - edu.uci.ics.texera.web.model.jooq.generated - - - core/amber/src/main/scala - - - - - - false - - true - true - - - org.jooq.codegen.JavaGenerator - - - - org.jooq.meta.mysql.MySQLDatabase - - - texera_db - - - .* - - - (test_.*)|(ignore_.*) - - - - - - edu.uci.ics.texera.dao.jooq.generated - - - core/dao/src/main/scala - - - diff --git a/core/util/project/build.properties b/core/util/project/build.properties deleted file mode 100644 index bb5389da211..00000000000 --- a/core/util/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.5.5 \ No newline at end of file diff --git a/core/util/src/main/java/edu/uci/ics/util/RunCodegen.java b/core/util/src/main/java/edu/uci/ics/util/RunCodegen.java deleted file mode 100644 index 3db167a5ba9..00000000000 --- a/core/util/src/main/java/edu/uci/ics/util/RunCodegen.java +++ /dev/null @@ -1,47 +0,0 @@ -package edu.uci.ics.util; - - -import com.typesafe.config.Config; -import com.typesafe.config.ConfigFactory; -import org.jooq.codegen.GenerationTool; -import org.jooq.meta.jaxb.Configuration; -import org.jooq.meta.jaxb.Jdbc; - -import java.nio.file.Files; -import java.nio.file.Path; - -/** - * This class is used to generate java classes representing the sql table in Texera database - * These auto generated classes are essential for the connection between backend and database when using JOOQ library. - *

- * Every time the table in the Texera database changes, including creating, dropping and modifying the tables, - * this class must be run to update the corresponding java classes. - *

- * Remember to change the username and password to your owns before you run this class. - *

- * The username, password and connection url is located in texera\core\conf\jdbc.conf - * The configuration file is located in texera\core\conf\jooq-conf.xml - */ -public class RunCodegen { - - public static void main(String[] args) throws Exception { - Path jooqXmlPath = Path.of("core").resolve("util").resolve("conf").resolve("jooq-conf.xml"); - Configuration jooqConfig = GenerationTool.load(Files.newInputStream(jooqXmlPath)); - - Path jdbcConfPath = Path.of("core").resolve("amber").resolve("src").resolve("main").resolve("resources").resolve("application.conf"); - Config jdbcConfig = ConfigFactory.parseFile(jdbcConfPath.toFile()); - - Jdbc jooqJdbcConfig = new Jdbc(); - jooqJdbcConfig.setDriver("com.mysql.cj.jdbc.Driver"); - jooqJdbcConfig.setUrl(jdbcConfig.getString("jdbc.url")); - jooqJdbcConfig.setUsername(jdbcConfig.getString("jdbc.username")); - jooqJdbcConfig.setPassword(jdbcConfig.getString("jdbc.password")); - jooqConfig.setJdbc(jooqJdbcConfig); - - GenerationTool.generate(jooqConfig); - } - -} - - -