-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ydb jooq is supported view index statement (#154)
- Loading branch information
1 parent
fee759a
commit fcaf26e
Showing
5 changed files
with
85 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## 1.0.0 ## | ||
|
||
- `REPLACE` / `UPSERT` builders from YDB | ||
- Supported VIEW INDEX from `useIndex("index_name")` HintedTable | ||
- Generated tables from schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.jooq.impl; | ||
|
||
import org.jooq.Name; | ||
import org.jooq.QueryPart; | ||
import org.jooq.RenderContext; | ||
import org.jooq.VisitContext; | ||
import org.jooq.VisitListener; | ||
|
||
/** | ||
* @author Kirill Kurdyukov | ||
*/ | ||
public class YdbListener implements VisitListener { | ||
|
||
private final String quote; | ||
|
||
private volatile int hintedTableStartSize; | ||
|
||
public YdbListener(String quote) { | ||
this.quote = quote; | ||
} | ||
|
||
@Override | ||
public void visitStart(VisitContext context) { | ||
addQuoteForName(context); | ||
visitStartHint(context); | ||
} | ||
|
||
@Override | ||
public void visitEnd(VisitContext context) { | ||
addQuoteForName(context); | ||
try { | ||
visitEndHint(context); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private void addQuoteForName(VisitContext context) { | ||
QueryPart part = context.queryPart(); | ||
if (part instanceof Name) { | ||
RenderContext renderContext = context.renderContext(); | ||
if (renderContext != null) { | ||
renderContext.sql(quote); | ||
} | ||
} | ||
} | ||
|
||
private void visitStartHint(VisitContext context) { | ||
QueryPart part = context.queryPart(); | ||
|
||
if (part instanceof QOM.HintedTable<?> hintedTable) { | ||
if (context.renderContext() instanceof DefaultRenderContext renderContext) { | ||
hintedTableStartSize = renderContext.sql.length(); | ||
} | ||
} | ||
} | ||
|
||
private void visitEndHint(VisitContext context) throws NoSuchFieldException, IllegalAccessException { | ||
QueryPart part = context.queryPart(); | ||
|
||
if (part instanceof HintedTable<?> hintedTable) { | ||
if (context.renderContext() instanceof DefaultRenderContext renderContext) { | ||
renderContext.sql.setLength(hintedTableStartSize); | ||
|
||
renderContext.sql(" view "); | ||
|
||
// Sorry, Lukas!!! :( | ||
java.lang.reflect.Field fieldArguments = hintedTable.getClass().getDeclaredField("arguments"); | ||
fieldArguments.setAccessible(true); | ||
QueryPartList<Name> arguments = (QueryPartList<Name>)fieldArguments.get(hintedTable); | ||
renderContext.visit(arguments); | ||
} | ||
} | ||
} | ||
} | ||
|
41 changes: 0 additions & 41 deletions
41
jooq-dialect/src/main/java/tech/ydb/jooq/CustomQuoteListener.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters