Skip to content

Commit df6cbe4

Browse files
author
i.kriushenkov
committed
Initial commit of codegen
1 parent 158603f commit df6cbe4

34 files changed

+3198
-70
lines changed

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: 53 additions & 2 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,6 +32,10 @@
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>
@@ -41,7 +45,7 @@
4145
<maven.compiler.target>11</maven.compiler.target>
4246

4347
<!--Last opensource JOOQ version for JDK 11-->
44-
<jooq.version>3.14.16</jooq.version>
48+
<jooq.version>3.19.0</jooq.version>
4549
</properties>
4650

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

5696
<build>
@@ -84,6 +124,17 @@
84124
</execution>
85125
</executions>
86126
</plugin>
127+
<plugin>
128+
<groupId>org.apache.maven.plugins</groupId>
129+
<artifactId>maven-surefire-plugin</artifactId>
130+
<version>3.1.0</version>
131+
<configuration>
132+
<environmentVariables>
133+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
134+
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:trunk</YDB_DOCKER_IMAGE>
135+
</environmentVariables>
136+
</configuration>
137+
</plugin>
87138
</plugins>
88139
</build>
89140

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)