[jOOQ/jOOQ#9574] Add org.jooq.Synonym

This includes:

- Add QOM API
- Add CREATE SYNONYM support
- Add DROP SYNONYM support
- Add parser support
This commit is contained in:
Lukas Eder 2024-09-25 15:13:26 +02:00
parent 3f03bd952f
commit 6195a73b62
6 changed files with 976 additions and 3 deletions

View File

@ -10878,6 +10878,130 @@ public interface DSLContext extends Scope {
@Support({ DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, YUGABYTEDB })
CreateSequenceAsStep<Number> createSequenceIfNotExists(Sequence<?> sequence);
/**
* The <code>DROP DATABASE</code> statement.
*
@ -11236,6 +11360,130 @@ public interface DSLContext extends Scope {
@Support({ CUBRID, DUCKDB, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES, YUGABYTEDB })
DropSequenceFinalStep dropSequenceIfExists(Sequence<?> sequence);
/**
* The <code>DROP TABLE</code> statement.
*

View File

@ -392,6 +392,7 @@ import org.jooq.Spatial;
import org.jooq.Statement;
import org.jooq.Stringly;
import org.jooq.Support;
// ...
import org.jooq.Table;
import org.jooq.TableLike;
// ...
@ -9783,6 +9784,202 @@ public class DSL {
return dsl().createSequenceIfNotExists(sequence);
}
/**
* The <code>DROP DATABASE</code> statement.
* <p>
@ -10369,6 +10566,202 @@ public class DSL {
return dsl().dropSequenceIfExists(sequence);
}
/**
* The <code>DROP TABLE</code> statement.
* <p>
@ -13716,6 +14109,30 @@ public class DSL {
);
}
/**
* Create a qualified type, given its type name.
*/

View File

@ -226,6 +226,7 @@ import org.jooq.Sequence;
import org.jooq.Source;
import org.jooq.Statement;
import org.jooq.Stringly;
// ...
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableLike;
@ -3758,6 +3759,82 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new CreateSequenceImpl(configuration(), sequence, true);
}
@Override
public org.jooq.DropDatabaseFinalStep dropDatabase(@Stringly.Name String database) {
return new DropDatabaseImpl(configuration(), DSL.catalog(DSL.name(database)), false);
@ -3964,6 +4041,82 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
return new DropSequenceImpl(configuration(), sequence, true);
}
@Override
public org.jooq.DropTableStep dropTable(@Stringly.Name String table) {
return new DropTableImpl(configuration(), false, DSL.table(DSL.name(table)), false);

View File

@ -415,6 +415,7 @@ final class Keywords {
static final Keyword K_STORED = keyword("stored");
static final Keyword K_STORING = keyword("storing");
static final Keyword K_STRUCT = keyword("struct");
static final Keyword K_SYNONYM = keyword("synonym");
static final Keyword K_SWITCH = keyword("switch");
static final Keyword K_SYMMETRIC = keyword("symmetric");
static final Keyword K_SYSTEM = keyword("system");

View File

@ -393,6 +393,7 @@ import static org.jooq.impl.DSL.stddevSamp;
import static org.jooq.impl.DSL.sum;
import static org.jooq.impl.DSL.sumDistinct;
// ...
// ...
import static org.jooq.impl.DSL.systemName;
import static org.jooq.impl.DSL.table;
import static org.jooq.impl.DSL.tan;
@ -595,6 +596,7 @@ import org.jooq.CreateIndexWhereStep;
// ...
import org.jooq.CreateSequenceAsStep;
import org.jooq.CreateSequenceFlagsStep;
// ...
import org.jooq.CreateTableAsStep;
import org.jooq.CreateTableCommentStep;
import org.jooq.CreateTableElementListStep;
@ -715,6 +717,7 @@ import org.jooq.Sequence;
import org.jooq.SortField;
import org.jooq.SortOrder;
import org.jooq.Statement;
// ...
import org.jooq.Table;
import org.jooq.TableElement;
import org.jooq.TableField;
@ -773,6 +776,8 @@ import org.jooq.types.Interval;
import org.jooq.types.YearToMonth;
import org.jooq.types.YearToSecond;
import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
@ -2876,6 +2881,14 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
parseKeyword("CREATE");
switch (characterUpper()) {
case 'A':
if (parseProKeywordIf("ALIAS"))
;
break;
case 'C':
if (parseKeywordIf("CACHED TABLE"))
return parseCreateTable(false);
@ -2957,9 +2970,19 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
;
else if (parseProKeywordIf("PUBLIC SYNONYM", "PUBLIC ALIAS"))
;
else if (parseProKeywordIf("SYNONYM", "ALIAS"))
;
else
throw expected("FUNCTION", "PACKAGE", "PROCEDURE", "TRIGGER", "VIEW");
throw expected("FUNCTION", "PACKAGE", "PROCEDURE", "PUBLIC SYNONYM", "SYNONYM", "TRIGGER", "VIEW");
}
break;
@ -2971,6 +2994,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
;
else if (parseProKeywordIf("PUBLIC SYNONYM", "PUBLIC ALIAS"))
;
break;
@ -2988,8 +3016,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
return parseCreateSequence();
else if (parseKeywordIf("SPATIAL INDEX") && requireUnsupportedSyntax())
return parseCreateIndex(false);
else if (parseKeywordIf("SYNONYM"))
throw notImplemented("CREATE SYNONYM", "https://github.com/jOOQ/jOOQ/issues/9574");
else if (parseProKeywordIf("SYNONYM"))
;
break;
@ -3028,6 +3059,7 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
}
throw expected(
"ALIAS",
"FUNCTION",
"GENERATOR",
"GLOBAL TEMPORARY TABLE",
@ -3035,8 +3067,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
"OR ALTER",
"OR REPLACE",
"PROCEDURE",
"PUBLIC ALIAS",
"PUBLIC SYNONYM",
"SCHEMA",
"SEQUENCE",
"SYNONYM",
"TABLE",
"TEMPORARY TABLE",
"TRIGGER",
@ -3139,6 +3174,14 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
parseKeyword("DROP");
switch (characterUpper()) {
case 'A':
if (parseProKeywordIf("ALIAS"))
;
break;
case 'D':
if (parseKeywordIf("DATABASE"))
return parseDropDatabase();
@ -3191,6 +3234,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
;
else if (parseProKeywordIf("PUBLIC ALIAS", "PUBLIC SYNONYM"))
;
break;
@ -3210,6 +3258,11 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
DropSchemaStep::cascade,
DropSchemaStep::restrict
);
else if (parseProKeywordIf("SYNONYM"))
;
break;
@ -3264,12 +3317,16 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
}
throw expected(
"ALIAS",
"GENERATOR",
"FUNCTION",
"INDEX",
"PROCEDURE",
"PUBLIC ALIAS",
"PUBLIC SYNONYM",
"SCHEMA",
"SEQUENCE",
"SYNONYM",
"TABLE",
"TEMPORARY TABLE",
"TRIGGER",
@ -4427,6 +4484,25 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
return s;
}
private final DDLQuery parseAlterSequence() {
boolean ifExists = parseKeywordIf("IF EXISTS");
Sequence<?> sequenceName = parseSequenceName();
@ -4568,6 +4644,25 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
: dsl.dropSequence(sequenceName);
}
private final DDLQuery parseCreateTable(boolean temporary) {
boolean ifNotExists = parseKeywordIf("IF NOT EXISTS");
Table<?> tableName = DSL.table(parseTableName().getQualifiedName());
@ -13255,6 +13350,15 @@ final class DefaultParseContext extends AbstractScope implements ParseContext {
return sequence(parseName());
}
private final Name parseIndexName() {
Name result = parseNameIf();

View File

@ -132,6 +132,7 @@ import org.jooq.Sequence;
import org.jooq.SortField;
import org.jooq.Spatial;
import org.jooq.Statement;
// ...
import org.jooq.Table;
import org.jooq.TableElement;
import org.jooq.TableLike;
@ -2307,6 +2308,32 @@ public final class QOM {
@NotNull CreateSequence<T> $noCache(boolean noCache);
}
/**
* The <code>DROP DATABASE</code> statement.
*/
@ -2444,6 +2471,29 @@ public final class QOM {
@NotNull DropSequence $ifExists(boolean ifExists);
}
/**
* The <code>DROP TABLE</code> statement.
*/