[jOOQ/jOOQ#9362] Add Settings.interpreterDialect

This commit is contained in:
Knut Wannheden 2019-10-30 06:48:10 +01:00
parent fcbbc5103e
commit b52ab14560
5 changed files with 67 additions and 11 deletions

View File

@ -183,6 +183,9 @@ public class Settings
protected ExecuteWithoutWhere executeDeleteWithoutWhere = ExecuteWithoutWhere.LOG_DEBUG;
@XmlElement(type = String.class, defaultValue = "DEFAULT")
@XmlJavaTypeAdapter(SQLDialectAdapter.class)
protected SQLDialect interpreterDialect;
@XmlElement(type = String.class, defaultValue = "DEFAULT")
@XmlJavaTypeAdapter(SQLDialectAdapter.class)
protected SQLDialect parseDialect;
@XmlElement(defaultValue = "OFF")
@XmlSchemaType(name = "string")
@ -1550,6 +1553,22 @@ public class Settings
this.executeDeleteWithoutWhere = value;
}
/**
* [#7337] The dialect that should be used to interpret SQL DDL statements. {@link SQLDialect#DEFAULT} means that jOOQ interprets the SQL itself. Any other dialect (if supported) will be interpreted on an actual JDBC connection.
*
*/
public SQLDialect getInterpreterDialect() {
return interpreterDialect;
}
/**
* [#7337] The dialect that should be used to interpret SQL DDL statements. {@link SQLDialect#DEFAULT} means that jOOQ interprets the SQL itself. Any other dialect (if supported) will be interpreted on an actual JDBC connection.
*
*/
public void setInterpreterDialect(SQLDialect value) {
this.interpreterDialect = value;
}
/**
* [#7337] The input dialect that should be chosen to disambiguate ambiguous SQL syntax.
*
@ -2170,6 +2189,15 @@ public class Settings
return this;
}
/**
* [#7337] The dialect that should be used to interpret SQL DDL statements. {@link SQLDialect#DEFAULT} means that jOOQ interprets the SQL itself. Any other dialect (if supported) will be interpreted on an actual JDBC connection.
*
*/
public Settings withInterpreterDialect(SQLDialect value) {
setInterpreterDialect(value);
return this;
}
/**
* [#7337] The input dialect that should be chosen to disambiguate ambiguous SQL syntax.
*
@ -2313,6 +2341,7 @@ public class Settings
builder.append("emulateOnDuplicateKeyUpdateOnPrimaryKeyOnly", emulateOnDuplicateKeyUpdateOnPrimaryKeyOnly);
builder.append("executeUpdateWithoutWhere", executeUpdateWithoutWhere);
builder.append("executeDeleteWithoutWhere", executeDeleteWithoutWhere);
builder.append("interpreterDialect", interpreterDialect);
builder.append("parseDialect", parseDialect);
builder.append("parseWithMetaLookups", parseWithMetaLookups);
builder.append("parseUnsupportedSyntax", parseUnsupportedSyntax);
@ -2891,6 +2920,15 @@ public class Settings
return false;
}
}
if (interpreterDialect == null) {
if (other.interpreterDialect!= null) {
return false;
}
} else {
if (!interpreterDialect.equals(other.interpreterDialect)) {
return false;
}
}
if (parseDialect == null) {
if (other.parseDialect!= null) {
return false;
@ -3031,6 +3069,7 @@ public class Settings
result = ((prime*result)+((emulateOnDuplicateKeyUpdateOnPrimaryKeyOnly == null)? 0 :emulateOnDuplicateKeyUpdateOnPrimaryKeyOnly.hashCode()));
result = ((prime*result)+((executeUpdateWithoutWhere == null)? 0 :executeUpdateWithoutWhere.hashCode()));
result = ((prime*result)+((executeDeleteWithoutWhere == null)? 0 :executeDeleteWithoutWhere.hashCode()));
result = ((prime*result)+((interpreterDialect == null)? 0 :interpreterDialect.hashCode()));
result = ((prime*result)+((parseDialect == null)? 0 :parseDialect.hashCode()));
result = ((prime*result)+((parseWithMetaLookups == null)? 0 :parseWithMetaLookups.hashCode()));
result = ((prime*result)+((parseUnsupportedSyntax == null)? 0 :parseUnsupportedSyntax.hashCode()));

View File

@ -63,18 +63,18 @@ final class DDLInterpreterMetaProvider implements MetaProvider {
private static final JooqLogger log = JooqLogger.getLogger(DDLInterpreterMetaProvider.class);
private final Configuration configuration;
private final Source[] scripts;
private final Source[] sources;
private final Query[] queries;
public DDLInterpreterMetaProvider(Configuration configuration, Source... scripts) {
public DDLInterpreterMetaProvider(Configuration configuration, Source... sources) {
this.configuration = configuration == null ? new DefaultConfiguration() : configuration;
this.scripts = scripts;
this.sources = sources;
this.queries = null;
}
public DDLInterpreterMetaProvider(Configuration configuration, Query... queries) {
this.configuration = configuration == null ? new DefaultConfiguration() : configuration;
this.scripts = null;
this.sources = null;
this.queries = queries;
}
@ -84,9 +84,9 @@ final class DDLInterpreterMetaProvider implements MetaProvider {
Configuration localConfiguration = configuration.derive();
DSLContext ctx = DSL.using(localConfiguration);
if (scripts != null)
for (Source script : scripts)
loadScript(ctx, script, interpreter);
if (sources != null)
for (Source source : sources)
loadSource(ctx, source, interpreter);
else
for (Query query : queries)
interpreter.accept(query);
@ -94,7 +94,7 @@ final class DDLInterpreterMetaProvider implements MetaProvider {
return interpreter.meta();
}
private final void loadScript(DSLContext ctx, Source source, DDLInterpreter interpreter) {
private final void loadSource(DSLContext ctx, Source source, DDLInterpreter interpreter) {
Reader reader = source.reader();
try {
Scanner s = new Scanner(reader).useDelimiter("\\A");

View File

@ -37,6 +37,8 @@
*/
package org.jooq.impl;
import static org.jooq.SQLDialect.DEFAULT;
import static org.jooq.tools.StringUtils.defaultIfNull;
import static org.jooq.tools.jdbc.JDBCUtils.safeClose;
import java.io.IOException;
@ -46,6 +48,7 @@ import java.io.StringWriter;
import org.jooq.Configuration;
import org.jooq.Meta;
import org.jooq.MetaProvider;
import org.jooq.SQLDialect;
import org.jooq.Source;
@ -94,6 +97,16 @@ final class SourceMetaProvider implements MetaProvider {
return new InformationSchemaMetaProvider(configuration, sources).provide();
}
return new DDLMetaProvider(configuration, sources).provide();
SQLDialect dialect = configuration.settings().getInterpreterDialect();
switch (defaultIfNull(dialect, DEFAULT)) {
case DEFAULT:
return new DDLInterpreterMetaProvider(configuration, sources).provide();
case H2:
return new DDLMetaProvider(configuration, sources).provide();
default:
throw new UnsupportedOperationException("Interpreter dialect not yet supported: " + dialect);
}
}
}

