Skip to content

Commit

Permalink
Add JooqCodeGenerator to dao and remove core/util (#3160)
Browse files Browse the repository at this point in the history
This PR removes the obsolete `core/util` package which is used to
generate jooq code. The generation logics has been moved to `dao` as
class `JooqCodeGenerator`
  • Loading branch information
bobbai00 authored Dec 16, 2024
1 parent edaf799 commit 41c47bc
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 155 deletions.
1 change: 1 addition & 0 deletions core/dao/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
46 changes: 46 additions & 0 deletions core/dao/src/main/resources/jooq-conf.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<configuration>
<generator>
<!-- The generator for dao -->
<generate>
<generatedAnnotation>false</generatedAnnotation>

<daos>true</daos>
<interfaces>true</interfaces>
</generate>
<!-- The default code generator. You can override this one, to generate your own code style.
Supported generators:
- org.jooq.codegen.JavaGenerator
- org.jooq.codegen.ScalaGenerator
Defaults to org.jooq.codegen.JavaGenerator -->
<name>org.jooq.codegen.JavaGenerator</name>

<database>
<!-- The database type. The format here is:
org.jooq.meta.[database].[database]Database -->
<name>org.jooq.meta.mysql.MySQLDatabase</name>

<!-- The database schema (or in the absence of schema support, in your RDBMS this
can be the owner, user, database name) to be generated -->
<inputSchema>texera_db</inputSchema>

<!-- All elements that are generated from your schema
(A Java regular expression. Use the pipe to separate several expressions)
Watch out for case-sensitivity. Depending on your database, this might be important! -->
<includes>.*</includes>

<!-- All elements that are excluded from your schema
(A Java regular expression. Use the pipe to separate several expressions).
Excludes match before includes, i.e. excludes have a higher priority -->
<excludes>(test_.*)|(ignore_.*)</excludes>

</database>

<target>
<!-- The destination package of your generated classes (within the destination directory) -->
<packageName>edu.uci.ics.texera.dao.jooq.generated</packageName>

<!-- The destination directory of your generated classes. Using Maven directory layout here -->
<directory>dao/src/main/scala</directory>
</target>
</generator>
</configuration>
Original file line number Diff line number Diff line change
@@ -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()
}
}
18 changes: 0 additions & 18 deletions core/util/build.sbt

This file was deleted.

89 changes: 0 additions & 89 deletions core/util/conf/jooq-conf.xml

This file was deleted.

1 change: 0 additions & 1 deletion core/util/project/build.properties

This file was deleted.

47 changes: 0 additions & 47 deletions core/util/src/main/java/edu/uci/ics/util/RunCodegen.java

This file was deleted.

0 comments on commit 41c47bc

Please sign in to comment.