Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jooq-dialect/src/main/java/org/jooq/impl/YdbListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public void visitEnd(VisitContext context) {
private void addQuoteForName(VisitContext context) {
QueryPart part = context.queryPart();
if (part instanceof Name) {
if (Name.Quoted.SYSTEM.equals(((Name) part).quoted())) {
return;
}
RenderContext renderContext = context.renderContext();
if (renderContext != null) {
renderContext.sql(quote);
Expand Down
26 changes: 26 additions & 0 deletions jooq-dialect/src/main/java/org/jooq/impl/YdbTableImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jooq.impl;

import org.jooq.Comment;
import org.jooq.Condition;
import org.jooq.Field;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Schema;
import org.jooq.Table;
import org.jooq.TableOptions;

public class YdbTableImpl<R extends Record> extends TableImpl<R> {
private static final Name PRIMARY_KEY = new UnqualifiedName("PRIMARY KEY", Name.Quoted.SYSTEM);

protected YdbTableImpl(Name alias, Table<R> aliased, Field<?>[] parameters, Condition where) {
super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table(), where);
}

protected YdbTableImpl(Name name, Schema schema, Table<R> aliased, Field<?>[] parameters, Comment comment, TableOptions options, Condition where) {
super(name, schema, null, null, null, aliased, parameters, comment, options, where);
}

public Table<R> viewPrimaryKey() {
return new HintedTable<>(this, DSL.keyword("use primary key"), new QueryPartList<>(PRIMARY_KEY));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tech.ydb.jooq.codegen;

import org.jooq.codegen.DefaultGeneratorStrategy;
import org.jooq.impl.YdbTableImpl;
import org.jooq.meta.Definition;
import org.jooq.meta.TableDefinition;
import org.jooq.tools.StringUtils;

public class YdbGeneratorStrategy extends DefaultGeneratorStrategy {
Expand Down Expand Up @@ -36,4 +38,12 @@ private static String getJavaClassName0(String outputName, Mode mode) {
public String getJavaIdentifier(Definition definition) {
return definition.getInputName().toUpperCase(getTargetLocale());
}

@Override
public String getJavaClassExtends(Definition definition, Mode mode) {
if (definition instanceof TableDefinition && YdbGeneratorStrategy.Mode.DEFAULT.equals(mode)) {
return YdbTableImpl.class.getName();
}
return super.getJavaClassExtends(definition, mode);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions jooq-dialect/src/test/java/tech/ydb/jooq/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public void selectAllFrom() {
assertEquals(List.of(FIRST, SECOND), series);
}

@Test
public void selectAllFromUsingPrimaryKey() {
Result<SeriesRecord> series = dsl
.selectFrom(SERIES.viewPrimaryKey())
.fetch();

assertEquals(List.of(FIRST, SECOND), series);
}

@Test
public void selectFromWhereText() {
Result<SeriesRecord> series = dsl
Expand Down