Saturday, June 4, 2022
HomeProgrammingThe jOOQ Parser Ignore Remark Syntax – Java, SQL and jOOQ.

The jOOQ Parser Ignore Remark Syntax – Java, SQL and jOOQ.


[*]

jOOQ’s parser can’t parse each potential SQL syntax. Do that random PostgreSQL syntax:

And the jOOQ parser will complain:

DOMAIN, INDEX, SCHEMA, SEQUENCE, SESSION, TABLE, TYPE, or VIEW anticipated: [1:7] ALTER [*]SYSTEM RESET ALL

That’s completely superb. The aim of the jOOQ parser isn’t to grasp all vendor particular syntax. The aim is to supply parser performance for the entire syntax supported by jOOQ thus far, and to have the ability to translate it between dialects. For lots of syntax just like the above, there isn’t an equal in different dialects anyway.

However if you happen to’re utilizing the jOOQ parser to simulate a database migration, e.g. to create a schema diff, or to generate jOOQ code utilizing the DDLDatabase, then you’ll have some bits of vendor particular SQL in your scripts that you really want jOOQ to disregard. For instance, the above command could also be in the course of a migration script:

CREATE TABLE a (i int);
ALTER SYSTEM RESET ALL;
CREATE TABLE b (i int);

Fortunately, with jOOQ, you possibly can add particular markers across the instructions you want to inform jOOQ to disregard, and jOOQ will ignore them. For this, simply allow the Settings.parseIgnoreComments flag, and now you need to use a particular remark syntax:

CREATE TABLE a (i int);

/* [jooq ignore start] */
ALTER SYSTEM RESET ALL;
/* [jooq ignore stop] */

CREATE TABLE b (i int);

The syntax is clear to your RDBMS, as a result of they’re simply feedback. So, the RDBMS will see and execute this, identical to earlier than. So, your precise database migration isn’t affected:

CREATE TABLE a (i int);

/*                     */
ALTER SYSTEM RESET ALL;
/*                    */

CREATE TABLE b (i int);

However jOOQ, then again, will interpret the feedback a bit in another way, and see and execute this, as an alternative:

CREATE TABLE a (i int);

/*

                      */

CREATE TABLE b (i int);

Word, if you happen to don’t just like the [jooq ignore start] and [jooq ignore stop] tokens, you possibly can customise them as nicely through Settings.parseIgnoreCommentStart and Settings.parseIgnoreCommentStop.

Like all of those purely text-based preprocessor syntaxes, this works fully transparently, even inside some command syntax. Assuming you’re utilizing some vendor-specific syntax in a CREATE TABLE‘s DEFAULT expression, you possibly can simply exclude that DEFAULT expression from jOOQ’s parsing:

CREATE TABLE t (
  a int 
    /* [jooq ignore start] */ 
    DEFAULT some_fancy_expression() 
    /* [jooq ignore stop] */
);

Clearly, you don’t must format issues this manner, that’s only for illustration functions on this weblog. Now, once more, the RDBMS will see and execute this:

CREATE TABLE t (
  a int 
    /*                     */ 
    DEFAULT some_fancy_expression() 
    /*                    */
);

Whereas jOOQ’s parser will see and execute this:

CREATE TABLE t (
  a int 
    /*

                          */
);

For extra details about this matter, please discuss with the jOOQ handbook.

[*]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments