Skip to content

Commit 2b1a13e

Browse files
authored
[JOOQ] Initial support for advanced JOOQ code generation (#123)
2 parents 158603f + 4480885 commit 2b1a13e

36 files changed

+3208
-78
lines changed

.github/workflows/ci-jooq-dialect.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
strategy:
2222
matrix:
23-
java: [ '11', '17' ]
23+
java: [ '17', '21' ]
2424

2525
steps:
2626
- uses: actions/checkout@v4

.github/workflows/publish-jooq-dialect.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Set up JDK
3838
uses: actions/setup-java@v4
3939
with:
40-
java-version: 11
40+
java-version: 17
4141
distribution: 'temurin'
4242
cache: 'maven'
4343

@@ -69,7 +69,7 @@ jobs:
6969
- name: Set up Maven Central Repository
7070
uses: actions/setup-java@v4
7171
with:
72-
java-version: 11
72+
java-version: 17
7373
distribution: 'temurin'
7474
cache: 'maven'
7575
server-id: ossrh-s01

jooq-dialect/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,126 @@
33
[![CI](https://img.shields.io/github/actions/workflow/status/ydb-platform/ydb-java-dialects/ci-jooq-dialect.yaml?branch=main&label=CI)](https://github.com/ydb-platform/ydb-java-dialects/actions/workflows/ci-jooq-dialect.yaml)
44

55
# YDB JOOQ Dialect
6+
7+
## Overview
8+
9+
This project introduces a JOOQ dialect specifically tailored for the Yandex Database (YDB). JOOQ, a popular Java-based ORM tool for SQL-centric database interaction, is now equipped to leverage the unique capabilities of YDB, enabling developers to maintain a high level of type safety and SQL abstraction.
10+
11+
### Features
12+
13+
- Full support for all YDB data types during code generation
14+
- Preserves the original file structure in generated code
15+
- Advanced type safety features aligning with YDB's data types
16+
- Support for YDB-specific SQL syntax and operations *(coming soon)*
17+
18+
## Getting Started
19+
20+
### Requirements
21+
22+
To utilize this JOOQ YDB Dialect, ensure you have:
23+
24+
- Java 11 or above.
25+
- JOOQ 3.15 or higher.
26+
- [YDB JDBC Driver](https://github.com/ydb-platform/ydb-jdbc-driver)
27+
- Access to a YDB Database instance.
28+
29+
### Installation
30+
31+
For Maven, add the following dependencies to your pom.xml:
32+
33+
```xml
34+
<dependency>
35+
<groupId>org.jooq</groupId>
36+
<artifactId>jooq</artifactId>
37+
<version>${jooq.version}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>tech.ydb.jdbc</groupId>
42+
<artifactId>ydb-jdbc-driver</artifactId>
43+
<version>${ydb.jdbc.version}</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>tech.ydb.dialects</groupId>
48+
<artifactId>jooq-ydb-dialect</artifactId>
49+
<version>${jooq.ydb.dialect.version}</version>
50+
</dependency>
51+
```
52+
For Gradle, include in your build.gradle:
53+
54+
```groovy
55+
dependencies {
56+
implementation "org.jooq:jooq:$jooqVersion"
57+
implementation "tech.ydb.dialects:jooq-ydb-dialect:$jooqYdbDialectVersion"
58+
implementation "tech.ydb.jdbc:ydb-jdbc-driver:$ydbJdbcVersion"
59+
}
60+
```
61+
62+
### Configuration
63+
Configure the JOOQ runtime to use the YDB dialect and JDBC driver:
64+
65+
```java
66+
String url = "jdbc:ydb:grpc://localhost:2136/local";
67+
Connection conn = DriverManager.getConnection(url);
68+
69+
DSLContext dsl = new YdbDslContext(conn);
70+
```
71+
72+
### XML config
73+
74+
To ensure successful code generation, it is essential to correctly configure the XML configuration file. Specifically, you must specify two mandatory fields for YDB: `strategy.name=tech.ydb.jooq.codegen.YdbGeneratorStrategy` and `database.name=tech.ydb.jooq.codegen.YdbDatabase`. Here is an example:
75+
76+
```xml
77+
<configuration>
78+
<jdbc>
79+
<driver>tech.ydb.jdbc.YdbDriver</driver>
80+
<url>jdbc:ydb:grpc://localhost:2136/local</url>
81+
<user>$user</user>
82+
<password>$password</password>
83+
</jdbc>
84+
85+
<generator>
86+
<name>org.jooq.codegen.JavaGenerator</name>
87+
88+
<strategy>
89+
<name>tech.ydb.jooq.codegen.YdbGeneratorStrategy</name>
90+
</strategy>
91+
92+
<database>
93+
<name>tech.ydb.jooq.codegen.YdbDatabase</name>
94+
95+
<includes>.*</includes>
96+
97+
<excludes></excludes>
98+
</database>
99+
100+
<target>
101+
<packageName>ydb</packageName>
102+
<directory>./generated</directory>
103+
</target>
104+
</generator>
105+
</configuration>
106+
```
107+
For more information, see [here](https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration/)
108+
109+
## Usage
110+
Leverage the power of JOOQ to create, read, update, and delete operations in a type-safe manner. Utilize advanced querying capabilities with the strong SQL abstraction provided by JOOQ.
111+
112+
Integration with Spring Boot:
113+
```properties
114+
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local
115+
```
116+
117+
## Limitations
118+
119+
To understand what SQL constructs YDB can perform,
120+
see the [documentation](https://ydb.tech/docs/en/yql/reference/) for the query language.
121+
122+
## Authorization
123+
124+
See [connect to YDB](../README.md/#connect-to-ydb).
125+
126+
## Support and Contact
127+
128+
For support, you can open issues in the repository issue tracker with tag `jooq`.

jooq-dialect/pom.xml

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>tech.ydb.dialects</groupId>
66
<artifactId>jooq-ydb-dialect</artifactId>
7-
<version>0.9.0</version>
7+
<version>0.10.0</version>
88

99
<name>YDB JOOQ Dialect module</name>
1010
<description>YDB JOOQ Dialect module</description>
@@ -32,16 +32,19 @@
3232
<organization>YDB</organization>
3333
<organizationUrl>https://ydb.tech/</organizationUrl>
3434
</developer>
35+
<developer>
36+
<name>Ilya Kriushenkov</name>
37+
<email>[email protected]</email>
38+
</developer>
3539
</developers>
3640

3741
<properties>
3842
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
39-
<maven.compiler.release>11</maven.compiler.release>
40-
<maven.compiler.source>11</maven.compiler.source>
41-
<maven.compiler.target>11</maven.compiler.target>
43+
<maven.compiler.release>17</maven.compiler.release>
44+
<maven.compiler.source>17</maven.compiler.source>
45+
<maven.compiler.target>17</maven.compiler.target>
4246

43-
<!--Last opensource JOOQ version for JDK 11-->
44-
<jooq.version>3.14.16</jooq.version>
47+
<jooq.version>3.19.0</jooq.version>
4548
</properties>
4649

4750
<dependencies>
@@ -51,6 +54,42 @@
5154
<version>${jooq.version}</version>
5255
<scope>provided</scope>
5356
</dependency>
57+
<dependency>
58+
<groupId>org.jooq</groupId>
59+
<artifactId>jooq-codegen</artifactId>
60+
<version>${jooq.version}</version>
61+
<scope>provided</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.jetbrains</groupId>
65+
<artifactId>annotations</artifactId>
66+
<version>24.1.0</version>
67+
<scope>compile</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>tech.ydb.jdbc</groupId>
71+
<artifactId>ydb-jdbc-driver-shaded</artifactId>
72+
<version>2.0.7</version>
73+
<scope>compile</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>tech.ydb.test</groupId>
77+
<artifactId>ydb-junit5-support</artifactId>
78+
<version>2.2.0</version>
79+
<scope>test</scope>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.junit.jupiter</groupId>
83+
<artifactId>junit-jupiter-api</artifactId>
84+
<version>5.10.1</version>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-simple</artifactId>
90+
<version>1.7.21</version>
91+
<scope>test</scope>
92+
</dependency>
5493
</dependencies>
5594

5695
<build>
@@ -60,7 +99,7 @@
6099
<artifactId>maven-javadoc-plugin</artifactId>
61100
<version>3.5.0</version>
62101
<configuration>
63-
<source>11</source>
102+
<source>17</source>
64103
</configuration>
65104
<executions>
66105
<execution>
@@ -84,6 +123,17 @@
84123
</execution>
85124
</executions>
86125
</plugin>
126+
<plugin>
127+
<groupId>org.apache.maven.plugins</groupId>
128+
<artifactId>maven-surefire-plugin</artifactId>
129+
<version>3.1.0</version>
130+
<configuration>
131+
<environmentVariables>
132+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
133+
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:latest</YDB_DOCKER_IMAGE>
134+
</environmentVariables>
135+
</configuration>
136+
</plugin>
87137
</plugins>
88138
</build>
89139

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package tech.ydb.jooq;
2+
3+
import org.jooq.Name;
4+
import org.jooq.QueryPart;
5+
import org.jooq.RenderContext;
6+
import org.jooq.VisitContext;
7+
import org.jooq.VisitListener;
8+
9+
public class CustomQuoteListener implements VisitListener {
10+
11+
private final String quote;
12+
13+
public CustomQuoteListener(String quote) {
14+
this.quote = quote;
15+
}
16+
17+
public CustomQuoteListener(char quote) {
18+
this.quote = String.valueOf(quote);
19+
}
20+
21+
@Override
22+
public void visitStart(VisitContext context) {
23+
addQuoteForName(context);
24+
}
25+
26+
@Override
27+
public void visitEnd(VisitContext context) {
28+
addQuoteForName(context);
29+
}
30+
31+
private void addQuoteForName(VisitContext context) {
32+
QueryPart part = context.queryPart();
33+
if (part instanceof Name) {
34+
RenderContext renderContext = context.renderContext();
35+
if (renderContext != null) {
36+
renderContext.sql(quote);
37+
}
38+
}
39+
}
40+
}
41+

jooq-dialect/src/main/java/tech/ydb/jooq/YDBDatabase.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)