View File

@ -25,8 +25,8 @@
<xjc:javaType name="java.util.Locale" adapter="org.jooq.conf.LocaleAdapter"/>
</jaxb:bindings>
<!-- [#7337] SQLDialects -->
<jaxb:bindings schemaLocation="../../xsd/jooq-runtime-3.13.0.xsd" multiple="true" node="//xs:element[@name='parseDialect']">
<!-- [#7337] [#9362] SQLDialects -->
<jaxb:bindings schemaLocation="../../xsd/jooq-runtime-3.13.0.xsd" multiple="true" node="//xs:element[@name='parseDialect' or @name='interpreterDialect']">
<xjc:javaType name="org.jooq.SQLDialect" adapter="org.jooq.conf.SQLDialectAdapter"/>
</jaxb:bindings>

View File

@ -379,6 +379,10 @@ jOOQ queries, for which no specific fetchSize value was specified.]]></jxb:javad
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[[#6771] Specifies whether DELETE statements are allowed to be executed lacking a WHERE clause. This has no effect on rendering the statements SQL string.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="interpreterDialect" type="string" minOccurs="0" maxOccurs="1" default="DEFAULT">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[[#7337] The dialect that should be used to interpret SQL DDL statements. {@link SQLDialect#DEFAULT} means that jOOQ interprets the SQL itself. Any other dialect (if supported) will be interpreted on an actual JDBC connection.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="parseDialect" type="string" minOccurs="0" maxOccurs="1" default="DEFAULT">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[[#7337] The input dialect that should be chosen to disambiguate ambiguous SQL syntax.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>