Skip to content

Commit a4ab344

Browse files
feat-jooq-view-index
1 parent fee759a commit a4ab344

File tree

5 files changed

+85
-45
lines changed

5 files changed

+85
-45
lines changed

jooq-dialect/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## 1.0.0 ##
2+
3+
- `REPLACE` / `UPDATE` builders from YDB
4+
- Supported VIEW INDEX from `useIndex("index_name")` HintedTable
5+
- Generated tables from schema

jooq-dialect/pom.xml

Lines changed: 1 addition & 1 deletion
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>1.0.0-RC1</version>
7+
<version>1.0.0</version>
88

99
<name>YDB JOOQ Dialect module</name>
1010
<description>YDB JOOQ Dialect module</description>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package org.jooq.impl;
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+
/**
10+
* @author Kirill Kurdyukov
11+
*/
12+
public class YdbListener implements VisitListener {
13+
14+
private final String quote;
15+
16+
private volatile int hintedTableStartSize;
17+
18+
public YdbListener(String quote) {
19+
this.quote = quote;
20+
}
21+
22+
@Override
23+
public void visitStart(VisitContext context) {
24+
addQuoteForName(context);
25+
visitStartHint(context);
26+
}
27+
28+
@Override
29+
public void visitEnd(VisitContext context) {
30+
addQuoteForName(context);
31+
try {
32+
visitEndHint(context);
33+
} catch (NoSuchFieldException | IllegalAccessException e) {
34+
throw new RuntimeException(e);
35+
}
36+
}
37+
38+
private void addQuoteForName(VisitContext context) {
39+
QueryPart part = context.queryPart();
40+
if (part instanceof Name) {
41+
RenderContext renderContext = context.renderContext();
42+
if (renderContext != null) {
43+
renderContext.sql(quote);
44+
}
45+
}
46+
}
47+
48+
private void visitStartHint(VisitContext context) {
49+
QueryPart part = context.queryPart();
50+
51+
if (part instanceof QOM.HintedTable<?> hintedTable) {
52+
if (context.renderContext() instanceof DefaultRenderContext renderContext) {
53+
hintedTableStartSize = renderContext.sql.length();
54+
}
55+
}
56+
}
57+
58+
private void visitEndHint(VisitContext context) throws NoSuchFieldException, IllegalAccessException {
59+
QueryPart part = context.queryPart();
60+
61+
if (part instanceof HintedTable<?> hintedTable) {
62+
if (context.renderContext() instanceof DefaultRenderContext renderContext) {
63+
renderContext.sql.setLength(hintedTableStartSize);
64+
65+
renderContext.sql(" view ");
66+
67+
// Sorry, Lukas!!! :(
68+
java.lang.reflect.Field fieldArguments = hintedTable.getClass().getDeclaredField("arguments");
69+
fieldArguments.setAccessible(true);
70+
QueryPartList<Name> arguments = (QueryPartList<Name>)fieldArguments.get(hintedTable);
71+
renderContext.visit(arguments);
72+
}
73+
}
74+
}
75+
}
76+

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

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

jooq-dialect/src/main/java/tech/ydb/jooq/impl/YdbDSLContextImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public YdbDSLContextImpl(Configuration configuration) {
6868
super(configuration
6969
.deriveSettings(YdbDSLContextImpl::addRequiredParameters)
7070
.set(YDB.DIALECT)
71-
.set(quoteListener()));
71+
.set(ydbListener()));
7272
}
7373

7474
private static Settings addRequiredParameters(Settings settings) {
@@ -77,8 +77,8 @@ private static Settings addRequiredParameters(Settings settings) {
7777
.withRenderSchema(false);
7878
}
7979

80-
private static VisitListener quoteListener() {
81-
return new CustomQuoteListener("`");
80+
private static VisitListener ydbListener() {
81+
return new YdbListener("`");
8282
}
8383

8484
@Override

0 commit comments

Comments
 (0)